Improve entity type hints [z] (#77890)

This commit is contained in:
epenet 2022-09-06 14:01:09 +02:00 committed by GitHub
parent 23052dc7b5
commit 3a0eae3986
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 42 additions and 37 deletions

View File

@ -117,7 +117,7 @@ class ZabbixTriggerCountSensor(SensorEntity):
output="extend", only_true=1, monitored=1, filter={"value": 1} output="extend", only_true=1, monitored=1, filter={"value": 1}
) )
def update(self): def update(self) -> None:
"""Update the sensor.""" """Update the sensor."""
_LOGGER.debug("Updating ZabbixTriggerCountSensor: %s", str(self._name)) _LOGGER.debug("Updating ZabbixTriggerCountSensor: %s", str(self._name))
triggers = self._call_zabbix_api() triggers = self._call_zabbix_api()

View File

@ -264,7 +264,7 @@ class ZamgSensor(SensorEntity):
ATTR_UPDATED: self.probe.last_update.isoformat(), ATTR_UPDATED: self.probe.last_update.isoformat(),
} }
def update(self): def update(self) -> None:
"""Delegate update to probe.""" """Delegate update to probe."""
self.probe.update() self.probe.update()

View File

@ -139,6 +139,6 @@ class ZamgWeather(WeatherEntity):
"""Return the wind bearing.""" """Return the wind bearing."""
return self.zamg_data.get_data(ATTR_WEATHER_WIND_BEARING) return self.zamg_data.get_data(ATTR_WEATHER_WIND_BEARING)
def update(self): def update(self) -> None:
"""Update current conditions.""" """Update current conditions."""
self.zamg_data.update() self.zamg_data.update()

View File

@ -69,7 +69,7 @@ class BinarySensor(ZhaEntity, BinarySensorEntity):
super().__init__(unique_id, zha_device, channels, **kwargs) super().__init__(unique_id, zha_device, channels, **kwargs)
self._channel = channels[0] self._channel = channels[0]
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(
@ -97,7 +97,7 @@ class BinarySensor(ZhaEntity, BinarySensorEntity):
self._state = bool(value) self._state = bool(value)
self.async_write_ha_state() self.async_write_ha_state()
async def async_update(self): async def async_update(self) -> None:
"""Attempt to retrieve on off state from the binary sensor.""" """Attempt to retrieve on off state from the binary sensor."""
await super().async_update() await super().async_update()
attribute = getattr(self._channel, "value_attribute", "on_off") attribute = getattr(self._channel, "value_attribute", "on_off")
@ -167,7 +167,7 @@ class IASZone(BinarySensor):
"""Return device class from component DEVICE_CLASSES.""" """Return device class from component DEVICE_CLASSES."""
return CLASS_MAPPING.get(self._channel.cluster.get("zone_type")) return CLASS_MAPPING.get(self._channel.cluster.get("zone_type"))
async def async_update(self): async def async_update(self) -> None:
"""Attempt to retrieve on off state from the binary sensor.""" """Attempt to retrieve on off state from the binary sensor."""
await super().async_update() await super().async_update()
value = await self._channel.get_attribute_value("zone_status") value = await self._channel.get_attribute_value("zone_status")

View File

@ -9,6 +9,7 @@ from __future__ import annotations
from datetime import datetime, timedelta from datetime import datetime, timedelta
import functools import functools
from random import randint from random import randint
from typing import Any
from zigpy.zcl.clusters.hvac import Fan as F, Thermostat as T from zigpy.zcl.clusters.hvac import Fan as F, Thermostat as T
@ -276,7 +277,7 @@ class Thermostat(ZhaEntity, ClimateEntity):
return self._presets return self._presets
@property @property
def supported_features(self): def supported_features(self) -> int:
"""Return the list of supported features.""" """Return the list of supported features."""
features = self._supported_flags features = self._supported_flags
if HVACMode.HEAT_COOL in self.hvac_modes: if HVACMode.HEAT_COOL in self.hvac_modes:
@ -358,7 +359,7 @@ class Thermostat(ZhaEntity, ClimateEntity):
return self.DEFAULT_MIN_TEMP return self.DEFAULT_MIN_TEMP
return round(min(temps) / ZCL_TEMP, 1) return round(min(temps) / ZCL_TEMP, 1)
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(
@ -427,7 +428,7 @@ class Thermostat(ZhaEntity, ClimateEntity):
self._preset = preset_mode self._preset = preset_mode
self.async_write_ha_state() self.async_write_ha_state()
async def async_set_temperature(self, **kwargs): async def async_set_temperature(self, **kwargs: Any) -> None:
"""Set new target temperature.""" """Set new target temperature."""
low_temp = kwargs.get(ATTR_TARGET_TEMP_LOW) low_temp = kwargs.get(ATTR_TARGET_TEMP_LOW)
high_temp = kwargs.get(ATTR_TARGET_TEMP_HIGH) high_temp = kwargs.get(ATTR_TARGET_TEMP_HIGH)
@ -533,7 +534,7 @@ class SinopeTechnologiesThermostat(Thermostat):
) )
) )
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()
async_track_time_interval( async_track_time_interval(

View File

@ -59,7 +59,7 @@ class ZHADeviceScannerEntity(ScannerEntity, ZhaEntity):
self._keepalive_interval = 60 self._keepalive_interval = 60
self._battery_level = None self._battery_level = None
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()
if self._battery_channel: if self._battery_channel:
@ -69,7 +69,7 @@ class ZHADeviceScannerEntity(ScannerEntity, ZhaEntity):
self.async_battery_percentage_remaining_updated, self.async_battery_percentage_remaining_updated,
) )
async def async_update(self): async def async_update(self) -> None:
"""Handle polling.""" """Handle polling."""
if self.zha_device.last_seen is None: if self.zha_device.last_seen is None:
self._connected = False self._connected = False

