Small cleanups to august (#119912)

pull/119929/head
J. Nick Koston 2024-06-18 15:43:16 -05:00 committed by GitHub
parent 8a38424c24
commit b8cafe7e5e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 21 additions and 51 deletions

View File

@ -210,8 +210,6 @@ class AugustDoorBinarySensor(AugustEntityMixin, BinarySensorEntity):
"""Initialize the sensor."""
super().__init__(data, device)
self.entity_description = description
self._data = data
self._device = device
self._attr_unique_id = f"{self._device_id}_{description.key}"
@callback
@ -273,22 +271,21 @@ class AugustDoorbellBinarySensor(AugustEntityMixin, BinarySensorEntity):
else:
self._attr_available = True
def _schedule_update_to_recheck_turn_off_sensor(self) -> None:
"""Schedule an update to recheck the sensor to see if it is ready to turn off."""
# If the sensor is already off there is nothing to do
if not self.is_on:
return
@callback
def _scheduled_update(now: datetime) -> None:
def _async_scheduled_update(self, now: datetime) -> None:
"""Timer callback for sensor update."""
self._check_for_off_update_listener = None
self._update_from_data()
if not self.is_on:
self.async_write_ha_state()
def _schedule_update_to_recheck_turn_off_sensor(self) -> None:
"""Schedule an update to recheck the sensor to see if it is ready to turn off."""
# If the sensor is already off there is nothing to do
if not self.is_on:
return
self._check_for_off_update_listener = async_call_later(
self.hass, TIME_TO_RECHECK_DETECTION.total_seconds(), _scheduled_update
self.hass, TIME_TO_RECHECK_DETECTION, self._async_scheduled_update
)
def _cancel_any_pending_updates(self) -> None:

View File

@ -43,6 +43,8 @@ class AugustCamera(AugustEntityMixin, Camera):
"""An implementation of an August security camera."""
_attr_translation_key = "camera"
_attr_motion_detection_enabled = True
_attr_brand = DEFAULT_NAME
def __init__(
self, data: AugustData, device: Doorbell, session: ClientSession, timeout: int
@ -55,8 +57,6 @@ class AugustCamera(AugustEntityMixin, Camera):
self._content_token = None
self._image_content = None
self._attr_unique_id = f"{self._device_id:s}_camera"
self._attr_motion_detection_enabled = True
self._attr_brand = DEFAULT_NAME
@property
def is_recording(self) -> bool:

View File

@ -40,11 +40,11 @@ class AugustLock(AugustEntityMixin, RestoreEntity, LockEntity):
"""Representation of an August lock."""
_attr_name = None
_lock_status: LockStatus | None = None
def __init__(self, data: AugustData, device: Lock) -> None:
"""Initialize the lock."""
super().__init__(data, device)
self._lock_status = None
self._attr_unique_id = f"{self._device_id:s}_lock"
if self._detail.unlatch_supported:
self._attr_supported_features = LockEntityFeature.OPEN
@ -136,14 +136,15 @@ class AugustLock(AugustEntityMixin, RestoreEntity, LockEntity):
update_lock_detail_from_activity(self._detail, bridge_activity)
self._update_lock_status_from_detail()
if self._lock_status is None or self._lock_status is LockStatus.UNKNOWN:
lock_status = self._lock_status
if lock_status is None or lock_status is LockStatus.UNKNOWN:
self._attr_is_locked = None
else:
self._attr_is_locked = self._lock_status is LockStatus.LOCKED
self._attr_is_locked = lock_status is LockStatus.LOCKED
self._attr_is_jammed = self._lock_status is LockStatus.JAMMED
self._attr_is_locking = self._lock_status is LockStatus.LOCKING
self._attr_is_unlocking = self._lock_status in (
self._attr_is_jammed = lock_status is LockStatus.JAMMED
self._attr_is_locking = lock_status is LockStatus.LOCKING
self._attr_is_unlocking = lock_status in (
LockStatus.UNLOCKING,
LockStatus.UNLATCHING,
)

View File

@ -26,7 +26,6 @@ from homeassistant.const import (
EntityCategory,
)
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import entity_registry as er
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import AugustConfigEntry, AugustData
@ -37,7 +36,6 @@ from .const import (
ATTR_OPERATION_METHOD,
ATTR_OPERATION_REMOTE,
ATTR_OPERATION_TAG,
DOMAIN,
OPERATION_METHOD_AUTORELOCK,
OPERATION_METHOD_KEYPAD,
OPERATION_METHOD_MANUAL,
@ -100,7 +98,6 @@ async def async_setup_entry(
"""Set up the August sensors."""
data = config_entry.runtime_data
entities: list[SensorEntity] = []
migrate_unique_id_devices = []
operation_sensors = []
batteries: dict[str, list[Doorbell | Lock]] = {
"device_battery": [],
@ -126,9 +123,7 @@ async def async_setup_entry(
device.device_name,
)
entities.append(
AugustBatterySensor[LockDetail](
data, device, device, SENSOR_TYPE_DEVICE_BATTERY
)
AugustBatterySensor[LockDetail](data, device, SENSOR_TYPE_DEVICE_BATTERY)
)
for device in batteries["linked_keypad_battery"]:
@ -145,34 +140,15 @@ async def async_setup_entry(
device.device_name,
)
keypad_battery_sensor = AugustBatterySensor[KeypadDetail](
data, detail.keypad, device, SENSOR_TYPE_KEYPAD_BATTERY
data, detail.keypad, SENSOR_TYPE_KEYPAD_BATTERY
)
entities.append(keypad_battery_sensor)
migrate_unique_id_devices.append(keypad_battery_sensor)
entities.extend(AugustOperatorSensor(data, device) for device in operation_sensors)
await _async_migrate_old_unique_ids(hass, migrate_unique_id_devices)
async_add_entities(entities)
async def _async_migrate_old_unique_ids(hass: HomeAssistant, devices) -> None:
"""Keypads now have their own serial number."""
registry = er.async_get(hass)
for device in devices:
old_entity_id = registry.async_get_entity_id(
"sensor", DOMAIN, device.old_unique_id
)
if old_entity_id is not None:
_LOGGER.debug(
"Migrating unique_id from [%s] to [%s]",
device.old_unique_id,
device.unique_id,
)
registry.async_update_entity(old_entity_id, new_unique_id=device.unique_id)
class AugustOperatorSensor(AugustEntityMixin, RestoreSensor):
"""Representation of an August lock operation sensor."""
@ -181,8 +157,6 @@ class AugustOperatorSensor(AugustEntityMixin, RestoreSensor):
def __init__(self, data: AugustData, device) -> None:
"""Initialize the sensor."""
super().__init__(data, device)
self._data = data
self._device = device
self._operated_remote: bool | None = None
self._operated_keypad: bool | None = None
self._operated_manual: bool | None = None
@ -279,15 +253,13 @@ class AugustBatterySensor(AugustEntityMixin, SensorEntity, Generic[_T]):
def __init__(
self,
data: AugustData,
device,
old_device,
device: Doorbell | Lock | KeypadDetail,
description: AugustSensorEntityDescription[_T],
) -> None:
"""Initialize the sensor."""
super().__init__(data, device)
self.entity_description = description
self._attr_unique_id = f"{self._device_id}_{description.key}"
self.old_unique_id = f"{old_device.device_id}_{description.key}"
self._update_from_data()
@callback