Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Dec 18, 2023
1 parent 50e3a91 commit dfd40f9
Show file tree
Hide file tree
Showing 81 changed files with 336 additions and 950 deletions.
11 changes: 2 additions & 9 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,7 @@
sys.path.insert(0, os.path.abspath(".."))

import ledfx.consts as const
from ledfx.consts import (
DEV_VERSION,
POST_VERSION,
PROJECT_NAME,
PROJECT_VERSION,
)
from ledfx.consts import DEV_VERSION, POST_VERSION, PROJECT_NAME, PROJECT_VERSION

# -- Project information -----------------------------------------------------

Expand All @@ -40,9 +35,7 @@
PROJECT_GITHUB_USERNAME = "LedFx"
PROJECT_GITHUB_REPOSITORY = "LedFx"
PROJECT_GITHUB_BRANCH = "main"
PROJECT_GITHUB_PATH = "{}/{}".format(
PROJECT_GITHUB_USERNAME, PROJECT_GITHUB_REPOSITORY
)
PROJECT_GITHUB_PATH = f"{PROJECT_GITHUB_USERNAME}/{PROJECT_GITHUB_REPOSITORY}"
PROJECT_GITHUB_URL = f"https://github.com/{PROJECT_GITHUB_PATH}"

project = f"{PROJECT_NAME}"
Expand Down
16 changes: 4 additions & 12 deletions ledfx/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,7 @@ def setup_logging(loglevel, config_dir):

console_handler = logging.StreamHandler()
console_handler.setLevel(console_loglevel) # set loglevel
console_formatter = logging.Formatter(
console_logformat
) # a simple console format
console_formatter = logging.Formatter(console_logformat) # a simple console format
console_handler.setFormatter(
console_formatter
) # tell the console_handler to use this format
Expand All @@ -115,9 +113,7 @@ def setup_logging(loglevel, config_dir):


def parse_args():
parser = argparse.ArgumentParser(
description="A Networked LED Effect Controller"
)
parser = argparse.ArgumentParser(description="A Networked LED Effect Controller")