View File

@ -260,7 +260,7 @@ class IkeaFan(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("ikea_airpurifier") self._fan_channel = self.cluster_channels.get("ikea_airpurifier")
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(
@ -317,7 +317,7 @@ class IkeaFan(BaseFan, ZhaEntity):
] ]
await self.async_set_percentage(percentage) await self.async_set_percentage(percentage)
async def async_turn_off(self, **kwargs) -> None: async def async_turn_off(self, **kwargs: Any) -> None:
"""Turn the entity off.""" """Turn the entity off."""
await self.async_set_percentage(0) await self.async_set_percentage(0)

View File

@ -168,7 +168,7 @@ class BaseLight(LogMixin, light.LightEntity):
self._attr_brightness = value self._attr_brightness = value
self.async_write_ha_state() self.async_write_ha_state()
async def async_turn_on(self, **kwargs): async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn the entity on.""" """Turn the entity on."""
transition = kwargs.get(light.ATTR_TRANSITION) transition = kwargs.get(light.ATTR_TRANSITION)
duration = ( duration = (

View File

@ -2,6 +2,7 @@
from __future__ import annotations from __future__ import annotations
import logging import logging
from typing import Any
import voluptuous as vol import voluptuous as vol
from zhong_hong_hvac.hub import ZhongHongGateway from zhong_hong_hvac.hub import ZhongHongGateway
@ -141,7 +142,7 @@ class ZhongHongClimate(ClimateEntity):
self._current_fan_mode = None self._current_fan_mode = None
self.is_initialized = False self.is_initialized = False
async def async_added_to_hass(self): async def async_added_to_hass(self) -> None:
"""Register callbacks.""" """Register callbacks."""
self._device.register_update_callback(self._after_update) self._device.register_update_callback(self._after_update)
self.is_initialized = True self.is_initialized = True
@ -219,15 +220,15 @@ class ZhongHongClimate(ClimateEntity):
"""Return the maximum temperature.""" """Return the maximum temperature."""
return self._device.max_temp return self._device.max_temp
def turn_on(self): def turn_on(self) -> None:
"""Turn on ac.""" """Turn on ac."""
return self._device.turn_on() return self._device.turn_on()
def turn_off(self): def turn_off(self) -> None:
"""Turn off ac.""" """Turn off ac."""
return self._device.turn_off() return self._device.turn_off()
def set_temperature(self, **kwargs): def set_temperature(self, **kwargs: Any) -> None:
"""Set new target temperature.""" """Set new target temperature."""
if (temperature := kwargs.get(ATTR_TEMPERATURE)) is not None: if (temperature := kwargs.get(ATTR_TEMPERATURE)) is not None:
self._device.set_temperature(temperature) self._device.set_temperature(temperature)
@ -247,6 +248,6 @@ class ZhongHongClimate(ClimateEntity):
self._device.set_operation_mode(hvac_mode.upper()) self._device.set_operation_mode(hvac_mode.upper())
def set_fan_mode(self, fan_mode): def set_fan_mode(self, fan_mode: str) -> None:
"""Set new target fan mode.""" """Set new target fan mode."""
self._device.set_fan_mode(fan_mode) self._device.set_fan_mode(fan_mode)

View File

@ -107,7 +107,7 @@ class ZiggoMediaboxXLDevice(MediaPlayerEntity):
self._available = available self._available = available
self._state = None self._state = None
def update(self): def update(self) -> None:
"""Retrieve the state of the device.""" """Retrieve the state of the device."""
try: try:
if self._mediabox.test_connection(): if self._mediabox.test_connection():
@ -153,25 +153,25 @@ class ZiggoMediaboxXLDevice(MediaPlayerEntity):
for c in sorted(self._mediabox.channels().keys()) for c in sorted(self._mediabox.channels().keys())
] ]
def turn_on(self): def turn_on(self) -> None:
"""Turn the media player on.""" """Turn the media player on."""
self.send_keys(["POWER"]) self.send_keys(["POWER"])
def turn_off(self): def turn_off(self) -> None:
"""Turn off media player.""" """Turn off media player."""
self.send_keys(["POWER"]) self.send_keys(["POWER"])
def media_play(self): def media_play(self) -> None:
"""Send play command.""" """Send play command."""
self.send_keys(["PLAY"]) self.send_keys(["PLAY"])
self._state = STATE_PLAYING self._state = STATE_PLAYING
def media_pause(self): def media_pause(self) -> None:
"""Send pause command.""" """Send pause command."""
self.send_keys(["PAUSE"]) self.send_keys(["PAUSE"])
self._state = STATE_PAUSED self._state = STATE_PAUSED
def media_play_pause(self): def media_play_pause(self) -> None:
"""Simulate play pause media player.""" """Simulate play pause media player."""
self.send_keys(["PAUSE"]) self.send_keys(["PAUSE"])
if self._state == STATE_PAUSED: if self._state == STATE_PAUSED:
@ -179,12 +179,12 @@ class ZiggoMediaboxXLDevice(MediaPlayerEntity):
else: else:
self._state = STATE_PAUSED self._state = STATE_PAUSED
def media_next_track(self): def media_next_track(self) -> None:
"""Channel up.""" """Channel up."""
self.send_keys(["CHAN_UP"]) self.send_keys(["CHAN_UP"])
self._state = STATE_PLAYING self._state = STATE_PLAYING
def media_previous_track(self): def media_previous_track(self) -> None:
"""Channel down.""" """Channel down."""
self.send_keys(["CHAN_DOWN"]) self.send_keys(["CHAN_DOWN"])
self._state = STATE_PLAYING self._state = STATE_PLAYING

View File

@ -49,6 +49,6 @@ class ZMAvailabilitySensor(BinarySensorEntity):
"""Return the class of this device, from component DEVICE_CLASSES.""" """Return the class of this device, from component DEVICE_CLASSES."""
return BinarySensorDeviceClass.CONNECTIVITY return BinarySensorDeviceClass.CONNECTIVITY
def update(self): def update(self) -> None:
"""Update the state of this sensor (availability of ZoneMinder).""" """Update the state of this sensor (availability of ZoneMinder)."""
self._state = self._client.is_available self._state = self._client.is_available

View File

@ -50,7 +50,7 @@ class ZoneMinderCamera(MjpegCamera):
self._is_available = None self._is_available = None
self._monitor = monitor self._monitor = monitor
def update(self): def update(self) -> None:
"""Update our recording state from the ZM API.""" """Update our recording state from the ZM API."""
_LOGGER.debug("Updating camera state for monitor %i", self._monitor.id) _LOGGER.debug("Updating camera state for monitor %i", self._monitor.id)
self._is_recording = self._monitor.is_recording self._is_recording = self._monitor.is_recording

View File

@ -116,7 +116,7 @@ class ZMSensorMonitors(SensorEntity):
"""Return True if Monitor is available.""" """Return True if Monitor is available."""
return self._is_available return self._is_available
def update(self): def update(self) -> None:
"""Update the sensor.""" """Update the sensor."""
if not (state := self._monitor.function): if not (state := self._monitor.function):
self._state = None self._state = None
@ -143,7 +143,7 @@ class ZMSensorEvents(SensorEntity):
"""Return the name of the sensor.""" """Return the name of the sensor."""
return f"{self._monitor.name} {self.time_period.title}" return f"{self._monitor.name} {self.time_period.title}"
def update(self): def update(self) -> None:
"""Update the sensor.""" """Update the sensor."""
self._attr_native_value = self._monitor.get_events( self._attr_native_value = self._monitor.get_events(
self.time_period, self._include_archived self.time_period, self._include_archived
@ -174,7 +174,7 @@ class ZMSensorRunState(SensorEntity):
"""Return True if ZoneMinder is available.""" """Return True if ZoneMinder is available."""
return self._is_available return self._is_available
def update(self): def update(self) -> None:
"""Update the sensor.""" """Update the sensor."""
self._state = self._client.get_active_state() self._state = self._client.get_active_state()
self._is_available = self._client.is_available self._is_available = self._client.is_available

View File

@ -2,6 +2,7 @@
from __future__ import annotations from __future__ import annotations
import logging import logging
from typing import Any
import voluptuous as vol import voluptuous as vol
from zoneminder.monitor import MonitorState from zoneminder.monitor import MonitorState
@ -64,7 +65,7 @@ class ZMSwitchMonitors(SwitchEntity):
"""Return the name of the switch.""" """Return the name of the switch."""
return f"{self._monitor.name} State" return f"{self._monitor.name} State"
def update(self): def update(self) -> None:
"""Update the switch value.""" """Update the switch value."""
self._state = self._monitor.function == self._on_state self._state = self._monitor.function == self._on_state
@ -73,10 +74,10 @@ class ZMSwitchMonitors(SwitchEntity):
"""Return True if entity is on.""" """Return True if entity is on."""
return self._state return self._state
def turn_on(self, **kwargs): def turn_on(self, **kwargs: Any) -> None:
"""Turn the entity on.""" """Turn the entity on."""
self._monitor.function = self._on_state self._monitor.function = self._on_state
def turn_off(self, **kwargs): def turn_off(self, **kwargs: Any) -> None:
"""Turn the entity off.""" """Turn the entity off."""
self._monitor.function = self._off_state self._monitor.function = self._off_state

View File

@ -1,6 +1,8 @@
"""Representation of a thermostat.""" """Representation of a thermostat."""
from __future__ import annotations from __future__ import annotations
from typing import Any
from zwave_me_ws import ZWaveMeData from zwave_me_ws import ZWaveMeData
from homeassistant.components.climate import ClimateEntity from homeassistant.components.climate import ClimateEntity
@ -52,7 +54,7 @@ class ZWaveMeClimate(ZWaveMeEntity, ClimateEntity):
_attr_hvac_modes = [HVACMode.HEAT] _attr_hvac_modes = [HVACMode.HEAT]
_attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE _attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE
def set_temperature(self, **kwargs) -> None: def set_temperature(self, **kwargs: Any) -> None:
"""Set new target temperature.""" """Set new target temperature."""
if (temperature := kwargs.get(ATTR_TEMPERATURE)) is None: if (temperature := kwargs.get(ATTR_TEMPERATURE)) is None:
return return