led-controller-version-3 3.0.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- led_controller_version_3-3.0.2.dist-info/METADATA +172 -0
- led_controller_version_3-3.0.2.dist-info/RECORD +52 -0
- led_controller_version_3-3.0.2.dist-info/WHEEL +4 -0
- led_controller_version_3-3.0.2.dist-info/entry_points.txt +13 -0
- lefx/device/respeaker/__init__.py +35 -0
- lefx/device/respeaker/cli.py +146 -0
- lefx/device/respeaker/contention.py +523 -0
- lefx/device/respeaker/provider.py +158 -0
- lefx/device/respeaker/registration.py +130 -0
- lefx/device/respeaker/sink.py +108 -0
- lefx/device/respeaker/transport.py +344 -0
- lefx/device/respeaker/xvf.py +313 -0
- lefx/engine/__init__.py +110 -0
- lefx/engine/composer.py +203 -0
- lefx/engine/config.py +27 -0
- lefx/engine/errors.py +84 -0
- lefx/engine/inputs.py +196 -0
- lefx/engine/invocation.py +129 -0
- lefx/engine/layers.py +114 -0
- lefx/engine/library.py +181 -0
- lefx/engine/packages/__init__.py +45 -0
- lefx/engine/packages/loader.py +375 -0
- lefx/engine/packages/manifest.py +308 -0
- lefx/engine/registry.py +347 -0
- lefx/engine/renderer.py +63 -0
- lefx/engine/runtime.py +393 -0
- lefx/engine/store.py +125 -0
- lefx/interfaces/__init__.py +40 -0
- lefx/interfaces/api.py +301 -0
- lefx/interfaces/cli.py +380 -0
- lefx/interfaces/client.py +165 -0
- lefx/interfaces/config.py +305 -0
- lefx/interfaces/discovery.py +308 -0
- lefx/interfaces/hosting.py +123 -0
- lefx/interfaces/paths.py +79 -0
- lefx/interfaces/presentation.py +118 -0
- lefx/interfaces/service.py +468 -0
- lefx/sdk/__init__.py +176 -0
- lefx/sdk/calibration.py +202 -0
- lefx/sdk/color.py +108 -0
- lefx/sdk/context.py +72 -0
- lefx/sdk/definitions.py +526 -0
- lefx/sdk/effects.py +63 -0
- lefx/sdk/errors.py +90 -0
- lefx/sdk/parameters.py +469 -0
- lefx/sdk/ports.py +76 -0
- lefx/sdk/validation.py +150 -0
- lefx/sdk/values.py +212 -0
- lefx/sets/core_set/__init__.py +32 -0
- lefx/sets/core_set/core-set.lefxset +0 -0
- lefx/sets/smartspeaker_set/__init__.py +32 -0
- lefx/sets/smartspeaker_set/smartspeaker-set.lefxset +0 -0
lefx/sdk/values.py
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
"""Canonical value normalization at the system boundary.
|
|
2
|
+
|
|
3
|
+
LEFX is forgiving about how a value arrives and strict about what it stores.
|
|
4
|
+
``blau``, ``#0000FF`` and ``0x0000FF`` all mean the same colour; internally only
|
|
5
|
+
``#0000FF`` exists. Every parser here is total: it either returns the canonical
|
|
6
|
+
form or raises with a code, the rejected value and — where useful — suggestions.
|
|
7
|
+
|
|
8
|
+
Effect packages never call these. They receive values that are already
|
|
9
|
+
canonical, which is why a renderer needs no second input language of its own.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
import difflib
|
|
15
|
+
import re
|
|
16
|
+
from dataclasses import dataclass
|
|
17
|
+
from typing import Any
|
|
18
|
+
|
|
19
|
+
from .errors import ValueNormalizationError
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@dataclass(slots=True, frozen=True)
|
|
23
|
+
class NamedColor:
|
|
24
|
+
name: str
|
|
25
|
+
value: int
|
|
26
|
+
aliases: tuple[str, ...] = ()
|
|
27
|
+
|
|
28
|
+
@property
|
|
29
|
+
def hex_value(self) -> str:
|
|
30
|
+
return f"#{self.value:06X}"
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
COLOR_CATALOG: tuple[NamedColor, ...] = (
|
|
34
|
+
NamedColor("black", 0x000000, ("schwarz",)),
|
|
35
|
+
NamedColor("white", 0xFFFFFF, ("weiss", "weiß")),
|
|
36
|
+
NamedColor("red", 0xFF0000, ("rot",)),
|
|
37
|
+
NamedColor("green", 0x00FF00, ("gruen", "grün")),
|
|
38
|
+
NamedColor("blue", 0x0000FF, ("blau",)),
|
|
39
|
+
NamedColor("cyan", 0x00FFFF, ("tuerkis", "türkis")),
|
|
40
|
+
NamedColor("yellow", 0xFFFF00, ("gelb",)),
|
|
41
|
+
NamedColor("orange", 0xFF8000, ()),
|
|
42
|
+
NamedColor("purple", 0x8000FF, ("lila", "violett", "violet")),
|
|
43
|
+
NamedColor("pink", 0xFF1493, ("rosa",)),
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
_COLOR_BY_ALIAS: dict[str, NamedColor] = {
|
|
47
|
+
alias.casefold(): color
|
|
48
|
+
for color in COLOR_CATALOG
|
|
49
|
+
for alias in (color.name, *color.aliases)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
_DURATION_RE = re.compile(r"^([+-]?(?:\d+(?:\.\d*)?|\.\d+))\s*(ms|s)?$", re.IGNORECASE)
|
|
53
|
+
_PERCENT_RE = re.compile(r"^([+-]?(?:\d+(?:\.\d*)?|\.\d+))\s*%$")
|
|
54
|
+
_ANGLE_RE = re.compile(r"^([+-]?(?:\d+(?:\.\d*)?|\.\d+))\s*(?:deg|°)?$", re.IGNORECASE)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def parse_color(value: Any) -> int:
|
|
58
|
+
"""Accept a colour name, ``#RRGGBB``, ``0xRRGGBB`` or an RGB integer."""
|
|
59
|
+
if isinstance(value, bool):
|
|
60
|
+
raise _invalid_color(value)
|
|
61
|
+
if isinstance(value, int):
|
|
62
|
+
if 0 <= value <= 0xFFFFFF:
|
|
63
|
+
return value
|
|
64
|
+
raise ValueNormalizationError(
|
|
65
|
+
f"Color integer must be in range 0..0xFFFFFF, got {value!r}",
|
|
66
|
+
code="color_out_of_range",
|
|
67
|
+
value=value,
|
|
68
|
+
)
|
|
69
|
+
if not isinstance(value, str):
|
|
70
|
+
raise _invalid_color(value)
|
|
71
|
+
|
|
72
|
+
text = value.strip()
|
|
73
|
+
named = _COLOR_BY_ALIAS.get(text.casefold())
|
|
74
|
+
if named is not None:
|
|
75
|
+
return named.value
|
|
76
|
+
|
|
77
|
+
digits = text[1:] if text.startswith("#") else text[2:] if text.lower().startswith("0x") else ""
|
|
78
|
+
if len(digits) == 6 and all(character in "0123456789abcdefABCDEF" for character in digits):
|
|
79
|
+
return int(digits, 16)
|
|
80
|
+
|
|
81
|
+
suggestions = tuple(
|
|
82
|
+
difflib.get_close_matches(text.casefold(), sorted(_COLOR_BY_ALIAS), n=3, cutoff=0.55)
|
|
83
|
+
)
|
|
84
|
+
raise ValueNormalizationError(
|
|
85
|
+
f"Unknown color {value!r}",
|
|
86
|
+
code="unknown_color",
|
|
87
|
+
value=value,
|
|
88
|
+
suggestions=suggestions,
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def format_color(value: Any) -> str:
|
|
93
|
+
"""Canonical colour form: uppercase ``#RRGGBB``."""
|
|
94
|
+
return f"#{parse_color(value):06X}"
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def describe_color(value: Any) -> dict[str, Any]:
|
|
98
|
+
parsed = parse_color(value)
|
|
99
|
+
named = next((color for color in COLOR_CATALOG if color.value == parsed), None)
|
|
100
|
+
payload: dict[str, Any] = {"hex": f"#{parsed:06X}"}
|
|
101
|
+
if named is not None:
|
|
102
|
+
payload["name"] = named.name
|
|
103
|
+
payload["aliases"] = list(named.aliases)
|
|
104
|
+
return payload
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def parse_duration_ms(value: Any, *, minimum: int = 0) -> int:
|
|
108
|
+
"""Accept a number, ``1500ms`` or ``1.5s``; return whole milliseconds."""
|
|
109
|
+
if isinstance(value, bool):
|
|
110
|
+
raise _invalid_value("invalid_duration", "Duration must be numeric or use ms/s", value)
|
|
111
|
+
if isinstance(value, (int, float)):
|
|
112
|
+
milliseconds = float(value)
|
|
113
|
+
elif isinstance(value, str):
|
|
114
|
+
match = _DURATION_RE.fullmatch(value.strip())
|
|
115
|
+
if match is None:
|
|
116
|
+
raise _invalid_value(
|
|
117
|
+
"invalid_duration",
|
|
118
|
+
"Duration must use a value such as 1500ms or 1.5s",
|
|
119
|
+
value,
|
|
120
|
+
)
|
|
121
|
+
milliseconds = float(match.group(1))
|
|
122
|
+
if (match.group(2) or "ms").lower() == "s":
|
|
123
|
+
milliseconds *= 1000.0
|
|
124
|
+
else:
|
|
125
|
+
raise _invalid_value("invalid_duration", "Duration must be numeric or use ms/s", value)
|
|
126
|
+
|
|
127
|
+
rounded = int(round(milliseconds))
|
|
128
|
+
if rounded < minimum:
|
|
129
|
+
raise ValueNormalizationError(
|
|
130
|
+
f"Duration must be >= {minimum}ms",
|
|
131
|
+
code="duration_out_of_range",
|
|
132
|
+
value=value,
|
|
133
|
+
)
|
|
134
|
+
return rounded
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def parse_ratio(value: Any) -> float:
|
|
138
|
+
"""Accept ``0.5`` or ``50%``; return a float between 0 and 1."""
|
|
139
|
+
if isinstance(value, bool):
|
|
140
|
+
raise _invalid_value("invalid_ratio", "Ratio must be between 0 and 1 or use a percentage", value)
|
|
141
|
+
if isinstance(value, (int, float)):
|
|
142
|
+
ratio = float(value)
|
|
143
|
+
elif isinstance(value, str):
|
|
144
|
+
text = value.strip()
|
|
145
|
+
percent = _PERCENT_RE.fullmatch(text)
|
|
146
|
+
if percent is not None:
|
|
147
|
+
ratio = float(percent.group(1)) / 100.0
|
|
148
|
+
else:
|
|
149
|
+
try:
|
|
150
|
+
ratio = float(text)
|
|
151
|
+
except ValueError as exc:
|
|
152
|
+
raise _invalid_value(
|
|
153
|
+
"invalid_ratio",
|
|
154
|
+
"Ratio must be between 0 and 1 or use a percentage such as 50%",
|
|
155
|
+
value,
|
|
156
|
+
) from exc
|
|
157
|
+
else:
|
|
158
|
+
raise _invalid_value("invalid_ratio", "Ratio must be between 0 and 1 or use a percentage", value)
|
|
159
|
+
if not 0.0 <= ratio <= 1.0:
|
|
160
|
+
raise ValueNormalizationError(
|
|
161
|
+
"Ratio must be between 0 and 1",
|
|
162
|
+
code="ratio_out_of_range",
|
|
163
|
+
value=value,
|
|
164
|
+
)
|
|
165
|
+
return ratio
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
def parse_angle_degrees(value: Any) -> float:
|
|
169
|
+
"""Accept ``90``, ``90deg`` or ``90°``; return a float in ``[0, 360)``."""
|
|
170
|
+
if isinstance(value, bool):
|
|
171
|
+
raise _invalid_value("invalid_angle", "Angle must be numeric or use deg", value)
|
|
172
|
+
if isinstance(value, (int, float)):
|
|
173
|
+
angle = float(value)
|
|
174
|
+
elif isinstance(value, str):
|
|
175
|
+
match = _ANGLE_RE.fullmatch(value.strip())
|
|
176
|
+
if match is None:
|
|
177
|
+
raise _invalid_value("invalid_angle", "Angle must use a value such as 90 or 90deg", value)
|
|
178
|
+
angle = float(match.group(1))
|
|
179
|
+
else:
|
|
180
|
+
raise _invalid_value("invalid_angle", "Angle must be numeric or use deg", value)
|
|
181
|
+
return angle % 360.0
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
def parse_bool(value: Any) -> bool:
|
|
185
|
+
"""Accept English and German switch words as well as ``0``/``1``."""
|
|
186
|
+
if isinstance(value, bool):
|
|
187
|
+
return value
|
|
188
|
+
if isinstance(value, int) and value in {0, 1}:
|
|
189
|
+
return bool(value)
|
|
190
|
+
if isinstance(value, str):
|
|
191
|
+
normalized = value.strip().casefold()
|
|
192
|
+
if normalized in {"1", "true", "yes", "on", "ja", "an"}:
|
|
193
|
+
return True
|
|
194
|
+
if normalized in {"0", "false", "no", "off", "nein", "aus"}:
|
|
195
|
+
return False
|
|
196
|
+
raise _invalid_value(
|
|
197
|
+
"invalid_boolean",
|
|
198
|
+
"Boolean must be true/false, on/off, an/aus or ja/nein",
|
|
199
|
+
value,
|
|
200
|
+
)
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
def _invalid_color(value: Any) -> ValueNormalizationError:
|
|
204
|
+
return ValueNormalizationError(
|
|
205
|
+
"Color must be a named color, #RRGGBB, 0xRRGGBB or an RGB integer",
|
|
206
|
+
code="invalid_color",
|
|
207
|
+
value=value,
|
|
208
|
+
)
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
def _invalid_value(code: str, message: str, value: Any) -> ValueNormalizationError:
|
|
212
|
+
return ValueNormalizationError(message, code=code, value=value)
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"""Where the core set's archive is, and nothing else.
|
|
2
|
+
|
|
3
|
+
A catalogue distribution carries one file and answers one question. The
|
|
4
|
+
question has to be answerable without unpacking anything, because the service
|
|
5
|
+
asks it before it has decided to load the set at all — so this is a path, not a
|
|
6
|
+
reader.
|
|
7
|
+
|
|
8
|
+
The archive sits beside this module rather than in a data directory: an
|
|
9
|
+
installed wheel and an editable checkout then look the same, and the checkout
|
|
10
|
+
needs no second search path for built output.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
|
|
17
|
+
SET_ID = "core-set"
|
|
18
|
+
ARCHIVE_NAME = "core-set.lefxset"
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def package_file() -> Path:
|
|
22
|
+
"""The ``.lefxset`` this distribution ships.
|
|
23
|
+
|
|
24
|
+
Returned whether or not it exists. In a checkout it does not until
|
|
25
|
+
``scripts/build_effects.py`` has run, and reporting a missing catalogue is
|
|
26
|
+
the caller's job — a set that silently disappears is worse than one that
|
|
27
|
+
says it has not been built.
|
|
28
|
+
"""
|
|
29
|
+
return Path(__file__).resolve().parent / ARCHIVE_NAME
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
__all__ = ["ARCHIVE_NAME", "SET_ID", "package_file"]
|
|
Binary file
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"""Where the smartspeaker set's archive is, and nothing else.
|
|
2
|
+
|
|
3
|
+
A catalogue distribution carries one file and answers one question. The
|
|
4
|
+
question has to be answerable without unpacking anything, because the service
|
|
5
|
+
asks it before it has decided to load the set at all — so this is a path, not a
|
|
6
|
+
reader.
|
|
7
|
+
|
|
8
|
+
The archive sits beside this module rather than in a data directory: an
|
|
9
|
+
installed wheel and an editable checkout then look the same, and the checkout
|
|
10
|
+
needs no second search path for built output.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
|
|
17
|
+
SET_ID = "smartspeaker-set"
|
|
18
|
+
ARCHIVE_NAME = "smartspeaker-set.lefxset"
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def package_file() -> Path:
|
|
22
|
+
"""The ``.lefxset`` this distribution ships.
|
|
23
|
+
|
|
24
|
+
Returned whether or not it exists. In a checkout it does not until
|
|
25
|
+
``scripts/build_effects.py`` has run, and reporting a missing catalogue is
|
|
26
|
+
the caller's job — a set that silently disappears is worse than one that
|
|
27
|
+
says it has not been built.
|
|
28
|
+
"""
|
|
29
|
+
return Path(__file__).resolve().parent / ARCHIVE_NAME
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
__all__ = ["ARCHIVE_NAME", "SET_ID", "package_file"]
|
|
Binary file
|