Skip to content

Commit

Permalink
Rewrite wled library (#1334)
Browse files Browse the repository at this point in the history
  • Loading branch information
frenck authored Jun 19, 2024
1 parent 72be2f1 commit 57d046c
Show file tree
Hide file tree
Showing 12 changed files with 1,180 additions and 1,420 deletions.
21 changes: 10 additions & 11 deletions examples/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,20 @@

async def main() -> None:
"""Show example on controlling your WLED device."""
async with WLED("10.10.11.61") as led:
async with WLED("10.10.11.31") as led:
device = await led.update()
print(device.info.version)
print(device.state)

print(device.info.leds)
print(device.state.segments[0])
# await led.segment(
# 0,
# await led.segment(
if device.state.on:
print("Turning off WLED....")
await led.master(on=False)
else:
print("Turning on WLED....")
await led.master(on=True)

# if isinstance(device.state.preset, Preset):

# if isinstance(device.state.playlist, Playlist):

# Turn strip on, full brightness
device = await led.update()
print(device.state)


if __name__ == "__main__":
Expand Down
17 changes: 12 additions & 5 deletions examples/upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,31 @@

import asyncio

from wled import WLED
from wled import WLED, WLEDReleases


async def main() -> None:
"""Show example on upgrade your WLED device."""
async with WLEDReleases() as releases:
latest = await releases.releases()
print(f"Latest stable version: {latest.stable}")
print(f"Latest beta version: {latest.beta}")

if not latest.stable:
print("No stable version found")
return

async with WLED("10.10.11.54") as led:
device = await led.update()
print(f"Latest stable version: {device.info.version_latest_stable}")
print(f"Latest beta version: {device.info.version_latest_beta}")
print(f"Current version: {device.info.version}")

print("Upgrading WLED....")
await led.upgrade(version="0.13.0-b4")
await led.upgrade(version=latest.stable)

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

device = await led.update(full_update=True)
device = await led.update()
print(f"Current version: {device.info.version}")


Expand Down
116 changes: 83 additions & 33 deletions poetry.lock

Large diffs are not rendered by default.

13 changes: 11 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ aiohttp = ">=3.0.0"
awesomeversion = ">=22.1.0"
backoff = ">=2.2.0"
cachetools = ">=4.0.0"
mashumaro = "^3.13"
orjson = ">=3.9.8"
python = "^3.11"
yarl = ">=1.6.0"
typer = {version = "^0.12.3", optional = true, extras = ["all"]}
yarl = ">=1.6.0"
zeroconf = {version = "^0.132.2", optional = true, extras = ["all"]}

[tool.poetry.extras]
Expand Down Expand Up @@ -66,7 +68,7 @@ plugins = ["covdefaults"]
source = ["wled"]

[tool.coverage.report]
fail_under = 53
fail_under = 25
show_missing = true
omit = ["src/wled/cli/*"]

Expand Down Expand Up @@ -138,13 +140,17 @@ max-line-length = 88
[tool.pylint.DESIGN]
max-attributes = 20

[tool.pylint.TYPECHECK]
ignored-modules = ["orjson"]

[tool.pytest.ini_options]
addopts = "--cov"
asyncio_mode = "auto"

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

[tool.ruff.lint.flake8-type-checking]
runtime-evaluated-base-classes = ["mashumaro.mixins.orjson.DataClassORJSONMixin"]

[tool.ruff.lint.mccabe]
max-complexity = 25

Expand Down
18 changes: 12 additions & 6 deletions src/wled/__init__.py
Original file line number Diff line number Diff line change
@@ -1,49 +1,55 @@
"""Asynchronous Python client for WLED."""

from .const import LightCapability, LiveDataOverride, NightlightMode, SyncGroup
from .exceptions import (
WLEDConnectionClosedError,
WLEDConnectionError,
WLEDConnectionTimeoutError,
WLEDError,
WLEDUnsupportedVersionError,
WLEDUpgradeError,
)
from .models import (
Device,
Effect,
Info,
Leds,
LightCapability,
Live,
Nightlight,
Palette,
Playlist,
PlaylistEntry,
Preset,
Releases,
Segment,
State,
Sync,
UDPSync,
)
from .wled import WLED
from .wled import WLED, WLEDReleases

__all__ = [
"Device",
"Effect",
"Info",
"Leds",
"LightCapability",
"Live",
"LiveDataOverride",
"Nightlight",
"NightlightMode",
"Palette",
"Playlist",
"PlaylistEntry",
"Preset",
"Releases",
"Segment",
"State",
"Sync",
"SyncGroup",
"UDPSync",
"WLED",
"WLEDConnectionClosedError",
"WLEDConnectionError",
"WLEDConnectionTimeoutError",
"WLEDError",
"WLEDReleases",
"WLEDUnsupportedVersionError",
"WLEDUpgradeError",
]
Loading

0 comments on commit 57d046c

Please sign in to comment.