Coordinate all august detail and activity updates (#32249)
* Removing polling from august * Now using subscribers to the detail and activity * Fix hash to list keys * continue to the next house if one fails * Add async_signal_device_id_update * Fix double initial update * Handle self.hass not being available until after async_added_to_hass * Remove not needed await * Fix regression with device name
This commit is contained in:
parent
fefbe02d44
commit
223c01d842
12 changed files with 385 additions and 460 deletions
67
homeassistant/components/august/entity.py
Normal file
67
homeassistant/components/august/entity.py
Normal file
|
@ -0,0 +1,67 @@
|
|||
"""Base class for August entity."""
|
||||
|
||||
import logging
|
||||
|
||||
from homeassistant.core import callback
|
||||
|
||||
from . import DEFAULT_NAME, DOMAIN
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class AugustEntityMixin:
|
||||
"""Base implementation for August device."""
|
||||
|
||||
def __init__(self, data, device):
|
||||
"""Initialize an August device."""
|
||||
super().__init__()
|
||||
self._data = data
|
||||
self._device = device
|
||||
self._undo_dispatch_subscription = None
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
"""Return False, updates are controlled via the hub."""
|
||||
return False
|
||||
|
||||
@property
|
||||
def _device_id(self):
|
||||
return self._device.device_id
|
||||
|
||||
@property
|
||||
def _detail(self):
|
||||
return self._data.get_device_detail(self._device.device_id)
|
||||
|
||||
@property
|
||||
def device_info(self):
|
||||
"""Return the device_info of the device."""
|
||||
return {
|
||||
"identifiers": {(DOMAIN, self._device_id)},
|
||||
"name": self._device.device_name,
|
||||
"manufacturer": DEFAULT_NAME,
|
||||
"sw_version": self._detail.firmware_version,
|
||||
"model": self._detail.model,
|
||||
}
|
||||
|
||||
@callback
|
||||
def _update_from_data_and_write_state(self):
|
||||
self._update_from_data()
|
||||
self.async_write_ha_state()
|
||||
|
||||
async def async_added_to_hass(self):
|
||||
"""Subscribe to updates."""
|
||||
self._data.async_subscribe_device_id(
|
||||
self._device_id, self._update_from_data_and_write_state
|
||||
)
|
||||
self._data.activity_stream.async_subscribe_device_id(
|
||||
self._device_id, self._update_from_data_and_write_state
|
||||
)
|
||||
|
||||
async def async_will_remove_from_hass(self):
|
||||
"""Undo subscription."""
|
||||
self._data.async_unsubscribe_device_id(
|
||||
self._device_id, self._update_from_data_and_write_state
|
||||
)
|
||||
self._data.activity_stream.async_unsubscribe_device_id(
|
||||
self._device_id, self._update_from_data_and_write_state
|
||||
)
|
Loading…
Add table
Add a link
Reference in a new issue