discovery
UDP discovery for Twinkly devices.
DISCOVERY_MESSAGE = b'\x01discover'
module-attribute
¶
DISCOVERY_PORT = 5555
module-attribute
¶
DEFAULT_BROADCAST = '255.255.255.255'
module-attribute
¶
DiscoveredDevice
dataclass
¶
Address and identifier advertised by a Twinkly discovery reply.
Source code in tinkly/discovery.py
parse_discovery_response(data: bytes) -> DiscoveredDevice
¶
Decode one discovery reply containing an IPv4 address and device ID.
Raises:
| Type | Description |
|---|---|
DiscoveryError
|
The packet is too short, lacks OK status, or lacks its terminating NUL byte. |
UnicodeDecodeError
|
The device identifier is not valid UTF-8. |
Source code in tinkly/discovery.py
discover(timeout: float = 2.0, grouping: float = 0.1, destination: str = DEFAULT_BROADCAST) -> Iterator[DiscoveredDevice]
¶
Broadcast a discovery request and yield each responding IPv4 address once.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout
|
float
|
Seconds to wait for the first valid device response. |
2.0
|
grouping
|
float
|
Seconds to collect further responses after the first valid response. Later replies do not extend this window. |
0.1
|
destination
|
str
|
IPv4 broadcast address or a specific device address. |
DEFAULT_BROADCAST
|
Devices are yielded as replies arrive. Exhausting the iterator waits until its deadline; an empty scan waits for timeout. Socket timeouts and the echoed request are ignored. Other socket errors and malformed reply errors propagate. Duplicate devices are identified by their advertised IP address. Consume promptly, normally with list(discover()), to collect the full scan. Time spent by the consumer between results counts toward the deadline and can leave timely replies unread in the socket when the iterator resumes.