Improve typing in fans and locks (#73901)
This commit is contained in:
parent
ff7d840a6c
commit
3c82c718cb
18 changed files with 27 additions and 26 deletions
|
@ -127,7 +127,7 @@ class AugustLock(AugustEntityMixin, RestoreEntity, LockEntity):
|
||||||
"keypad_battery_level"
|
"keypad_battery_level"
|
||||||
] = self._detail.keypad.battery_level
|
] = self._detail.keypad.battery_level
|
||||||
|
|
||||||
async def async_added_to_hass(self):
|
async def async_added_to_hass(self) -> None:
|
||||||
"""Restore ATTR_CHANGED_BY on startup since it is likely no longer in the activity log."""
|
"""Restore ATTR_CHANGED_BY on startup since it is likely no longer in the activity log."""
|
||||||
await super().async_added_to_hass()
|
await super().async_added_to_hass()
|
||||||
|
|
||||||
|
|
|
@ -124,7 +124,7 @@ class BaseDemoFan(FanEntity):
|
||||||
self._direction = "forward"
|
self._direction = "forward"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unique_id(self):
|
def unique_id(self) -> str:
|
||||||
"""Return the unique id."""
|
"""Return the unique id."""
|
||||||
return self._unique_id
|
return self._unique_id
|
||||||
|
|
||||||
|
@ -134,7 +134,7 @@ class BaseDemoFan(FanEntity):
|
||||||
return self._name
|
return self._name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def should_poll(self):
|
def should_poll(self) -> bool:
|
||||||
"""No polling needed for a demo fan."""
|
"""No polling needed for a demo fan."""
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
|
@ -111,7 +111,7 @@ class DemoLock(LockEntity):
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def supported_features(self):
|
def supported_features(self) -> int:
|
||||||
"""Flag supported features."""
|
"""Flag supported features."""
|
||||||
if self._openable:
|
if self._openable:
|
||||||
return LockEntityFeature.OPEN
|
return LockEntityFeature.OPEN
|
||||||
|
|
|
@ -83,7 +83,7 @@ class KiwiLock(LockEntity):
|
||||||
}
|
}
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self) -> str | None:
|
||||||
"""Return the name of the lock."""
|
"""Return the name of the lock."""
|
||||||
name = self._sensor.get("name")
|
name = self._sensor.get("name")
|
||||||
specifier = self._sensor["address"].get("specifier")
|
specifier = self._sensor["address"].get("specifier")
|
||||||
|
@ -95,7 +95,7 @@ class KiwiLock(LockEntity):
|
||||||
return self._state == STATE_LOCKED
|
return self._state == STATE_LOCKED
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def extra_state_attributes(self):
|
def extra_state_attributes(self) -> dict[str, Any]:
|
||||||
"""Return the device specific state attributes."""
|
"""Return the device specific state attributes."""
|
||||||
return self._device_attrs
|
return self._device_attrs
|
||||||
|
|
||||||
|
|
|
@ -502,7 +502,7 @@ class MqttFan(MqttEntity, FanEntity):
|
||||||
await subscription.async_subscribe_topics(self.hass, self._sub_state)
|
await subscription.async_subscribe_topics(self.hass, self._sub_state)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def assumed_state(self):
|
def assumed_state(self) -> bool:
|
||||||
"""Return true if we do optimistic updates."""
|
"""Return true if we do optimistic updates."""
|
||||||
return self._optimistic
|
return self._optimistic
|
||||||
|
|
||||||
|
|
|
@ -189,12 +189,12 @@ class MqttLock(MqttEntity, LockEntity):
|
||||||
return self._state
|
return self._state
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def assumed_state(self):
|
def assumed_state(self) -> bool:
|
||||||
"""Return true if we do optimistic updates."""
|
"""Return true if we do optimistic updates."""
|
||||||
return self._optimistic
|
return self._optimistic
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def supported_features(self):
|
def supported_features(self) -> int:
|
||||||
"""Flag supported features."""
|
"""Flag supported features."""
|
||||||
return LockEntityFeature.OPEN if CONF_PAYLOAD_OPEN in self._config else 0
|
return LockEntityFeature.OPEN if CONF_PAYLOAD_OPEN in self._config else 0
|
||||||
|
|
||||||
|
|
|
@ -82,7 +82,7 @@ class SesameDevice(LockEntity):
|
||||||
self._responsive = status["responsive"]
|
self._responsive = status["responsive"]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def extra_state_attributes(self) -> dict:
|
def extra_state_attributes(self) -> dict[str, Any]:
|
||||||
"""Return the state attributes."""
|
"""Return the state attributes."""
|
||||||
return {
|
return {
|
||||||
ATTR_DEVICE_ID: self._device_id,
|
ATTR_DEVICE_ID: self._device_id,
|
||||||
|
|
|
@ -67,7 +67,7 @@ class SmartThingsLock(SmartThingsEntity, LockEntity):
|
||||||
return self._device.status.lock == ST_STATE_LOCKED
|
return self._device.status.lock == ST_STATE_LOCKED
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def extra_state_attributes(self):
|
def extra_state_attributes(self) -> dict[str, Any]:
|
||||||
"""Return device specific state attributes."""
|
"""Return device specific state attributes."""
|
||||||
state_attrs = {}
|
state_attrs = {}
|
||||||
status = self._device.status.attributes[Attribute.lock]
|
status = self._device.status.attributes[Attribute.lock]
|
||||||
|
|
|
@ -35,12 +35,12 @@ class StarlineLock(StarlineEntity, LockEntity):
|
||||||
super().__init__(account, device, "lock", "Security")
|
super().__init__(account, device, "lock", "Security")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def available(self):
|
def available(self) -> bool:
|
||||||
"""Return True if entity is available."""
|
"""Return True if entity is available."""
|
||||||
return super().available and self._device.online
|
return super().available and self._device.online
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def extra_state_attributes(self):
|
def extra_state_attributes(self) -> dict[str, bool]:
|
||||||
"""Return the state attributes of the lock.
|
"""Return the state attributes of the lock.
|
||||||
|
|
||||||
Possible dictionary keys:
|
Possible dictionary keys:
|
||||||
|
@ -61,7 +61,7 @@ class StarlineLock(StarlineEntity, LockEntity):
|
||||||
return self._device.alarm_state
|
return self._device.alarm_state
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def icon(self):
|
def icon(self) -> str:
|
||||||
"""Icon to use in the frontend, if any."""
|
"""Icon to use in the frontend, if any."""
|
||||||
return (
|
return (
|
||||||
"mdi:shield-check-outline" if self.is_locked else "mdi:shield-alert-outline"
|
"mdi:shield-check-outline" if self.is_locked else "mdi:shield-alert-outline"
|
||||||
|
|
|
@ -354,7 +354,7 @@ class TemplateFan(TemplateEntity, FanEntity):
|
||||||
)
|
)
|
||||||
self._state = None
|
self._state = None
|
||||||
|
|
||||||
async def async_added_to_hass(self):
|
async def async_added_to_hass(self) -> None:
|
||||||
"""Register callbacks."""
|
"""Register callbacks."""
|
||||||
self.add_template_attribute("_state", self._template, None, self._update_state)
|
self.add_template_attribute("_state", self._template, None, self._update_state)
|
||||||
if self._preset_mode_template is not None:
|
if self._preset_mode_template is not None:
|
||||||
|
|
|
@ -92,9 +92,9 @@ class TemplateLock(TemplateEntity, LockEntity):
|
||||||
self._optimistic = config.get(CONF_OPTIMISTIC)
|
self._optimistic = config.get(CONF_OPTIMISTIC)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def assumed_state(self):
|
def assumed_state(self) -> bool:
|
||||||
"""Return true if we do optimistic updates."""
|
"""Return true if we do optimistic updates."""
|
||||||
return self._optimistic
|
return bool(self._optimistic)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_locked(self) -> bool:
|
def is_locked(self) -> bool:
|
||||||
|
@ -133,7 +133,7 @@ class TemplateLock(TemplateEntity, LockEntity):
|
||||||
|
|
||||||
self._state = None
|
self._state = None
|
||||||
|
|
||||||
async def async_added_to_hass(self):
|
async def async_added_to_hass(self) -> None:
|
||||||
"""Register callbacks."""
|
"""Register callbacks."""
|
||||||
self.add_template_attribute(
|
self.add_template_attribute(
|
||||||
"_state", self._state_template, None, self._update_state
|
"_state", self._state_template, None, self._update_state
|
||||||
|
|
|
@ -119,7 +119,7 @@ class VerisureDoorlock(CoordinatorEntity[VerisureDataUpdateCoordinator], LockEnt
|
||||||
)
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def extra_state_attributes(self):
|
def extra_state_attributes(self) -> dict[str, str]:
|
||||||
"""Return the state attributes."""
|
"""Return the state attributes."""
|
||||||
return {"method": self.changed_method}
|
return {"method": self.changed_method}
|
||||||
|
|
||||||
|
|
|
@ -130,7 +130,7 @@ class VeSyncFanHA(VeSyncDevice, FanEntity):
|
||||||
return self.smartfan.uuid
|
return self.smartfan.uuid
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def extra_state_attributes(self):
|
def extra_state_attributes(self) -> dict[str, Any]:
|
||||||
"""Return the state attributes of the fan."""
|
"""Return the state attributes of the fan."""
|
||||||
attr = {}
|
attr = {}
|
||||||
|
|
||||||
|
|
|
@ -58,7 +58,7 @@ class XiaomiAqaraLock(LockEntity, XiaomiDevice):
|
||||||
return self._changed_by
|
return self._changed_by
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def extra_state_attributes(self) -> dict:
|
def extra_state_attributes(self) -> dict[str, int]:
|
||||||
"""Return the state attributes."""
|
"""Return the state attributes."""
|
||||||
attributes = {ATTR_VERIFIED_WRONG_TIMES: self._verified_wrong_times}
|
attributes = {ATTR_VERIFIED_WRONG_TIMES: self._verified_wrong_times}
|
||||||
return attributes
|
return attributes
|
||||||
|
|
|
@ -304,7 +304,7 @@ class XiaomiGenericDevice(XiaomiCoordinatedMiioEntity, FanEntity):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def extra_state_attributes(self):
|
def extra_state_attributes(self) -> dict[str, Any]:
|
||||||
"""Return the state attributes of the device."""
|
"""Return the state attributes of the device."""
|
||||||
return self._state_attrs
|
return self._state_attrs
|
||||||
|
|
||||||
|
|
|
@ -134,7 +134,7 @@ class ZhaFan(BaseFan, ZhaEntity):
|
||||||
super().__init__(unique_id, zha_device, channels, **kwargs)
|
super().__init__(unique_id, zha_device, channels, **kwargs)
|
||||||
self._fan_channel = self.cluster_channels.get(CHANNEL_FAN)
|
self._fan_channel = self.cluster_channels.get(CHANNEL_FAN)
|
||||||
|
|
||||||
async def async_added_to_hass(self):
|
async def async_added_to_hass(self) -> None:
|
||||||
"""Run when about to be added to hass."""
|
"""Run when about to be added to hass."""
|
||||||
await super().async_added_to_hass()
|
await super().async_added_to_hass()
|
||||||
self.async_accept_signal(
|
self.async_accept_signal(
|
||||||
|
|
|
@ -11,6 +11,7 @@ from homeassistant.const import Platform
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers import config_validation as cv, entity_platform
|
from homeassistant.helpers import config_validation as cv, entity_platform
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||||
|
from homeassistant.helpers.typing import StateType
|
||||||
|
|
||||||
from .core import discovery
|
from .core import discovery
|
||||||
from .core.const import (
|
from .core.const import (
|
||||||
|
@ -96,7 +97,7 @@ class ZhaDoorLock(ZhaEntity, LockEntity):
|
||||||
super().__init__(unique_id, zha_device, channels, **kwargs)
|
super().__init__(unique_id, zha_device, channels, **kwargs)
|
||||||
self._doorlock_channel = self.cluster_channels.get(CHANNEL_DOORLOCK)
|
self._doorlock_channel = self.cluster_channels.get(CHANNEL_DOORLOCK)
|
||||||
|
|
||||||
async def async_added_to_hass(self):
|
async def async_added_to_hass(self) -> None:
|
||||||
"""Run when about to be added to hass."""
|
"""Run when about to be added to hass."""
|
||||||
await super().async_added_to_hass()
|
await super().async_added_to_hass()
|
||||||
self.async_accept_signal(
|
self.async_accept_signal(
|
||||||
|
@ -116,7 +117,7 @@ class ZhaDoorLock(ZhaEntity, LockEntity):
|
||||||
return self._state == STATE_LOCKED
|
return self._state == STATE_LOCKED
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def extra_state_attributes(self):
|
def extra_state_attributes(self) -> dict[str, StateType]:
|
||||||
"""Return state attributes."""
|
"""Return state attributes."""
|
||||||
return self.state_attributes
|
return self.state_attributes
|
||||||
|
|
||||||
|
|
|
@ -404,7 +404,7 @@ class ZwaveThermostatFan(ZWaveBaseEntity, FanEntity):
|
||||||
return cast(str, self._fan_state.metadata.states[str(value)])
|
return cast(str, self._fan_state.metadata.states[str(value)])
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def extra_state_attributes(self) -> dict[str, str] | None:
|
def extra_state_attributes(self) -> dict[str, str]:
|
||||||
"""Return the optional state attributes."""
|
"""Return the optional state attributes."""
|
||||||
attrs = {}
|
attrs = {}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue