Skip to content

Commit 57d046c

Browse files
authored
Rewrite wled library (#1334)
1 parent 72be2f1 commit 57d046c

File tree

12 files changed

+1180
-1420
lines changed

12 files changed

+1180
-1420
lines changed

examples/control.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,20 @@
88

99
async def main() -> None:
1010
"""Show example on controlling your WLED device."""
11-
async with WLED("10.10.11.61") as led:
11+
async with WLED("10.10.11.31") as led:
1212
device = await led.update()
1313
print(device.info.version)
14+
print(device.state)
1415

15-
print(device.info.leds)
16-
print(device.state.segments[0])
17-
# await led.segment(
18-
# 0,
19-
# await led.segment(
16+
if device.state.on:
17+
print("Turning off WLED....")
18+
await led.master(on=False)
19+
else:
20+
print("Turning on WLED....")
21+
await led.master(on=True)
2022

21-
# if isinstance(device.state.preset, Preset):
22-
23-
# if isinstance(device.state.playlist, Playlist):
24-
25-
# Turn strip on, full brightness
23+
device = await led.update()
24+
print(device.state)
2625

2726

2827
if __name__ == "__main__":

examples/upgrade.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,31 @@
33

44
import asyncio
55

6-
from wled import WLED
6+
from wled import WLED, WLEDReleases
77

88

99
async def main() -> None:
1010
"""Show example on upgrade your WLED device."""
11+
async with WLEDReleases() as releases:
12+
latest = await releases.releases()
13+
print(f"Latest stable version: {latest.stable}")
14+
print(f"Latest beta version: {latest.beta}")
15+
16+
if not latest.stable:
17+
print("No stable version found")
18+
return
19+
1120
async with WLED("10.10.11.54") as led:
1221
device = await led.update()
13-
print(f"Latest stable version: {device.info.version_latest_stable}")
14-
print(f"Latest beta version: {device.info.version_latest_beta}")
1522
print(f"Current version: {device.info.version}")
1623

1724
print("Upgrading WLED....")
18-
await led.upgrade(version="0.13.0-b4")
25+
await led.upgrade(version=latest.stable)
1926

2027
print("Waiting for WLED to come back....")
2128
await asyncio.sleep(5)
2229

23-
device = await led.update(full_update=True)
30+
device = await led.update()
2431
print(f"Current version: {device.info.version}")
2532

2633

poetry.lock

Lines changed: 83 additions & 33 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@ aiohttp = ">=3.0.0"
2929
awesomeversion = ">=22.1.0"
3030
backoff = ">=2.2.0"
3131
cachetools = ">=4.0.0"
32+
mashumaro = "^3.13"
33+
orjson = ">=3.9.8"
3234
python = "^3.11"
33-
yarl = ">=1.6.0"
3435
typer = {version = "^0.12.3", optional = true, extras = ["all"]}
36+
yarl = ">=1.6.0"
3537
zeroconf = {version = "^0.132.2", optional = true, extras = ["all"]}
3638

3739
[tool.poetry.extras]
@@ -66,7 +68,7 @@ plugins = ["covdefaults"]
6668
source = ["wled"]
6769

6870
[tool.coverage.report]
69-
fail_under = 53
71+
fail_under = 25
7072
show_missing = true
7173
omit = ["src/wled/cli/*"]
7274

@@ -138,13 +140,17 @@ max-line-length = 88
138140
[tool.pylint.DESIGN]
139141
max-attributes = 20
140142

143+
[tool.pylint.TYPECHECK]
144+
ignored-modules = ["orjson"]
145+
141146
[tool.pytest.ini_options]
142147
addopts = "--cov"
143148
asyncio_mode = "auto"
144149

145150
[tool.ruff.lint]
146151
ignore = [
147152
"ANN101", # Self... explanatory
153+
"ANN102", # cls... clear screen?
148154
"ANN401", # Opinioated warning on disallowing dynamically typed expressions
149155
"D203", # Conflicts with other rules
150156
"D213", # Conflicts with other rules
@@ -164,6 +170,9 @@ mark-parentheses = false
164170
[tool.ruff.lint.isort]
165171
known-first-party = ["wled"]
166172

173+
[tool.ruff.lint.flake8-type-checking]
174+
runtime-evaluated-base-classes = ["mashumaro.mixins.orjson.DataClassORJSONMixin"]
175+
167176
[tool.ruff.lint.mccabe]
168177
max-complexity = 25
169178

src/wled/__init__.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,55 @@
11
"""Asynchronous Python client for WLED."""
22

3+
from .const import LightCapability, LiveDataOverride, NightlightMode, SyncGroup
34
from .exceptions import (
45
WLEDConnectionClosedError,
56
WLEDConnectionError,
67
WLEDConnectionTimeoutError,
78
WLEDError,
9+
WLEDUnsupportedVersionError,
810
WLEDUpgradeError,
911
)
1012
from .models import (
1113
Device,
1214
Effect,
1315
Info,
1416
Leds,
15-
LightCapability,
16-
Live,
1717
Nightlight,
1818
Palette,
1919
Playlist,
2020
PlaylistEntry,
2121
Preset,
22+
Releases,
2223
Segment,
2324
State,
24-
Sync,
25+
UDPSync,
2526
)
26-
from .wled import WLED
27+
from .wled import WLED, WLEDReleases
2728

2829
__all__ = [
2930
"Device",
3031
"Effect",
3132
"Info",
3233
"Leds",
3334
"LightCapability",
34-
"Live",
35+
"LiveDataOverride",
3536
"Nightlight",
37+
"NightlightMode",
3638
"Palette",
3739
"Playlist",
3840
"PlaylistEntry",
3941
"Preset",
42+
"Releases",
4043
"Segment",
4144
"State",
42-
"Sync",
45+
"SyncGroup",
46+
"UDPSync",
4347
"WLED",
4448
"WLEDConnectionClosedError",
4549
"WLEDConnectionError",
4650
"WLEDConnectionTimeoutError",
4751
"WLEDError",
52+
"WLEDReleases",
53+
"WLEDUnsupportedVersionError",
4854
"WLEDUpgradeError",
4955
]

0 commit comments

Comments
 (0)