Conversation
| """Close connection when hass stops.""" | ||
| hass.async_add_job(factory.shutdown()) | ||
|
|
||
| self.hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, on_hass_stop) |
There was a problem hiding this comment.
undefined name 'self'
undefined name 'EVENT_HOMEASSISTANT_STOP'
| """Close connection when hass stops.""" | ||
| hass.async_add_job(factory.shutdown()) | ||
|
|
||
| self.hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, on_hass_stop) |
There was a problem hiding this comment.
undefined name 'self'
undefined name 'EVENT_HOMEASSISTANT_STOP'
|
|
||
| def on_hass_stop(event): | ||
| """Close connection when hass stops.""" | ||
| hass.async_add_job(factory.shutdown()) |
There was a problem hiding this comment.
We don't use this function anymore. If it a coro use async_create_task. You need also decorate that as callback.
There was a problem hiding this comment.
@pvizeli hmm ok, I lifted the example from elsewhere in the code after searching for async_listen_once(EVENT_HOMEASSISTANT_STOP.
| """Close connection when hass stops.""" | ||
| hass.async_add_job(factory.shutdown()) | ||
|
|
||
| hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, on_hass_stop) |
There was a problem hiding this comment.
Is this shutting down the same observation as the one created when the config entry is created? If not, why do we need to wait until home assistant stops? If it is the same, we should only need to shut it down once, right?
There was a problem hiding this comment.
It's any observations that pytradfri holds that have been created since loading, if there's a disconnect and reconnect, that'll be a new observation. It's a global shutdown for any connections pytradfri is holding.
There was a problem hiding this comment.
So then we only need one event listener?
There was a problem hiding this comment.
Sorry should have worded that better - any factory instances hold observations, I put this next to factory creation to ensure each factory is shutdown.
Looking at the code below this, you're right - we only need to call it once as the api isn't used after. I'll change later.
Description:
Shutdown tradfri on HA shutdown to avoid event loop errors on open observations.
Library syntax bump to 3.5.
Handle aiocoap OSErrors errors upstream.
Related issue (if applicable): fixes #???
Example entry for
configuration.yaml(if applicable):discover: