aiofindpop 0.1.0__tar.gz
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.
- aiofindpop-0.1.0/.gitignore +18 -0
- aiofindpop-0.1.0/LICENSE +21 -0
- aiofindpop-0.1.0/PKG-INFO +226 -0
- aiofindpop-0.1.0/README.md +176 -0
- aiofindpop-0.1.0/aiofindpop/__init__.py +57 -0
- aiofindpop-0.1.0/aiofindpop/commands.py +224 -0
- aiofindpop-0.1.0/aiofindpop/connection.py +127 -0
- aiofindpop-0.1.0/aiofindpop/const.py +63 -0
- aiofindpop-0.1.0/aiofindpop/device.py +215 -0
- aiofindpop-0.1.0/aiofindpop/discovery.py +135 -0
- aiofindpop-0.1.0/aiofindpop/exceptions.py +23 -0
- aiofindpop-0.1.0/aiofindpop/models.py +141 -0
- aiofindpop-0.1.0/aiofindpop/py.typed +0 -0
- aiofindpop-0.1.0/pyproject.toml +95 -0
- aiofindpop-0.1.0/tests/__init__.py +1 -0
- aiofindpop-0.1.0/tests/conftest.py +105 -0
- aiofindpop-0.1.0/tests/test_commands.py +111 -0
- aiofindpop-0.1.0/tests/test_connection.py +114 -0
- aiofindpop-0.1.0/tests/test_device.py +186 -0
- aiofindpop-0.1.0/tests/test_discovery.py +109 -0
- aiofindpop-0.1.0/tests/test_models.py +70 -0
aiofindpop-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Gene Hand
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: aiofindpop
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Async client for FindPop / KBD CL441 curtain lights over the local network
|
|
5
|
+
Project-URL: Source Code, https://github.com/genehand/aiofindpop
|
|
6
|
+
Project-URL: Bug Reports, https://github.com/genehand/aiofindpop/issues
|
|
7
|
+
License: MIT License
|
|
8
|
+
|
|
9
|
+
Copyright (c) 2025 Gene Hand
|
|
10
|
+
|
|
11
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
12
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
13
|
+
in the Software without restriction, including without limitation the rights
|
|
14
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
15
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
16
|
+
furnished to do so, subject to the following conditions:
|
|
17
|
+
|
|
18
|
+
The above copyright notice and this permission notice shall be included in all
|
|
19
|
+
copies or substantial portions of the Software.
|
|
20
|
+
|
|
21
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
22
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
23
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
24
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
25
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
26
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
27
|
+
SOFTWARE.
|
|
28
|
+
License-File: LICENSE
|
|
29
|
+
Keywords: async,asyncio,findpop,home-assistant,kbd
|
|
30
|
+
Classifier: Development Status :: 4 - Beta
|
|
31
|
+
Classifier: Framework :: AsyncIO
|
|
32
|
+
Classifier: Intended Audience :: Developers
|
|
33
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
34
|
+
Classifier: Operating System :: OS Independent
|
|
35
|
+
Classifier: Programming Language :: Python :: 3
|
|
36
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
37
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
38
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
39
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
40
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
41
|
+
Classifier: Typing :: Typed
|
|
42
|
+
Requires-Python: >=3.11
|
|
43
|
+
Requires-Dist: aiohttp>=3.9.0
|
|
44
|
+
Provides-Extra: dev
|
|
45
|
+
Requires-Dist: mypy>=1.13; extra == 'dev'
|
|
46
|
+
Requires-Dist: pytest-asyncio>=0.24; extra == 'dev'
|
|
47
|
+
Requires-Dist: pytest>=8.3; extra == 'dev'
|
|
48
|
+
Requires-Dist: ruff>=0.8; extra == 'dev'
|
|
49
|
+
Description-Content-Type: text/markdown
|
|
50
|
+
|
|
51
|
+
# aiofindpop
|
|
52
|
+
|
|
53
|
+
Async Python client for **FindPop / KBD "CL441" curtain lights**.
|
|
54
|
+
|
|
55
|
+
The device is an ESP32 with a small HTTP server on port 80. Every command is a
|
|
56
|
+
`POST /kbd` whose body is an ASCII command plus raw arguments. There is no
|
|
57
|
+
authentication, no cloud dependency, and no push channel. This library wraps that
|
|
58
|
+
protocol behind a small async API and is intended to back a Home Assistant
|
|
59
|
+
integration.
|
|
60
|
+
|
|
61
|
+
```python
|
|
62
|
+
import asyncio
|
|
63
|
+
from collections.abc import AsyncIterator
|
|
64
|
+
import aiohttp
|
|
65
|
+
from aiofindpop import FindPopConnection, FindPopDevice
|
|
66
|
+
|
|
67
|
+
async def main() -> None:
|
|
68
|
+
async with aiohttp.ClientSession() as session:
|
|
69
|
+
device = FindPopDevice("192.168.1.x", session=session)
|
|
70
|
+
|
|
71
|
+
info = await device.async_update()
|
|
72
|
+
print(info.name, info.version, info.led_count, info.is_on)
|
|
73
|
+
|
|
74
|
+
await device.async_turn_on()
|
|
75
|
+
await device.async_set_color("#1e90ff")
|
|
76
|
+
await device.async_set_brightness(40)
|
|
77
|
+
|
|
78
|
+
asyncio.run(main())
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Installation
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
pip install aiofindpop
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Requires Python 3.11+ and `aiohttp`. `py.typed` is included.
|
|
88
|
+
|
|
89
|
+
## Design
|
|
90
|
+
|
|
91
|
+
Following the [Home Assistant API library guidelines](https://contributors.home-assistant.io/core/integrations/api-library/),
|
|
92
|
+
the package is split in two:
|
|
93
|
+
|
|
94
|
+
| Module | Role |
|
|
95
|
+
|---|---|
|
|
96
|
+
| `connection.py` | The transport (the "auth" layer). The only code that talks to the device. Holds the caller's `aiohttp.ClientSession`, the host, the timeout, and an `asyncio.Lock` that serializes commands. |
|
|
97
|
+
| `device.py` | `FindPopDevice`: writes as methods, state as a separate snapshot. |
|
|
98
|
+
| `models.py` | `FindPopInfo`: everything `/getinfo?` reports, unconverted, with the device's own units. |
|
|
99
|
+
| `commands.py` | Pure functions that build command bodies; tested against captures. |
|
|
100
|
+
| `discovery.py` | UDP broadcast discovery, returning MAC → host. |
|
|
101
|
+
| `exceptions.py` | `FindPopError`, `FindPopConnectionError`, `FindPopProtocolError`. |
|
|
102
|
+
|
|
103
|
+
No session is created internally: pass Home Assistant's shared session. The library
|
|
104
|
+
never polls and never converts units — brightness stays on the device's 0-100 scale,
|
|
105
|
+
and the integration scales to 0-255.
|
|
106
|
+
|
|
107
|
+
## API
|
|
108
|
+
|
|
109
|
+
```python
|
|
110
|
+
FindPopDevice(host, *, session, port=80, timeout=5.0) # what an integration uses
|
|
111
|
+
FindPopConnection(host, *, session, port=80, timeout=5.0) # lower level transport
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Both take the host first and the caller's session as a keyword, matching other
|
|
115
|
+
Home Assistant libraries. `FindPopDevice` creates and exposes its `connection`.
|
|
116
|
+
|
|
117
|
+
| Method | Wire command | Notes |
|
|
118
|
+
|---|---|---|
|
|
119
|
+
| `async_update()` | `/getinfo?` | Returns `FindPopInfo`; requires `code == 11`. |
|
|
120
|
+
| `async_turn_on()` / `async_turn_off()` / `async_set_power(on)` | `/lightp?\x01` / `\x00` | Byte polarity is inverted, see below. |
|
|
121
|
+
| `async_set_brightness(0-100)` | `/setb?<byte>` | Clamped; leaves the strip on. |
|
|
122
|
+
| `async_set_color("#rrggbb", zone=, rows=, slot=)` | `/setdata?<json>` | The verified paint path. |
|
|
123
|
+
| `async_set_sensitivity(0-100)` | `/sets?<byte>\x01` | Microphone sensitivity. |
|
|
124
|
+
| `async_set_mirror(bool)` | `/mirror?<0|1>` | Layout mirror. |
|
|
125
|
+
| `async_set_name(str)` | `/setname?<ascii>` | Rename the device. |
|
|
126
|
+
| `async_cancel_effect(bool)` | `/canc?<0|1>` | Stop the running effect. |
|
|
127
|
+
| `async_set_timer(on_min, off_min, current_time=0)` | `/settimer?` | 10-byte big-endian payload. |
|
|
128
|
+
| `async_play_pattern(index)` | `/setp?<u16 LE>` | Built-in pattern; re-asserts power. |
|
|
129
|
+
| `async_send_playlist(entry)` | `/setp?<json>` | One playlist entry (the playlist lives in the app). |
|
|
130
|
+
| `async_set_pixels(rgb)` | `/setD?<json>` | **Unverified** |
|
|
131
|
+
| `async_show_demo(bool)` | `/showon?` / `/showoff?` | Demo overlay. |
|
|
132
|
+
| `async_configure_wifi(ssid, password)` | `/configwifi?<json>` | Wi-Fi provisioning. |
|
|
133
|
+
|
|
134
|
+
`FindPopInfo` exposes `code`, `name`, `version`, `ip`, `ssid`, `leds`, `led_count`,
|
|
135
|
+
`model`, `brightness`, `sensitivity`, `power`, `is_on`, `hex_color`, `mirror`,
|
|
136
|
+
`run_time`, `on_timer`, `off_timer`, `mqtt_connected`, plus the untouched `raw_data`.
|
|
137
|
+
|
|
138
|
+
Discovery, for a config flow:
|
|
139
|
+
|
|
140
|
+
```python
|
|
141
|
+
from aiofindpop import async_discover_devices
|
|
142
|
+
|
|
143
|
+
for mac, dev in (await async_discover_devices(timeout=2.0)).items():
|
|
144
|
+
print(mac, dev.host)
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## Three things that can trip you up
|
|
148
|
+
|
|
149
|
+
1. **`power` is inverted.** `/getinfo?` reports `power: 0` while the strip is lit and
|
|
150
|
+
`power: 1` while it is dark, matching the command byte (`\x01` = on). Read
|
|
151
|
+
`FindPopInfo.is_on`, not `power`.
|
|
152
|
+
2. **`/edit?` does not paint.** It updates the reported `hexColor` and nothing else.
|
|
153
|
+
Only the `/setdata?` body with the opaque `c` template and the `e` color wrapper
|
|
154
|
+
lights the LEDs. `commands.color_command()` builds exactly that.
|
|
155
|
+
3. **Never send a body shorter than 3 bytes.** The firmware drops the TCP connection.
|
|
156
|
+
The library rejects short bodies before they reach the socket.
|
|
157
|
+
|
|
158
|
+
Also: `POST /kbd` returns `200` with an empty body for almost everything, so a
|
|
159
|
+
successful write means "accepted", not "applied" — poll `/getinfo?` to confirm. And
|
|
160
|
+
`/setb?` already leaves the strip on; sending a power command after a brightness
|
|
161
|
+
change turns it **off**.
|
|
162
|
+
|
|
163
|
+
The ESP32 httpd is small and drops connections when requests overlap, so
|
|
164
|
+
`FindPopConnection` serializes every command behind one lock. Keep one connection per
|
|
165
|
+
device and reuse it.
|
|
166
|
+
|
|
167
|
+
## Using it from Home Assistant
|
|
168
|
+
|
|
169
|
+
```python
|
|
170
|
+
from aiofindpop import FindPopDevice, FindPopConnectionError
|
|
171
|
+
|
|
172
|
+
device = FindPopDevice(host, session=async_get_clientsession(hass))
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
* In the coordinator, call `await device.async_update()` and raise
|
|
176
|
+
`UpdateFailed` on `FindPopConnectionError`. There are no credentials, so there is
|
|
177
|
+
nothing to reauthenticate; a device that stops answering is just unavailable.
|
|
178
|
+
* Map `FindPopProtocolError` to `UpdateFailed` too, but log it: it means the firmware
|
|
179
|
+
answered something unexpected, which usually precedes a bug report.
|
|
180
|
+
* The light entity derives `is_on` from `info.is_on`, scales
|
|
181
|
+
`brightness * 255 // 100` and back, and parses `info.hex_color` (`None` in
|
|
182
|
+
effect/image mode).
|
|
183
|
+
* There is no push channel. Poll every 10 s; `/getinfo?` answers in ~90 ms on a LAN.
|
|
184
|
+
* Unique ID: query the MAC with `async_discover_devices(addresses=[host])` once
|
|
185
|
+
during the config flow, and fall back to the host if the device does not answer
|
|
186
|
+
discovery. The UDP reply contains the raw 6-byte MAC.
|
|
187
|
+
* Device registry: `manufacturer="Findpop"`, `model=f"CL{info.led_count}"`,
|
|
188
|
+
`sw_version=info.version`, name from `info.name`.
|
|
189
|
+
|
|
190
|
+
## Limitations
|
|
191
|
+
|
|
192
|
+
* Pixel frames (`/setD?`, color type 5 RGB24) are accepted but have never been
|
|
193
|
+
observed to light the strip on firmware 2.1.13; something the app only sends over
|
|
194
|
+
UDP appears to gate rendering. `async_set_pixels` is a starting point, not a
|
|
195
|
+
supported feature.
|
|
196
|
+
* Playlists are pushed by the app, entry by entry. The device stores no playlist.
|
|
197
|
+
* No BLE support: the app's BLE side is unencrypted BLUFI, but it is out of scope
|
|
198
|
+
here. Wi-Fi/HTTP is enough for Home Assistant.
|
|
199
|
+
* Timers are sent, not interpreted; the device does not report them back in a form
|
|
200
|
+
the app displays.
|
|
201
|
+
|
|
202
|
+
## Development
|
|
203
|
+
|
|
204
|
+
```bash
|
|
205
|
+
python -m venv .venv
|
|
206
|
+
.venv/bin/pip install -e ".[dev]"
|
|
207
|
+
|
|
208
|
+
.venv/bin/pytest
|
|
209
|
+
.venv/bin/ruff check .
|
|
210
|
+
.venv/bin/mypy aiofindpop
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
The tests run against an `aiohttp` test server that records `/kbd` bodies, so no
|
|
214
|
+
hardware is needed. To exercise a real device:
|
|
215
|
+
|
|
216
|
+
```bash
|
|
217
|
+
.venv/bin/python examples/usage.py 192.168.1.x
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
## Releasing
|
|
221
|
+
|
|
222
|
+
`pyproject.toml` carries the version. Publishing is automated: push a tag matching
|
|
223
|
+
`v<version>` (for example `v0.1.0`) and `.github/workflows/release.yml` builds the
|
|
224
|
+
sdist/wheel and uploads to PyPI via trusted publishing. CI refuses a tag that does
|
|
225
|
+
not match the version, and every release must have a matching tag in the public
|
|
226
|
+
repository, as Home Assistant requires.
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
# aiofindpop
|
|
2
|
+
|
|
3
|
+
Async Python client for **FindPop / KBD "CL441" curtain lights**.
|
|
4
|
+
|
|
5
|
+
The device is an ESP32 with a small HTTP server on port 80. Every command is a
|
|
6
|
+
`POST /kbd` whose body is an ASCII command plus raw arguments. There is no
|
|
7
|
+
authentication, no cloud dependency, and no push channel. This library wraps that
|
|
8
|
+
protocol behind a small async API and is intended to back a Home Assistant
|
|
9
|
+
integration.
|
|
10
|
+
|
|
11
|
+
```python
|
|
12
|
+
import asyncio
|
|
13
|
+
from collections.abc import AsyncIterator
|
|
14
|
+
import aiohttp
|
|
15
|
+
from aiofindpop import FindPopConnection, FindPopDevice
|
|
16
|
+
|
|
17
|
+
async def main() -> None:
|
|
18
|
+
async with aiohttp.ClientSession() as session:
|
|
19
|
+
device = FindPopDevice("192.168.1.x", session=session)
|
|
20
|
+
|
|
21
|
+
info = await device.async_update()
|
|
22
|
+
print(info.name, info.version, info.led_count, info.is_on)
|
|
23
|
+
|
|
24
|
+
await device.async_turn_on()
|
|
25
|
+
await device.async_set_color("#1e90ff")
|
|
26
|
+
await device.async_set_brightness(40)
|
|
27
|
+
|
|
28
|
+
asyncio.run(main())
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Installation
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
pip install aiofindpop
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Requires Python 3.11+ and `aiohttp`. `py.typed` is included.
|
|
38
|
+
|
|
39
|
+
## Design
|
|
40
|
+
|
|
41
|
+
Following the [Home Assistant API library guidelines](https://contributors.home-assistant.io/core/integrations/api-library/),
|
|
42
|
+
the package is split in two:
|
|
43
|
+
|
|
44
|
+
| Module | Role |
|
|
45
|
+
|---|---|
|
|
46
|
+
| `connection.py` | The transport (the "auth" layer). The only code that talks to the device. Holds the caller's `aiohttp.ClientSession`, the host, the timeout, and an `asyncio.Lock` that serializes commands. |
|
|
47
|
+
| `device.py` | `FindPopDevice`: writes as methods, state as a separate snapshot. |
|
|
48
|
+
| `models.py` | `FindPopInfo`: everything `/getinfo?` reports, unconverted, with the device's own units. |
|
|
49
|
+
| `commands.py` | Pure functions that build command bodies; tested against captures. |
|
|
50
|
+
| `discovery.py` | UDP broadcast discovery, returning MAC → host. |
|
|
51
|
+
| `exceptions.py` | `FindPopError`, `FindPopConnectionError`, `FindPopProtocolError`. |
|
|
52
|
+
|
|
53
|
+
No session is created internally: pass Home Assistant's shared session. The library
|
|
54
|
+
never polls and never converts units — brightness stays on the device's 0-100 scale,
|
|
55
|
+
and the integration scales to 0-255.
|
|
56
|
+
|
|
57
|
+
## API
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
FindPopDevice(host, *, session, port=80, timeout=5.0) # what an integration uses
|
|
61
|
+
FindPopConnection(host, *, session, port=80, timeout=5.0) # lower level transport
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Both take the host first and the caller's session as a keyword, matching other
|
|
65
|
+
Home Assistant libraries. `FindPopDevice` creates and exposes its `connection`.
|
|
66
|
+
|
|
67
|
+
| Method | Wire command | Notes |
|
|
68
|
+
|---|---|---|
|
|
69
|
+
| `async_update()` | `/getinfo?` | Returns `FindPopInfo`; requires `code == 11`. |
|
|
70
|
+
| `async_turn_on()` / `async_turn_off()` / `async_set_power(on)` | `/lightp?\x01` / `\x00` | Byte polarity is inverted, see below. |
|
|
71
|
+
| `async_set_brightness(0-100)` | `/setb?<byte>` | Clamped; leaves the strip on. |
|
|
72
|
+
| `async_set_color("#rrggbb", zone=, rows=, slot=)` | `/setdata?<json>` | The verified paint path. |
|
|
73
|
+
| `async_set_sensitivity(0-100)` | `/sets?<byte>\x01` | Microphone sensitivity. |
|
|
74
|
+
| `async_set_mirror(bool)` | `/mirror?<0|1>` | Layout mirror. |
|
|
75
|
+
| `async_set_name(str)` | `/setname?<ascii>` | Rename the device. |
|
|
76
|
+
| `async_cancel_effect(bool)` | `/canc?<0|1>` | Stop the running effect. |
|
|
77
|
+
| `async_set_timer(on_min, off_min, current_time=0)` | `/settimer?` | 10-byte big-endian payload. |
|
|
78
|
+
| `async_play_pattern(index)` | `/setp?<u16 LE>` | Built-in pattern; re-asserts power. |
|
|
79
|
+
| `async_send_playlist(entry)` | `/setp?<json>` | One playlist entry (the playlist lives in the app). |
|
|
80
|
+
| `async_set_pixels(rgb)` | `/setD?<json>` | **Unverified** |
|
|
81
|
+
| `async_show_demo(bool)` | `/showon?` / `/showoff?` | Demo overlay. |
|
|
82
|
+
| `async_configure_wifi(ssid, password)` | `/configwifi?<json>` | Wi-Fi provisioning. |
|
|
83
|
+
|
|
84
|
+
`FindPopInfo` exposes `code`, `name`, `version`, `ip`, `ssid`, `leds`, `led_count`,
|
|
85
|
+
`model`, `brightness`, `sensitivity`, `power`, `is_on`, `hex_color`, `mirror`,
|
|
86
|
+
`run_time`, `on_timer`, `off_timer`, `mqtt_connected`, plus the untouched `raw_data`.
|
|
87
|
+
|
|
88
|
+
Discovery, for a config flow:
|
|
89
|
+
|
|
90
|
+
```python
|
|
91
|
+
from aiofindpop import async_discover_devices
|
|
92
|
+
|
|
93
|
+
for mac, dev in (await async_discover_devices(timeout=2.0)).items():
|
|
94
|
+
print(mac, dev.host)
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Three things that can trip you up
|
|
98
|
+
|
|
99
|
+
1. **`power` is inverted.** `/getinfo?` reports `power: 0` while the strip is lit and
|
|
100
|
+
`power: 1` while it is dark, matching the command byte (`\x01` = on). Read
|
|
101
|
+
`FindPopInfo.is_on`, not `power`.
|
|
102
|
+
2. **`/edit?` does not paint.** It updates the reported `hexColor` and nothing else.
|
|
103
|
+
Only the `/setdata?` body with the opaque `c` template and the `e` color wrapper
|
|
104
|
+
lights the LEDs. `commands.color_command()` builds exactly that.
|
|
105
|
+
3. **Never send a body shorter than 3 bytes.** The firmware drops the TCP connection.
|
|
106
|
+
The library rejects short bodies before they reach the socket.
|
|
107
|
+
|
|
108
|
+
Also: `POST /kbd` returns `200` with an empty body for almost everything, so a
|
|
109
|
+
successful write means "accepted", not "applied" — poll `/getinfo?` to confirm. And
|
|
110
|
+
`/setb?` already leaves the strip on; sending a power command after a brightness
|
|
111
|
+
change turns it **off**.
|
|
112
|
+
|
|
113
|
+
The ESP32 httpd is small and drops connections when requests overlap, so
|
|
114
|
+
`FindPopConnection` serializes every command behind one lock. Keep one connection per
|
|
115
|
+
device and reuse it.
|
|
116
|
+
|
|
117
|
+
## Using it from Home Assistant
|
|
118
|
+
|
|
119
|
+
```python
|
|
120
|
+
from aiofindpop import FindPopDevice, FindPopConnectionError
|
|
121
|
+
|
|
122
|
+
device = FindPopDevice(host, session=async_get_clientsession(hass))
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
* In the coordinator, call `await device.async_update()` and raise
|
|
126
|
+
`UpdateFailed` on `FindPopConnectionError`. There are no credentials, so there is
|
|
127
|
+
nothing to reauthenticate; a device that stops answering is just unavailable.
|
|
128
|
+
* Map `FindPopProtocolError` to `UpdateFailed` too, but log it: it means the firmware
|
|
129
|
+
answered something unexpected, which usually precedes a bug report.
|
|
130
|
+
* The light entity derives `is_on` from `info.is_on`, scales
|
|
131
|
+
`brightness * 255 // 100` and back, and parses `info.hex_color` (`None` in
|
|
132
|
+
effect/image mode).
|
|
133
|
+
* There is no push channel. Poll every 10 s; `/getinfo?` answers in ~90 ms on a LAN.
|
|
134
|
+
* Unique ID: query the MAC with `async_discover_devices(addresses=[host])` once
|
|
135
|
+
during the config flow, and fall back to the host if the device does not answer
|
|
136
|
+
discovery. The UDP reply contains the raw 6-byte MAC.
|
|
137
|
+
* Device registry: `manufacturer="Findpop"`, `model=f"CL{info.led_count}"`,
|
|
138
|
+
`sw_version=info.version`, name from `info.name`.
|
|
139
|
+
|
|
140
|
+
## Limitations
|
|
141
|
+
|
|
142
|
+
* Pixel frames (`/setD?`, color type 5 RGB24) are accepted but have never been
|
|
143
|
+
observed to light the strip on firmware 2.1.13; something the app only sends over
|
|
144
|
+
UDP appears to gate rendering. `async_set_pixels` is a starting point, not a
|
|
145
|
+
supported feature.
|
|
146
|
+
* Playlists are pushed by the app, entry by entry. The device stores no playlist.
|
|
147
|
+
* No BLE support: the app's BLE side is unencrypted BLUFI, but it is out of scope
|
|
148
|
+
here. Wi-Fi/HTTP is enough for Home Assistant.
|
|
149
|
+
* Timers are sent, not interpreted; the device does not report them back in a form
|
|
150
|
+
the app displays.
|
|
151
|
+
|
|
152
|
+
## Development
|
|
153
|
+
|
|
154
|
+
```bash
|
|
155
|
+
python -m venv .venv
|
|
156
|
+
.venv/bin/pip install -e ".[dev]"
|
|
157
|
+
|
|
158
|
+
.venv/bin/pytest
|
|
159
|
+
.venv/bin/ruff check .
|
|
160
|
+
.venv/bin/mypy aiofindpop
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
The tests run against an `aiohttp` test server that records `/kbd` bodies, so no
|
|
164
|
+
hardware is needed. To exercise a real device:
|
|
165
|
+
|
|
166
|
+
```bash
|
|
167
|
+
.venv/bin/python examples/usage.py 192.168.1.x
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
## Releasing
|
|
171
|
+
|
|
172
|
+
`pyproject.toml` carries the version. Publishing is automated: push a tag matching
|
|
173
|
+
`v<version>` (for example `v0.1.0`) and `.github/workflows/release.yml` builds the
|
|
174
|
+
sdist/wheel and uploads to PyPI via trusted publishing. CI refuses a tag that does
|
|
175
|
+
not match the version, and every release must have a matching tag in the public
|
|
176
|
+
repository, as Home Assistant requires.
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"""Async client for FindPop / KBD "CL441" curtain lights.
|
|
2
|
+
|
|
3
|
+
The library speaks the device's local HTTP protocol: every command is a body posted
|
|
4
|
+
to ``/kbd`` on port 80. It is async, uses the caller's ``aiohttp.ClientSession``, and
|
|
5
|
+
raises its own exceptions so an integration can tell an offline device from a device
|
|
6
|
+
that answered something unexpected.
|
|
7
|
+
|
|
8
|
+
Example:
|
|
9
|
+
>>> import aiohttp
|
|
10
|
+
>>> from aiofindpop import FindPopDevice
|
|
11
|
+
>>> async with aiohttp.ClientSession() as session:
|
|
12
|
+
... device = FindPopDevice("192.168.1.x", session=session)
|
|
13
|
+
... info = await device.async_update()
|
|
14
|
+
... print(info.name, info.version, info.is_on)
|
|
15
|
+
... await device.async_set_color("#1e90ff")
|
|
16
|
+
|
|
17
|
+
Protocol notes, including the inverted ``power`` field and the color template the
|
|
18
|
+
device needs, are in the project README.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
from __future__ import annotations
|
|
22
|
+
|
|
23
|
+
from .connection import FindPopConnection
|
|
24
|
+
from .const import (
|
|
25
|
+
COMMAND_PATH,
|
|
26
|
+
DEFAULT_PORT,
|
|
27
|
+
DEFAULT_TIMEOUT,
|
|
28
|
+
DISCOVERY_PORT,
|
|
29
|
+
INFO_SUCCESS_CODE,
|
|
30
|
+
MIN_COMMAND_LENGTH,
|
|
31
|
+
)
|
|
32
|
+
from .device import FindPopDevice
|
|
33
|
+
from .discovery import DiscoveredDevice, async_discover_devices, parse_mac
|
|
34
|
+
from .exceptions import (
|
|
35
|
+
FindPopConnectionError,
|
|
36
|
+
FindPopError,
|
|
37
|
+
FindPopProtocolError,
|
|
38
|
+
)
|
|
39
|
+
from .models import FindPopInfo
|
|
40
|
+
|
|
41
|
+
__all__ = [
|
|
42
|
+
"COMMAND_PATH",
|
|
43
|
+
"DEFAULT_PORT",
|
|
44
|
+
"DEFAULT_TIMEOUT",
|
|
45
|
+
"DISCOVERY_PORT",
|
|
46
|
+
"INFO_SUCCESS_CODE",
|
|
47
|
+
"MIN_COMMAND_LENGTH",
|
|
48
|
+
"DiscoveredDevice",
|
|
49
|
+
"FindPopConnection",
|
|
50
|
+
"FindPopConnectionError",
|
|
51
|
+
"FindPopDevice",
|
|
52
|
+
"FindPopError",
|
|
53
|
+
"FindPopInfo",
|
|
54
|
+
"FindPopProtocolError",
|
|
55
|
+
"async_discover_devices",
|
|
56
|
+
"parse_mac",
|
|
57
|
+
]
|