Improve typing in fans and locks (#73901)

This commit is contained in:
epenet 2022-06-23 16:34:40 +02:00 committed by GitHub
parent ff7d840a6c
commit 3c82c718cb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 27 additions and 26 deletions

View file

@ -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()

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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,

View file

@ -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]

View file

@ -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"

View file

@ -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:

View file

@ -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

View file

@ -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}

View file

@ -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 = {}

View file

@ -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

View file

@ -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

View file

@ -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(

View file

@ -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

View file

@ -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 = {}