From 3c82c718cb37fca96002558019e3a0fba7ccde66 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Thu, 23 Jun 2022 16:34:40 +0200 Subject: [PATCH] Improve typing in fans and locks (#73901) --- homeassistant/components/august/lock.py | 2 +- homeassistant/components/demo/fan.py | 4 ++-- homeassistant/components/demo/lock.py | 2 +- homeassistant/components/kiwi/lock.py | 4 ++-- homeassistant/components/mqtt/fan.py | 2 +- homeassistant/components/mqtt/lock.py | 4 ++-- homeassistant/components/sesame/lock.py | 2 +- homeassistant/components/smartthings/lock.py | 2 +- homeassistant/components/starline/lock.py | 6 +++--- homeassistant/components/template/fan.py | 2 +- homeassistant/components/template/lock.py | 6 +++--- homeassistant/components/verisure/lock.py | 2 +- homeassistant/components/vesync/fan.py | 2 +- homeassistant/components/xiaomi_aqara/lock.py | 2 +- homeassistant/components/xiaomi_miio/fan.py | 2 +- homeassistant/components/zha/fan.py | 2 +- homeassistant/components/zha/lock.py | 5 +++-- homeassistant/components/zwave_js/fan.py | 2 +- 18 files changed, 27 insertions(+), 26 deletions(-) diff --git a/homeassistant/components/august/lock.py b/homeassistant/components/august/lock.py index 9269dc52c6a..d77a61a0659 100644 --- a/homeassistant/components/august/lock.py +++ b/homeassistant/components/august/lock.py @@ -127,7 +127,7 @@ class AugustLock(AugustEntityMixin, RestoreEntity, LockEntity): "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.""" await super().async_added_to_hass() diff --git a/homeassistant/components/demo/fan.py b/homeassistant/components/demo/fan.py index a36e7a35cff..02623b7b644 100644 --- a/homeassistant/components/demo/fan.py +++ b/homeassistant/components/demo/fan.py @@ -124,7 +124,7 @@ class BaseDemoFan(FanEntity): self._direction = "forward" @property - def unique_id(self): + def unique_id(self) -> str: """Return the unique id.""" return self._unique_id @@ -134,7 +134,7 @@ class BaseDemoFan(FanEntity): return self._name @property - def should_poll(self): + def should_poll(self) -> bool: """No polling needed for a demo fan.""" return False diff --git a/homeassistant/components/demo/lock.py b/homeassistant/components/demo/lock.py index c59dfad2fab..d21d89f238b 100644 --- a/homeassistant/components/demo/lock.py +++ b/homeassistant/components/demo/lock.py @@ -111,7 +111,7 @@ class DemoLock(LockEntity): self.async_write_ha_state() @property - def supported_features(self): + def supported_features(self) -> int: """Flag supported features.""" if self._openable: return LockEntityFeature.OPEN diff --git a/homeassistant/components/kiwi/lock.py b/homeassistant/components/kiwi/lock.py index bfd6b430c9f..44dc2bb2521 100644 --- a/homeassistant/components/kiwi/lock.py +++ b/homeassistant/components/kiwi/lock.py @@ -83,7 +83,7 @@ class KiwiLock(LockEntity): } @property - def name(self): + def name(self) -> str | None: """Return the name of the lock.""" name = self._sensor.get("name") specifier = self._sensor["address"].get("specifier") @@ -95,7 +95,7 @@ class KiwiLock(LockEntity): return self._state == STATE_LOCKED @property - def extra_state_attributes(self): + def extra_state_attributes(self) -> dict[str, Any]: """Return the device specific state attributes.""" return self._device_attrs diff --git a/homeassistant/components/mqtt/fan.py b/homeassistant/components/mqtt/fan.py index f1a1dbed657..721fa93f244 100644 --- a/homeassistant/components/mqtt/fan.py +++ b/homeassistant/components/mqtt/fan.py @@ -502,7 +502,7 @@ class MqttFan(MqttEntity, FanEntity): await subscription.async_subscribe_topics(self.hass, self._sub_state) @property - def assumed_state(self): + def assumed_state(self) -> bool: """Return true if we do optimistic updates.""" return self._optimistic diff --git a/homeassistant/components/mqtt/lock.py b/homeassistant/components/mqtt/lock.py index 8cf65485a09..1d6a40c2331 100644 --- a/homeassistant/components/mqtt/lock.py +++ b/homeassistant/components/mqtt/lock.py @@ -189,12 +189,12 @@ class MqttLock(MqttEntity, LockEntity): return self._state @property - def assumed_state(self): + def assumed_state(self) -> bool: """Return true if we do optimistic updates.""" return self._optimistic @property - def supported_features(self): + def supported_features(self) -> int: """Flag supported features.""" return LockEntityFeature.OPEN if CONF_PAYLOAD_OPEN in self._config else 0 diff --git a/homeassistant/components/sesame/lock.py b/homeassistant/components/sesame/lock.py index b9a230fed63..c539e7507eb 100644 --- a/homeassistant/components/sesame/lock.py +++ b/homeassistant/components/sesame/lock.py @@ -82,7 +82,7 @@ class SesameDevice(LockEntity): self._responsive = status["responsive"] @property - def extra_state_attributes(self) -> dict: + def extra_state_attributes(self) -> dict[str, Any]: """Return the state attributes.""" return { ATTR_DEVICE_ID: self._device_id, diff --git a/homeassistant/components/smartthings/lock.py b/homeassistant/components/smartthings/lock.py index 81866010667..c0fbc32fa19 100644 --- a/homeassistant/components/smartthings/lock.py +++ b/homeassistant/components/smartthings/lock.py @@ -67,7 +67,7 @@ class SmartThingsLock(SmartThingsEntity, LockEntity): return self._device.status.lock == ST_STATE_LOCKED @property - def extra_state_attributes(self): + def extra_state_attributes(self) -> dict[str, Any]: """Return device specific state attributes.""" state_attrs = {} status = self._device.status.attributes[Attribute.lock] diff --git a/homeassistant/components/starline/lock.py b/homeassistant/components/starline/lock.py index 3a5c45a2ed1..4fb8457a779 100644 --- a/homeassistant/components/starline/lock.py +++ b/homeassistant/components/starline/lock.py @@ -35,12 +35,12 @@ class StarlineLock(StarlineEntity, LockEntity): super().__init__(account, device, "lock", "Security") @property - def available(self): + def available(self) -> bool: """Return True if entity is available.""" return super().available and self._device.online @property - def extra_state_attributes(self): + def extra_state_attributes(self) -> dict[str, bool]: """Return the state attributes of the lock. Possible dictionary keys: @@ -61,7 +61,7 @@ class StarlineLock(StarlineEntity, LockEntity): return self._device.alarm_state @property - def icon(self): + def icon(self) -> str: """Icon to use in the frontend, if any.""" return ( "mdi:shield-check-outline" if self.is_locked else "mdi:shield-alert-outline" diff --git a/homeassistant/components/template/fan.py b/homeassistant/components/template/fan.py index 67cbeb07170..b60e7f53364 100644 --- a/homeassistant/components/template/fan.py +++ b/homeassistant/components/template/fan.py @@ -354,7 +354,7 @@ class TemplateFan(TemplateEntity, FanEntity): ) self._state = None - async def async_added_to_hass(self): + async def async_added_to_hass(self) -> None: """Register callbacks.""" self.add_template_attribute("_state", self._template, None, self._update_state) if self._preset_mode_template is not None: diff --git a/homeassistant/components/template/lock.py b/homeassistant/components/template/lock.py index 3f83e628f71..da8be80d8a4 100644 --- a/homeassistant/components/template/lock.py +++ b/homeassistant/components/template/lock.py @@ -92,9 +92,9 @@ class TemplateLock(TemplateEntity, LockEntity): self._optimistic = config.get(CONF_OPTIMISTIC) @property - def assumed_state(self): + def assumed_state(self) -> bool: """Return true if we do optimistic updates.""" - return self._optimistic + return bool(self._optimistic) @property def is_locked(self) -> bool: @@ -133,7 +133,7 @@ class TemplateLock(TemplateEntity, LockEntity): self._state = None - async def async_added_to_hass(self): + async def async_added_to_hass(self) -> None: """Register callbacks.""" self.add_template_attribute( "_state", self._state_template, None, self._update_state diff --git a/homeassistant/components/verisure/lock.py b/homeassistant/components/verisure/lock.py index f96b99e2a8c..8074cf28f32 100644 --- a/homeassistant/components/verisure/lock.py +++ b/homeassistant/components/verisure/lock.py @@ -119,7 +119,7 @@ class VerisureDoorlock(CoordinatorEntity[VerisureDataUpdateCoordinator], LockEnt ) @property - def extra_state_attributes(self): + def extra_state_attributes(self) -> dict[str, str]: """Return the state attributes.""" return {"method": self.changed_method} diff --git a/homeassistant/components/vesync/fan.py b/homeassistant/components/vesync/fan.py index 9932790fa96..f89224aaba8 100644 --- a/homeassistant/components/vesync/fan.py +++ b/homeassistant/components/vesync/fan.py @@ -130,7 +130,7 @@ class VeSyncFanHA(VeSyncDevice, FanEntity): return self.smartfan.uuid @property - def extra_state_attributes(self): + def extra_state_attributes(self) -> dict[str, Any]: """Return the state attributes of the fan.""" attr = {} diff --git a/homeassistant/components/xiaomi_aqara/lock.py b/homeassistant/components/xiaomi_aqara/lock.py index 1885c1aef85..fea729b2b47 100644 --- a/homeassistant/components/xiaomi_aqara/lock.py +++ b/homeassistant/components/xiaomi_aqara/lock.py @@ -58,7 +58,7 @@ class XiaomiAqaraLock(LockEntity, XiaomiDevice): return self._changed_by @property - def extra_state_attributes(self) -> dict: + def extra_state_attributes(self) -> dict[str, int]: """Return the state attributes.""" attributes = {ATTR_VERIFIED_WRONG_TIMES: self._verified_wrong_times} return attributes diff --git a/homeassistant/components/xiaomi_miio/fan.py b/homeassistant/components/xiaomi_miio/fan.py index b70ddc945ea..ac85955b347 100644 --- a/homeassistant/components/xiaomi_miio/fan.py +++ b/homeassistant/components/xiaomi_miio/fan.py @@ -304,7 +304,7 @@ class XiaomiGenericDevice(XiaomiCoordinatedMiioEntity, FanEntity): return None @property - def extra_state_attributes(self): + def extra_state_attributes(self) -> dict[str, Any]: """Return the state attributes of the device.""" return self._state_attrs diff --git a/homeassistant/components/zha/fan.py b/homeassistant/components/zha/fan.py index 1873c906a6f..3b9793c5137 100644 --- a/homeassistant/components/zha/fan.py +++ b/homeassistant/components/zha/fan.py @@ -134,7 +134,7 @@ class ZhaFan(BaseFan, ZhaEntity): super().__init__(unique_id, zha_device, channels, **kwargs) 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.""" await super().async_added_to_hass() self.async_accept_signal( diff --git a/homeassistant/components/zha/lock.py b/homeassistant/components/zha/lock.py index 449fd1089eb..6615141f4d1 100644 --- a/homeassistant/components/zha/lock.py +++ b/homeassistant/components/zha/lock.py @@ -11,6 +11,7 @@ from homeassistant.const import Platform from homeassistant.core import HomeAssistant, callback from homeassistant.helpers import config_validation as cv, entity_platform from homeassistant.helpers.dispatcher import async_dispatcher_connect +from homeassistant.helpers.typing import StateType from .core import discovery from .core.const import ( @@ -96,7 +97,7 @@ class ZhaDoorLock(ZhaEntity, LockEntity): super().__init__(unique_id, zha_device, channels, **kwargs) 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.""" await super().async_added_to_hass() self.async_accept_signal( @@ -116,7 +117,7 @@ class ZhaDoorLock(ZhaEntity, LockEntity): return self._state == STATE_LOCKED @property - def extra_state_attributes(self): + def extra_state_attributes(self) -> dict[str, StateType]: """Return state attributes.""" return self.state_attributes diff --git a/homeassistant/components/zwave_js/fan.py b/homeassistant/components/zwave_js/fan.py index ae9df47b420..27f73353ca8 100644 --- a/homeassistant/components/zwave_js/fan.py +++ b/homeassistant/components/zwave_js/fan.py @@ -404,7 +404,7 @@ class ZwaveThermostatFan(ZWaveBaseEntity, FanEntity): return cast(str, self._fan_state.metadata.states[str(value)]) @property - def extra_state_attributes(self) -> dict[str, str] | None: + def extra_state_attributes(self) -> dict[str, str]: """Return the optional state attributes.""" attrs = {}