Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pylint = "3.0.3"
pytest = "7.4.4"
pytest-asyncio = "0.23.4"
pytest-cov = "4.1.0"
ruff = "0.1.14"
ruff = "0.1.15"
safety = "3.0.1"
types-cachetools = "^5.3.0"
yamllint = "1.33.0"
Expand Down
18 changes: 18 additions & 0 deletions src/wled/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def from_dict(data: dict[str, Any]) -> Nightlight:
Returns:
-------
A Nightlight object.

"""
nightlight = data.get("nl", {})

Expand Down Expand Up @@ -69,6 +70,7 @@ def from_dict(data: dict[str, Any]) -> Sync:
Returns:
-------
A sync object.

"""
sync = data.get("udpn", {})
return Sync(send=sync.get("send", False), receive=sync.get("recv", False))
Expand All @@ -93,6 +95,7 @@ class Palette:
Returns:
-------
A palette object.

"""

name: str
Expand All @@ -110,6 +113,7 @@ class Segment:
Returns:
-------
A segment object.

"""

brightness: int
Expand Down Expand Up @@ -154,6 +158,7 @@ def from_dict( # noqa: PLR0913
Returns:
-------
An Segment object.

"""
start = data.get("start", 0)
stop = data.get("stop", 0)
Expand Down Expand Up @@ -223,6 +228,7 @@ def from_dict(data: dict[str, Any]) -> Leds:
Returns:
-------
A Leds object.

"""
leds = data.get("leds", {})

Expand Down Expand Up @@ -259,6 +265,7 @@ class Wifi:
Returns:
-------
A Wi-Fi object.

"""

bssid: str
Expand All @@ -277,6 +284,7 @@ def from_dict(data: dict[str, Any]) -> Wifi | None:
Returns:
-------
An Wifi object.

"""
if "wifi" not in data:
return None
Expand All @@ -300,6 +308,7 @@ class Filesystem:
Returns:
-------
A Filesystem object.

"""

total: int
Expand All @@ -318,6 +327,7 @@ def from_dict(data: dict[str, Any]) -> Filesystem | None:
Returns:
-------
An Filesystem object.

"""
if "fs" not in data:
return None
Expand Down Expand Up @@ -372,6 +382,7 @@ def from_dict(data: dict[str, Any]) -> Info:
Returns:
-------
A info object.

"""
if (websocket := data.get("ws")) == -1:
websocket = None
Expand Down Expand Up @@ -447,6 +458,7 @@ def playlist_active(self) -> bool:
Returns
-------
True if there is currently a playlist active, False otherwise.

"""
return self.playlist == -1

Expand All @@ -457,6 +469,7 @@ def preset_active(self) -> bool:
Returns
-------
True is a preset is currently active, False otherwise.

"""
return self.preset == -1

Expand All @@ -481,6 +494,7 @@ def from_dict(
Returns:
-------
A State object.

"""
brightness = data.get("bri", 1)
on = data.get("on", False)
Expand Down Expand Up @@ -556,6 +570,7 @@ def from_dict(
Returns:
-------
A Preset object.

"""
segment_data = data.get("seg", [])
if not isinstance(segment_data, list):
Expand Down Expand Up @@ -629,6 +644,7 @@ def from_dict(
Returns:
-------
A Playlist object.

"""
playlist = data.get("playlist", {})
entries_durations = playlist.get("dur", [])
Expand Down Expand Up @@ -684,6 +700,7 @@ def __init__(self, data: dict[str, Any]) -> None:
------
WLEDError: In case the given API response is incomplete in a way
that a Device object cannot be constructed from it.

"""
self.effects = []
self.palettes = []
Expand All @@ -710,6 +727,7 @@ def update_from_dict(self, data: dict[str, Any]) -> Device:
Returns:
-------
The updated Device object.

"""
if _effects := data.get("effects"):
effects = [
Expand Down
17 changes: 17 additions & 0 deletions src/wled/wled.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def connected(self) -> bool:
-------
True if we are connected to the WebSocket of a WLED device,
False otherwise.

"""
return self._client is not None and not self._client.closed

Expand All @@ -65,6 +66,7 @@ async def connect(self) -> None:
communications.
WLEDConnectionError: Error occurred while communicating with
the WLED device via the WebSocket.

"""
if self.connected:
return
Expand Down Expand Up @@ -106,6 +108,7 @@ async def listen(self, callback: Callable[[Device], None]) -> None:
to the WLED device.
WLEDConnectionClosedError: The WebSocket connection to the remote WLED
has been closed.

"""
if not self._client or not self.connected or not self._device:
msg = "Not connected to a WLED WebSocket"
Expand Down Expand Up @@ -167,6 +170,7 @@ async def request(
WLEDConnectionTimeoutError: A timeout occurred while communicating
with the WLED device.
WLEDError: Received an unexpected response from the WLED device.

"""
url = URL.build(scheme="http", host=self.host, port=80, path=uri)

Expand Down Expand Up @@ -250,6 +254,7 @@ async def update(self, *, full_update: bool = False) -> Device: # noqa: PLR0912
Raises:
------
WLEDEmptyResponseError: The WLED device returned an empty response.

"""
if self._device is None or full_update:
if not (data := await self.request("/json")):
Expand Down Expand Up @@ -352,6 +357,7 @@ async def master(
transition: Duration of the crossfade between different
colors/brightness levels. One unit is 100ms, so a value of 4
results in a transition of 400ms.

"""
state: dict[str, bool | int] = {}

Expand Down Expand Up @@ -423,6 +429,7 @@ async def segment( # noqa: PLR0912, PLR0913
Raises:
------
WLEDError: Something went wrong setting the segment state.

"""
if self._device is None:
await self.update()
Expand Down Expand Up @@ -521,6 +528,7 @@ async def transition(self, transition: int) -> None:
transition: Duration of the default crossfade between different
colors/brightness levels. One unit is 100ms, so a value of 4
results in a transition of 400ms.

"""
await self.request(
"/json/state",
Expand All @@ -534,6 +542,7 @@ async def preset(self, preset: int | str | Preset) -> None:
Args:
----
preset: The preset to activate on this WLED device.

"""
# Find preset if it was based on a name
if self._device and self._device.presets and isinstance(preset, str):
Expand All @@ -557,6 +566,7 @@ async def playlist(self, playlist: int | str | Playlist) -> None:
Args:
----
playlist: The playlist to activate on this WLED device.

"""
# Find playlist if it was based on a name
if self._device and self._device.playlists and isinstance(playlist, str):
Expand All @@ -580,6 +590,7 @@ async def live(self, live: Live) -> None:
Args:
----
live: The live override mode to set on this WLED device.

"""
await self.request("/json/state", method="POST", data={"lor": live.value})

Expand All @@ -595,6 +606,7 @@ async def sync(
----
send: Send WLED broadcast (UDP sync) packet on state change.
receive: Receive broadcast packets.

"""
sync = {"send": send, "recv": receive}
sync = {k: v for k, v in sync.items() if v is not None}
Expand All @@ -618,6 +630,7 @@ async def nightlight(
target brightness once the duration has elapsed.
on: A boolean, true to turn the nightlight on, false otherwise.
target_brightness: Target brightness of nightlight, between 0 and 255.

"""
nightlight = {
"dur": duration,
Expand All @@ -642,6 +655,7 @@ async def upgrade(self, *, version: str | AwesomeVersion) -> None:
WLEDUpgradeError: If the upgrade has failed.
WLEDConnectionTimeoutError: When a connection timeout occurs.
WLEDConnectionError: When a connection error occurs.

"""
if self._device is None:
await self.update()
Expand Down Expand Up @@ -732,6 +746,7 @@ async def get_wled_versions_from_github(self) -> dict[str, str | None]:
GitHub for WLED version information.
WLEDError: Didn't get a JSON response from GitHub while retrieving
version information.

"""
with suppress(KeyError):
return {
Expand Down Expand Up @@ -810,6 +825,7 @@ async def __aenter__(self) -> Self:
Returns
-------
The WLED object.

"""
return self

Expand All @@ -819,5 +835,6 @@ async def __aexit__(self, *_exc_info: object) -> None:
Args:
----
_exc_info: Exec type.

"""
await self.close()