2020-02-28 03:44:23 +00:00
|
|
|
"""Base class for August entity."""
|
|
|
|
from homeassistant.core import callback
|
2021-10-22 14:35:39 +00:00
|
|
|
from homeassistant.helpers.entity import DeviceInfo, Entity
|
2020-02-28 03:44:23 +00:00
|
|
|
|
2020-07-15 04:03:24 +00:00
|
|
|
from . import DOMAIN
|
|
|
|
from .const import MANUFACTURER
|
2020-02-28 03:44:23 +00:00
|
|
|
|
2021-03-15 05:42:49 +00:00
|
|
|
DEVICE_TYPES = ["keypad", "lock", "camera", "doorbell", "door", "bell"]
|
|
|
|
|
2020-02-28 03:44:23 +00:00
|
|
|
|
2020-02-29 11:12:50 +00:00
|
|
|
class AugustEntityMixin(Entity):
|
2020-02-28 03:44:23 +00:00
|
|
|
"""Base implementation for August device."""
|
|
|
|
|
2021-07-13 19:56:34 +00:00
|
|
|
_attr_should_poll = False
|
|
|
|
|
2020-02-28 03:44:23 +00:00
|
|
|
def __init__(self, data, device):
|
|
|
|
"""Initialize an August device."""
|
|
|
|
super().__init__()
|
|
|
|
self._data = data
|
|
|
|
self._device = device
|
2021-10-22 14:35:39 +00:00
|
|
|
self._attr_device_info = DeviceInfo(
|
|
|
|
identifiers={(DOMAIN, self._device_id)},
|
|
|
|
manufacturer=MANUFACTURER,
|
|
|
|
model=self._detail.model,
|
|
|
|
name=device.device_name,
|
|
|
|
sw_version=self._detail.firmware_version,
|
|
|
|
suggested_area=_remove_device_types(device.device_name, DEVICE_TYPES),
|
2021-11-20 03:55:51 +00:00
|
|
|
configuration_url="https://account.august.com",
|
2021-10-22 14:35:39 +00:00
|
|
|
)
|
2020-02-28 03:44:23 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def _device_id(self):
|
|
|
|
return self._device.device_id
|
|
|
|
|
|
|
|
@property
|
|
|
|
def _detail(self):
|
|
|
|
return self._data.get_device_detail(self._device.device_id)
|
|
|
|
|
2022-02-11 23:13:35 +00:00
|
|
|
@property
|
|
|
|
def _hyper_bridge(self):
|
|
|
|
"""Check if the lock has a paired hyper bridge."""
|
|
|
|
return bool(self._detail.bridge and self._detail.bridge.hyper_bridge)
|
|
|
|
|
2020-02-28 03:44:23 +00:00
|
|
|
@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."""
|
2020-10-25 12:27:51 +00:00
|
|
|
self.async_on_remove(
|
|
|
|
self._data.async_subscribe_device_id(
|
|
|
|
self._device_id, self._update_from_data_and_write_state
|
|
|
|
)
|
2020-02-28 03:44:23 +00:00
|
|
|
)
|
2020-10-25 12:27:51 +00:00
|
|
|
self.async_on_remove(
|
|
|
|
self._data.activity_stream.async_subscribe_device_id(
|
|
|
|
self._device_id, self._update_from_data_and_write_state
|
|
|
|
)
|
2020-02-28 03:44:23 +00:00
|
|
|
)
|
2021-03-15 05:42:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
def _remove_device_types(name, device_types):
|
|
|
|
"""Strip device types from a string.
|
|
|
|
|
|
|
|
August stores the name as Master Bed Lock
|
|
|
|
or Master Bed Door. We can come up with a
|
|
|
|
reasonable suggestion by removing the supported
|
|
|
|
device types from the string.
|
|
|
|
"""
|
|
|
|
lower_name = name.lower()
|
|
|
|
for device_type in device_types:
|
|
|
|
device_type_with_space = f" {device_type}"
|
|
|
|
if lower_name.endswith(device_type_with_space):
|
|
|
|
lower_name = lower_name[: -len(device_type_with_space)]
|
|
|
|
return name[: len(lower_name)]
|