mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 06:07:17 +00:00
Small cleanups to august (#119912)
This commit is contained in:
parent
8a38424c24
commit
b8cafe7e5e
@ -210,8 +210,6 @@ class AugustDoorBinarySensor(AugustEntityMixin, BinarySensorEntity):
|
|||||||
"""Initialize the sensor."""
|
"""Initialize the sensor."""
|
||||||
super().__init__(data, device)
|
super().__init__(data, device)
|
||||||
self.entity_description = description
|
self.entity_description = description
|
||||||
self._data = data
|
|
||||||
self._device = device
|
|
||||||
self._attr_unique_id = f"{self._device_id}_{description.key}"
|
self._attr_unique_id = f"{self._device_id}_{description.key}"
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
@ -273,22 +271,21 @@ class AugustDoorbellBinarySensor(AugustEntityMixin, BinarySensorEntity):
|
|||||||
else:
|
else:
|
||||||
self._attr_available = True
|
self._attr_available = True
|
||||||
|
|
||||||
|
@callback
|
||||||
|
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:
|
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."""
|
"""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 the sensor is already off there is nothing to do
|
||||||
if not self.is_on:
|
if not self.is_on:
|
||||||
return
|
return
|
||||||
|
|
||||||
@callback
|
|
||||||
def _scheduled_update(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()
|
|
||||||
|
|
||||||
self._check_for_off_update_listener = async_call_later(
|
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:
|
def _cancel_any_pending_updates(self) -> None:
|
||||||
|
@ -43,6 +43,8 @@ class AugustCamera(AugustEntityMixin, Camera):
|
|||||||
"""An implementation of an August security camera."""
|
"""An implementation of an August security camera."""
|
||||||
|
|
||||||
_attr_translation_key = "camera"
|
_attr_translation_key = "camera"
|
||||||
|
_attr_motion_detection_enabled = True
|
||||||
|
_attr_brand = DEFAULT_NAME
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, data: AugustData, device: Doorbell, session: ClientSession, timeout: int
|
self, data: AugustData, device: Doorbell, session: ClientSession, timeout: int
|
||||||
@ -55,8 +57,6 @@ class AugustCamera(AugustEntityMixin, Camera):
|
|||||||
self._content_token = None
|
self._content_token = None
|
||||||
self._image_content = None
|
self._image_content = None
|
||||||
self._attr_unique_id = f"{self._device_id:s}_camera"
|
self._attr_unique_id = f"{self._device_id:s}_camera"
|
||||||
self._attr_motion_detection_enabled = True
|
|
||||||
self._attr_brand = DEFAULT_NAME
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_recording(self) -> bool:
|
def is_recording(self) -> bool:
|
||||||
|
@ -40,11 +40,11 @@ class AugustLock(AugustEntityMixin, RestoreEntity, LockEntity):
|
|||||||
"""Representation of an August lock."""
|
"""Representation of an August lock."""
|
||||||
|
|
||||||
_attr_name = None
|
_attr_name = None
|
||||||
|
_lock_status: LockStatus | None = None
|
||||||
|
|
||||||
def __init__(self, data: AugustData, device: Lock) -> None:
|
def __init__(self, data: AugustData, device: Lock) -> None:
|
||||||
"""Initialize the lock."""
|
"""Initialize the lock."""
|
||||||
super().__init__(data, device)
|
super().__init__(data, device)
|
||||||
self._lock_status = None
|
|
||||||
self._attr_unique_id = f"{self._device_id:s}_lock"
|
self._attr_unique_id = f"{self._device_id:s}_lock"
|
||||||
if self._detail.unlatch_supported:
|
if self._detail.unlatch_supported:
|
||||||
self._attr_supported_features = LockEntityFeature.OPEN
|
self._attr_supported_features = LockEntityFeature.OPEN
|
||||||
@ -136,14 +136,15 @@ class AugustLock(AugustEntityMixin, RestoreEntity, LockEntity):
|
|||||||
update_lock_detail_from_activity(self._detail, bridge_activity)
|
update_lock_detail_from_activity(self._detail, bridge_activity)
|
||||||
|
|
||||||
self._update_lock_status_from_detail()
|
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
|
self._attr_is_locked = None
|
||||||
else:
|
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_jammed = lock_status is LockStatus.JAMMED
|
||||||
self._attr_is_locking = self._lock_status is LockStatus.LOCKING
|
self._attr_is_locking = lock_status is LockStatus.LOCKING
|
||||||
self._attr_is_unlocking = self._lock_status in (
|
self._attr_is_unlocking = lock_status in (
|
||||||
LockStatus.UNLOCKING,
|
LockStatus.UNLOCKING,
|
||||||
LockStatus.UNLATCHING,
|
LockStatus.UNLATCHING,
|
||||||
)
|
)
|
||||||
|
@ -26,7 +26,6 @@ from homeassistant.const import (
|
|||||||
EntityCategory,
|
EntityCategory,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers import entity_registry as er
|
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import AugustConfigEntry, AugustData
|
from . import AugustConfigEntry, AugustData
|
||||||
@ -37,7 +36,6 @@ from .const import (
|
|||||||
ATTR_OPERATION_METHOD,
|
ATTR_OPERATION_METHOD,
|
||||||
ATTR_OPERATION_REMOTE,
|
ATTR_OPERATION_REMOTE,
|
||||||
ATTR_OPERATION_TAG,
|
ATTR_OPERATION_TAG,
|
||||||
DOMAIN,
|
|
||||||
OPERATION_METHOD_AUTORELOCK,
|
OPERATION_METHOD_AUTORELOCK,
|
||||||
OPERATION_METHOD_KEYPAD,
|
OPERATION_METHOD_KEYPAD,
|
||||||
OPERATION_METHOD_MANUAL,
|
OPERATION_METHOD_MANUAL,
|
||||||
@ -100,7 +98,6 @@ async def async_setup_entry(
|
|||||||
"""Set up the August sensors."""
|
"""Set up the August sensors."""
|
||||||
data = config_entry.runtime_data
|
data = config_entry.runtime_data
|
||||||
entities: list[SensorEntity] = []
|
entities: list[SensorEntity] = []
|
||||||
migrate_unique_id_devices = []
|
|
||||||
operation_sensors = []
|
operation_sensors = []
|
||||||
batteries: dict[str, list[Doorbell | Lock]] = {
|
batteries: dict[str, list[Doorbell | Lock]] = {
|
||||||
"device_battery": [],
|
"device_battery": [],
|
||||||
@ -126,9 +123,7 @@ async def async_setup_entry(
|
|||||||
device.device_name,
|
device.device_name,
|
||||||
)
|
)
|
||||||
entities.append(
|
entities.append(
|
||||||
AugustBatterySensor[LockDetail](
|
AugustBatterySensor[LockDetail](data, device, SENSOR_TYPE_DEVICE_BATTERY)
|
||||||
data, device, device, SENSOR_TYPE_DEVICE_BATTERY
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
for device in batteries["linked_keypad_battery"]:
|
for device in batteries["linked_keypad_battery"]:
|
||||||
@ -145,34 +140,15 @@ async def async_setup_entry(
|
|||||||
device.device_name,
|
device.device_name,
|
||||||
)
|
)
|
||||||
keypad_battery_sensor = AugustBatterySensor[KeypadDetail](
|
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)
|
entities.append(keypad_battery_sensor)
|
||||||
migrate_unique_id_devices.append(keypad_battery_sensor)
|
|
||||||
|
|
||||||
entities.extend(AugustOperatorSensor(data, device) for device in operation_sensors)
|
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_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):
|
class AugustOperatorSensor(AugustEntityMixin, RestoreSensor):
|
||||||
"""Representation of an August lock operation sensor."""
|
"""Representation of an August lock operation sensor."""
|
||||||
|
|
||||||
@ -181,8 +157,6 @@ class AugustOperatorSensor(AugustEntityMixin, RestoreSensor):
|
|||||||
def __init__(self, data: AugustData, device) -> None:
|
def __init__(self, data: AugustData, device) -> None:
|
||||||
"""Initialize the sensor."""
|
"""Initialize the sensor."""
|
||||||
super().__init__(data, device)
|
super().__init__(data, device)
|
||||||
self._data = data
|
|
||||||
self._device = device
|
|
||||||
self._operated_remote: bool | None = None
|
self._operated_remote: bool | None = None
|
||||||
self._operated_keypad: bool | None = None
|
self._operated_keypad: bool | None = None
|
||||||
self._operated_manual: bool | None = None
|
self._operated_manual: bool | None = None
|
||||||
@ -279,15 +253,13 @@ class AugustBatterySensor(AugustEntityMixin, SensorEntity, Generic[_T]):
|
|||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
data: AugustData,
|
data: AugustData,
|
||||||
device,
|
device: Doorbell | Lock | KeypadDetail,
|
||||||
old_device,
|
|
||||||
description: AugustSensorEntityDescription[_T],
|
description: AugustSensorEntityDescription[_T],
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize the sensor."""
|
"""Initialize the sensor."""
|
||||||
super().__init__(data, device)
|
super().__init__(data, device)
|
||||||
self.entity_description = description
|
self.entity_description = description
|
||||||
self._attr_unique_id = f"{self._device_id}_{description.key}"
|
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()
|
self._update_from_data()
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
|
Loading…
x
Reference in New Issue
Block a user