parser.add_argument(
"--version",
Expand Down Expand Up @@ -242,9 +238,7 @@ def log_packages():
from pkg_resources import working_set

_LOGGER.debug(f"{system()} : {release()} : {processor()}")
_LOGGER.debug(
f"{python_version()} : {python_build()} : {python_implementation()}"
)
_LOGGER.debug(f"{python_version()} : {python_build()} : {python_implementation()}")
_LOGGER.debug("Packages")
dists = [d for d in working_set]
dists.sort(key=lambda x: x.project_name)
Expand Down Expand Up @@ -304,9 +298,7 @@ def main():

icon_location = get_icon_path("tray.png")

icon = pystray.Icon(
"LedFx", icon=Image.open(icon_location), title="LedFx"
)
icon = pystray.Icon("LedFx", icon=Image.open(icon_location), title="LedFx")
else:
icon = None

Expand Down
5 changes: 1 addition & 4 deletions ledfx/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ async def handler(self, request: web.Request):

try:
return await method(
**{
arg_name: available_args[arg_name]
for arg_name in wanted_args
}
**{arg_name: available_args[arg_name] for arg_name in wanted_args}
)
except Exception as e:
# _LOGGER.exception(e)
Expand Down
4 changes: 1 addition & 3 deletions ledfx/api/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ async def get(self) -> web.Response:
Get LedFx colors and gradients
"""
response = {
"colors": dict(
zip(("builtin", "user"), self._ledfx.colors.get_all())
),
"colors": dict(zip(("builtin", "user"), self._ledfx.colors.get_all())),
"gradients": dict(
zip(("builtin", "user"), self._ledfx.gradients.get_all())
),
Expand Down
24 changes: 6 additions & 18 deletions ledfx/api/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,8 @@ async def post(self, request) -> web.Response:
audio_config = AudioInputSource.AUDIO_CONFIG_SCHEMA.fget()(
config.pop("audio", {})
)
wled_config = WLED_CONFIG_SCHEMA(
config.pop("wled_preferences", {})
)
melbanks_config = Melbanks.CONFIG_SCHEMA(
config.pop("melbanks", {})
)
wled_config = WLED_CONFIG_SCHEMA(config.pop("wled_preferences", {}))
melbanks_config = Melbanks.CONFIG_SCHEMA(config.pop("melbanks", {}))
core_config = CORE_CONFIG_SCHEMA(config)

core_config["audio"] = audio_config
Expand Down Expand Up @@ -161,9 +157,7 @@ async def put(self, request) -> web.Response:
melbanks_config = validate_and_trim_config(
config.pop("melbanks", {}), Melbanks.CONFIG_SCHEMA, "melbanks"
)
core_config = validate_and_trim_config(
config, CORE_CONFIG_SCHEMA, "core"
)
core_config = validate_and_trim_config(config, CORE_CONFIG_SCHEMA, "core")

self._ledfx.config["audio"].update(audio_config)
self._ledfx.config["melbanks"].update(melbanks_config)
Expand All @@ -172,13 +166,9 @@ async def put(self, request) -> web.Response:
# handle special case wled_preferences nested dict
for key in wled_config:
if key in self._ledfx.config["wled_preferences"]:
self._ledfx.config["wled_preferences"][key].update(
wled_config[key]
)
self._ledfx.config["wled_preferences"][key].update(wled_config[key])
else:
self._ledfx.config["wled_preferences"][key] = wled_config[
key
]
self._ledfx.config["wled_preferences"][key] = wled_config[key]

# TODO
# Do something if wled preferences config is updated
Expand All @@ -191,9 +181,7 @@ async def put(self, request) -> web.Response:
self._ledfx.audio.update_config(self._ledfx.config["audio"])

if hasattr(self._ledfx, "audio") and melbanks_config:
self._ledfx.audio.melbanks.update_config(
self._ledfx.config["melbanks"]
)
self._ledfx.audio.melbanks.update_config(self._ledfx.config["melbanks"])

if core_config and not (
any(
Expand Down
8 changes: 2 additions & 6 deletions ledfx/api/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ async def put(self, device_id, request) -> web.Response:
return web.json_response(data=response, status=400)

_LOGGER.debug(
("Updating device {} with config {}").format(
device_id, device_config
)
("Updating device {} with config {}").format(device_id, device_config)
)

try:
Expand Down Expand Up @@ -106,9 +104,7 @@ async def post(self, device_id, request) -> web.Response:
effect_response["config"] = virtual.active_effect.config
effect_response["name"] = virtual.active_effect.name
effect_response["type"] = virtual.active_effect.type
response["virtuals"][virtual.id][
"effect"
] = effect_response
response["virtuals"][virtual.id]["effect"] = effect_response

except (voluptuous.Error, ValueError) as msg:
response = {
Expand Down
4 changes: 1 addition & 3 deletions ledfx/api/get_nanoleaf_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ async def post(self, request) -> web.Response:
_LOGGER.info(f"Get Nanoleaf Token from {ip}:{port}")

try:
response = requests.post(
f"http://{ip}:{port}/api/v1/new", timeout=(3, 3)
)
response = requests.post(f"http://{ip}:{port}/api/v1/new", timeout=(3, 3))
if response.text == "":
msg = f"{ip}:{port}: Ensure Nanoleaf controller is in pairing mode"
_LOGGER.error(msg)
Expand Down
8 changes: 2 additions & 6 deletions ledfx/api/integration_spotify.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ async def post(self, integration_id, request) -> web.Response:

integration.add_trigger(scene_id, song_id, song_name, song_position)

save_config(
config=self._ledfx.config, config_dir=self._ledfx.config_dir
)
save_config(config=self._ledfx.config, config_dir=self._ledfx.config_dir)

response = {"status": "success"}
return web.json_response(data=response, status=200)
Expand Down Expand Up @@ -116,9 +114,7 @@ async def delete(self, integration_id, request) -> web.Response:
integration.delete_trigger(trigger_id)

# Update and save the config
save_config(
config=self._ledfx.config, config_dir=self._ledfx.config_dir
)
save_config(config=self._ledfx.config, config_dir=self._ledfx.config_dir)

response = {"status": "success"}
return web.json_response(data=response, status=200)
4 changes: 1 addition & 3 deletions ledfx/api/integrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,7 @@ async def delete(self, request) -> web.Response:
]

# Save the config
save_config(
config=self._ledfx.config, config_dir=self._ledfx.config_dir
)
save_config(config=self._ledfx.config, config_dir=self._ledfx.config_dir)

response = {"status": "success"}
return web.json_response(data=response, status=200)
Expand Down
4 changes: 1 addition & 3 deletions ledfx/api/scenes.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,7 @@ async def put(self, request) -> web.Response:
"reason": 'Required attribute "ms" was not provided',
}
return web.json_response(data=response, status=400)
self._ledfx.loop.call_later(
ms, self._ledfx.scenes.activate, scene_id
)
self._ledfx.loop.call_later(ms, self._ledfx.scenes.activate, scene_id)
response = {
"status": "success",
"payload": {
Expand Down
10 changes: 2 additions & 8 deletions ledfx/api/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,7 @@ async def get(self, request) -> web.Response:
elif schema == "virtuals":
# Get virtuals schema
response["virtuals"] = {
"schema": convertToJsonSchema(
self._ledfx.virtuals.schema()
),
"schema": convertToJsonSchema(self._ledfx.virtuals.schema()),
}

elif schema == "audio":
Expand Down Expand Up @@ -157,11 +155,7 @@ async def get(self, request) -> web.Response:
**convertToJsonSchema(
WLED_CONFIG_SCHEMA,
),
**{
"permitted_keys": PERMITTED_KEYS[
"wled_preferences"
]
},
**{"permitted_keys": PERMITTED_KEYS["wled_preferences"]},
},
}

Expand Down
19 changes: 4 additions & 15 deletions ledfx/api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,7 @@ def convertToJsonSchema(schema):

return val

if (
callable(schema)
and getattr(schema, "__name__", None) == "fps_validator"
):
if callable(schema) and getattr(schema, "__name__", None) == "fps_validator":
return {"type": "int", "enum": list(AVAILABLE_FPS)}

elif (
Expand All @@ -113,16 +110,10 @@ def convertToJsonSchema(schema):
):
return {"type": "string", "enum": AudioInputSource.input_devices()}

elif (
callable(schema)
and getattr(schema, "__name__", None) == "validate_color"
):
elif callable(schema) and getattr(schema, "__name__", None) == "validate_color":
return {"type": "color", "gradient": False}

elif (
callable(schema)
and getattr(schema, "__name__", None) == "validate_gradient"
):
elif callable(schema) and getattr(schema, "__name__", None) == "validate_gradient":
return {"type": "color", "gradient": True}

elif isinstance(schema, vol.All):
Expand Down Expand Up @@ -169,9 +160,7 @@ def convertToJsonSchema(schema):
elif isinstance(schema, list):
val = {
"type": "list",
"validators": list(
convertToJsonSchema(validator) for validator in schema
),
"validators": list(convertToJsonSchema(validator) for validator in schema),
}
return val

Expand Down
4 changes: 1 addition & 3 deletions ledfx/api/virtual.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ async def get(self, virtual_id) -> web.Response:
"effect": {},
}
# TODO: protect from DummyEffect, future consider side effects
if virtual.active_effect and not isinstance(
virtual.active_effect, DummyEffect
):
if virtual.active_effect and not isinstance(virtual.active_effect, DummyEffect):
effect_response = {}
effect_response["config"] = virtual.active_effect.config
effect_response["name"] = virtual.active_effect.name
Expand Down
5 changes: 1 addition & 4 deletions ledfx/api/virtual_effects.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,7 @@ async def put(self, virtual_id, request) -> web.Response:

try:
# handling an effect update. nested if else and repeated code bleh. ain't a looker ;)
if (
virtual.active_effect
and virtual.active_effect.type == effect_type
):
if virtual.active_effect and virtual.active_effect.type == effect_type:
# substring search to match any key of color
# this handles special cases where we want to update an effect and also trigger
# a transition by creating a new effect.
Expand Down
8 changes: 2 additions & 6 deletions ledfx/api/virtual_presets.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,7 @@ async def put(self, virtual_id, request) -> web.Response:
return web.json_response(data=response, status=400)

# Create the effect and add it to the virtual
effect_config = self._ledfx.config[category][effect_id][preset_id][
"config"
]
effect_config = self._ledfx.config[category][effect_id][preset_id]["config"]
effect = self._ledfx.effects.create(
ledfx=self._ledfx, type=effect_id, config=effect_config
)
Expand Down Expand Up @@ -219,9 +217,7 @@ async def post(self, virtual_id, request) -> web.Response:

# Update the preset if it already exists, else create it
self._ledfx.config["user_presets"][effect_id][preset_id] = {}
self._ledfx.config["user_presets"][effect_id][preset_id][
"name"
] = preset_name
self._ledfx.config["user_presets"][effect_id][preset_id]["name"] = preset_name
self._ledfx.config["user_presets"][effect_id][preset_id][
"config"
] = virtual.active_effect.config
Expand Down
4 changes: 1 addition & 3 deletions ledfx/api/virtuals.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,7 @@ async def post(self, request) -> web.Response:
return web.json_response(data=response, status=404)
# Update the virtual's configuration
virtual.config = virtual_config
_LOGGER.info(
f"Updated virtual {virtual.id} config to {virtual_config}"
)
_LOGGER.info(f"Updated virtual {virtual.id} config to {virtual_config}")
# Update ledfx's config
for idx, item in enumerate(self._ledfx.config["virtuals"]):
if item["id"] == virtual.id:
Expand Down
8 changes: 2 additions & 6 deletions ledfx/api/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ async def get(self, request) -> web.Response:
try:
return await WebsocketConnection(self._ledfx).handle(request)
except ConnectionResetError:
_LOGGER.debug(
"Connection Reset Error on Websocket Connection - retrying."
)
_LOGGER.debug("Connection Reset Error on Websocket Connection - retrying.")


class WebsocketConnection:
Expand Down Expand Up @@ -84,9 +82,7 @@ def send(self, message):
self._sender_queue.put_nowait(message)
except asyncio.QueueFull:
_LOGGER.error(
"Client sender queue size exceeded {}".format(
MAX_PENDING_MESSAGES
)
f"Client sender queue size exceeded {MAX_PENDING_MESSAGES}"
)
self.close()

Expand Down
9 changes: 2 additions & 7 deletions ledfx/color.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,10 @@ def from_string(cls, gradient_str: str):
angle = int(angle.strip("deg"))
# Split each color/position string
colors = colors.split("%")
colors = [
color.strip(", ").rsplit(" ", 1)
for color in colors
if color.strip()
]
colors = [color.strip(", ").rsplit(" ", 1) for color in colors if color.strip()]
# Parse color and position
colors = [
(parse_color(color), float(position) / 100.0)
for color, position in colors
(parse_color(color), float(position) / 100.0) for color, position in colors
]
# Sort color list by position (0.0->1.0)
colors.sort(key=lambda tup: tup[1])
Expand Down
Loading

0 comments on commit dfd40f9

Please sign in to comment.