Repository navigation
2.6
Subscribe to device events instead of polling
A device can push its changes rather than being asked for them. Each key is
named for the method returning the same value, so is_muted in an event is
what is_muted() would have returned.
def on_event(changes):
if changes.get("is_subscribed") is False:
return # subscription lost; treat the state as stale
print(changes) # {"volume": 42, "is_muted": False}
if device.events_enabled:
await device.subscribe(on_event)
...
await device.unsubscribe()The first event after subscribing carries the device's whole state; after
that only what changed. Subscribing needs the Product, Transport and Info
services — events_enabled says whether this device has them, and
subscribe() raises OpenhomeDeviceError if it does not, so older firmware
and third party renderers should keep polling.
Subscriptions are renewed in the background. If one cannot be renewed the
rest are released and the callback is called a final time with
{"is_subscribed": False}; call subscribe() again to recover.
By default a notify server is started per device. Pass an event_handler to
the constructor to share one across several, in the same way a session can
already be shared.
Report what the device can do with what is playing
Rather than guessing from the source type, ask the device.
await device.can_pause() # False on a turntable at a line input
await device.can_skip_next() # True on a playlist
await device.can_skip_previous()Each returns None on a device with no Transport service, meaning it cannot
say rather than the answer being no, so a caller can fall back to guessing
from the source type as before.
Fixes
sources() now reads <Visible>1</Visible> as well as <Visible>true</Visible>,
so it no longer returns an empty list on AURALiC devices. Diagnosed by
@droman42 in #26.
await device.sources() # ['Playlist', 'Radio', 'Songcast', 'Spotify']pins_enabled reports whether the Pins service resolved, rather than whether
the device advertises Pins version 1 specifically, so a later version of the
service no longer reads as having no pins at all.
What's Changed
- Tidy setup.py and delete the dead setup.cfg by @bazwilliams in #28
- Report what the device can do with what is playing by @bazwilliams in #29
- Subscribe to device events instead of polling by @bazwilliams in #30
- Bump version to 2.6 by @bazwilliams in #31
Full Changelog: 2.5...2.6