Refactor homekit_controller entity update to work more like update coordinator (#32670)
* Clean up use of get_characteristic_types * Get rid of get_hk_char_value helper * Get rid of _update_fn callbacks * Call async_write_has_state directly as async_state_changed doesnt do anything any more
This commit is contained in:
parent
4248893007
commit
647d137daa
12 changed files with 159 additions and 358 deletions
|
@ -37,12 +37,6 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||
class HomeKitLock(HomeKitEntity, LockDevice):
|
||||
"""Representation of a HomeKit Controller Lock."""
|
||||
|
||||
def __init__(self, accessory, discovery_info):
|
||||
"""Initialise the Lock."""
|
||||
super().__init__(accessory, discovery_info)
|
||||
self._state = None
|
||||
self._battery_level = None
|
||||
|
||||
def get_characteristic_types(self):
|
||||
"""Define the homekit characteristics the entity cares about."""
|
||||
return [
|
||||
|
@ -51,16 +45,11 @@ class HomeKitLock(HomeKitEntity, LockDevice):
|
|||
CharacteristicsTypes.BATTERY_LEVEL,
|
||||
]
|
||||
|
||||
def _update_lock_mechanism_current_state(self, value):
|
||||
self._state = CURRENT_STATE_MAP[value]
|
||||
|
||||
def _update_battery_level(self, value):
|
||||
self._battery_level = value
|
||||
|
||||
@property
|
||||
def is_locked(self):
|
||||
"""Return true if device is locked."""
|
||||
return self._state == STATE_LOCKED
|
||||
value = self.service.value(CharacteristicsTypes.LOCK_MECHANISM_CURRENT_STATE)
|
||||
return CURRENT_STATE_MAP[value] == STATE_LOCKED
|
||||
|
||||
async def async_lock(self, **kwargs):
|
||||
"""Lock the device."""
|
||||
|
@ -84,7 +73,10 @@ class HomeKitLock(HomeKitEntity, LockDevice):
|
|||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return the optional state attributes."""
|
||||
if self._battery_level is None:
|
||||
return None
|
||||
attributes = {}
|
||||
|
||||
return {ATTR_BATTERY_LEVEL: self._battery_level}
|
||||
battery_level = self.service.value(CharacteristicsTypes.BATTERY_LEVEL)
|
||||
if battery_level:
|
||||
attributes[ATTR_BATTERY_LEVEL] = battery_level
|
||||
|
||||
return attributes
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue