bazwilliams / openhomedevice

Python library to access services on Linn Ds and other Openhome devices
MIT License
7 stars 3 forks source link

Feature request: Device.IsOnline() #18

Closed jooste closed 3 years ago

jooste commented 4 years ago

Hi Barry,

I have the following problem in HomeAssistant: I turn off my DSM when I don't use it to conserve power. However, home assistant keeps polling its status, causing a frequently repeating exception in Device.IsInStandby(), flooding the home assistant log with megabytes of tracebacks if the device is off for more than a couple of hours.

My suggestion would be to add a method, e.g., Device.IsOnline(), that can check whether the device is responding at all, before other updates are performed, thus avoiding all the tracebacks in the logs. Would this approach make sense?

Thanks! Joost

bazwilliams commented 4 years ago

Hi @jooste

I've heard a few reports like this and have experienced the issue myself. I suspect the best way would be for each request to the device to throw an exception which HomeAssistant integration can handle in an appropriate way; this would at least stop the verbose error logging.

Going further, when this exception is caught the integration could deregister the device as 'gone away' until it is rediscovered by upnp on wakeup. This also makes me wonder if the HomeAssistant integration is missing a hook for when the device goes offline as it does send an ssdp:byebye signal on shutdown. Hooking into this would also stop HomeAssistant making requests that will never be fulfilled.

I probably also should consider using upnp subscriptions to update HA - I wrote a javascript library to do that years ago and never wrote it in python.

Thanks for the issue - it has prompted me to look into it.

Incidentally, I save power on my power amp by using an HA controlled power switch. An automation watches for the DSM to go into a 'playing' state on some enabled sources and that triggers the power amp to be turned on. Though doing a full power off would be prefered - and I've a spare zigbee controlled socket :)

jooste commented 4 years ago

Thanks for the quick reply! The ssdp:byebye, does it even still send that when you switch the DSM off with its power switch? Or only when you go into standby? I've found that the standby consumption of Linn devices is quite high, high enough for me to just switch them off at night :)

bazwilliams commented 4 years ago

For Linn devices, the device stores enough current to send the ssdp:byebye when it detects the power has gone. Though something else will need to be done in addition to ssdp:byebye as it won't work if the network cable is removed or router restarted.

The 'standby' mode of Linn devices does very little as it still keeps the processor and network circuitry awake so it can still communicate with their apps; it essentially turns the screen off. I think legally they have to call it 'sleep' mode now as it doesn't fit criteria for 'standby' power consumption.

bazwilliams commented 3 years ago

I've tweaked the integration within Home Assistant to capture exceptions and use that to indicate availability which should stop your logs being filled with exceptions. This should provide a stop gap until this library subscribes directly to the devices.

On the plus side it uses https://github.com/StevenLooman/async_upnp_client which is really nice and supports subscriptions 😄

https://github.com/home-assistant/core/pull/48283