From 18cdb4e283d86c5096af7440241096d483e36aa6 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Tue, 6 Sep 2022 10:16:59 +0000 Subject: [PATCH] Improve entity type hints [z] --- homeassistant/components/zabbix/sensor.py | 2 +- homeassistant/components/zamg/sensor.py | 2 +- homeassistant/components/zamg/weather.py | 2 +- homeassistant/components/zha/binary_sensor.py | 6 +++--- homeassistant/components/zha/climate.py | 9 +++++---- homeassistant/components/zha/device_tracker.py | 4 ++-- homeassistant/components/zha/fan.py | 4 ++-- homeassistant/components/zha/light.py | 2 +- homeassistant/components/zhong_hong/climate.py | 11 ++++++----- .../components/ziggo_mediabox_xl/media_player.py | 16 ++++++++-------- .../components/zoneminder/binary_sensor.py | 2 +- homeassistant/components/zoneminder/camera.py | 2 +- homeassistant/components/zoneminder/sensor.py | 6 +++--- homeassistant/components/zoneminder/switch.py | 7 ++++--- homeassistant/components/zwave_me/climate.py | 4 +++- 15 files changed, 42 insertions(+), 37 deletions(-) diff --git a/homeassistant/components/zabbix/sensor.py b/homeassistant/components/zabbix/sensor.py index 3e72e4d71f1ade..a5172d5ef956f9 100644 --- a/homeassistant/components/zabbix/sensor.py +++ b/homeassistant/components/zabbix/sensor.py @@ -117,7 +117,7 @@ def _call_zabbix_api(self): output="extend", only_true=1, monitored=1, filter={"value": 1} ) - def update(self): + def update(self) -> None: """Update the sensor.""" _LOGGER.debug("Updating ZabbixTriggerCountSensor: %s", str(self._name)) triggers = self._call_zabbix_api() diff --git a/homeassistant/components/zamg/sensor.py b/homeassistant/components/zamg/sensor.py index e8d5f745ccebbc..73902b1982f7f7 100644 --- a/homeassistant/components/zamg/sensor.py +++ b/homeassistant/components/zamg/sensor.py @@ -264,7 +264,7 @@ def extra_state_attributes(self): ATTR_UPDATED: self.probe.last_update.isoformat(), } - def update(self): + def update(self) -> None: """Delegate update to probe.""" self.probe.update() diff --git a/homeassistant/components/zamg/weather.py b/homeassistant/components/zamg/weather.py index 6910955fcf7449..eb2992df64f388 100644 --- a/homeassistant/components/zamg/weather.py +++ b/homeassistant/components/zamg/weather.py @@ -139,6 +139,6 @@ def wind_bearing(self): """Return the wind bearing.""" return self.zamg_data.get_data(ATTR_WEATHER_WIND_BEARING) - def update(self): + def update(self) -> None: """Update current conditions.""" self.zamg_data.update() diff --git a/homeassistant/components/zha/binary_sensor.py b/homeassistant/components/zha/binary_sensor.py index 23d26e4b13f6fb..abddfda3358122 100644 --- a/homeassistant/components/zha/binary_sensor.py +++ b/homeassistant/components/zha/binary_sensor.py @@ -69,7 +69,7 @@ def __init__(self, unique_id, zha_device, channels, **kwargs): super().__init__(unique_id, zha_device, channels, **kwargs) 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.""" await super().async_added_to_hass() self.async_accept_signal( @@ -97,7 +97,7 @@ def async_set_state(self, attr_id, attr_name, value): self._state = bool(value) 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.""" await super().async_update() attribute = getattr(self._channel, "value_attribute", "on_off") @@ -167,7 +167,7 @@ def device_class(self) -> BinarySensorDeviceClass | None: """Return device class from component DEVICE_CLASSES.""" 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.""" await super().async_update() value = await self._channel.get_attribute_value("zone_status") diff --git a/homeassistant/components/zha/climate.py b/homeassistant/components/zha/climate.py index 573b3df44fa56d..4585d41d44df4b 100644 --- a/homeassistant/components/zha/climate.py +++ b/homeassistant/components/zha/climate.py @@ -9,6 +9,7 @@ from datetime import datetime, timedelta import functools from random import randint +from typing import Any from zigpy.zcl.clusters.hvac import Fan as F, Thermostat as T @@ -276,7 +277,7 @@ def preset_modes(self) -> list[str] | None: return self._presets @property - def supported_features(self): + def supported_features(self) -> int: """Return the list of supported features.""" features = self._supported_flags if HVACMode.HEAT_COOL in self.hvac_modes: @@ -358,7 +359,7 @@ def min_temp(self) -> float: return self.DEFAULT_MIN_TEMP 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.""" await super().async_added_to_hass() self.async_accept_signal( @@ -427,7 +428,7 @@ async def async_set_preset_mode(self, preset_mode: str) -> None: self._preset = preset_mode 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.""" low_temp = kwargs.get(ATTR_TARGET_TEMP_LOW) high_temp = kwargs.get(ATTR_TARGET_TEMP_HIGH) @@ -533,7 +534,7 @@ def _async_update_time(self, timestamp=None) -> None: ) ) - 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() async_track_time_interval( diff --git a/homeassistant/components/zha/device_tracker.py b/homeassistant/components/zha/device_tracker.py index 5a20273d085b05..8ecc85a4e56a81 100644 --- a/homeassistant/components/zha/device_tracker.py +++ b/homeassistant/components/zha/device_tracker.py @@ -59,7 +59,7 @@ def __init__(self, unique_id, zha_device, channels, **kwargs): self._keepalive_interval = 60 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.""" await super().async_added_to_hass() if self._battery_channel: @@ -69,7 +69,7 @@ async def async_added_to_hass(self): self.async_battery_percentage_remaining_updated, ) - async def async_update(self): + async def async_update(self) -> None: """Handle polling.""" if self.zha_device.last_seen is None: self._connected = False diff --git a/homeassistant/components/zha/fan.py b/homeassistant/components/zha/fan.py index c38a71e32491b9..6c1d2bf2bee9be 100644 --- a/homeassistant/components/zha/fan.py +++ b/homeassistant/components/zha/fan.py @@ -260,7 +260,7 @@ def __init__(self, unique_id, zha_device, channels, **kwargs): super().__init__(unique_id, zha_device, channels, **kwargs) 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.""" await super().async_added_to_hass() self.async_accept_signal( @@ -317,7 +317,7 @@ async def async_turn_on(self, percentage=None, preset_mode=None, **kwargs) -> No ] 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.""" await self.async_set_percentage(0) diff --git a/homeassistant/components/zha/light.py b/homeassistant/components/zha/light.py index dbb250a5d33b71..ea46c0c49f1639 100644 --- a/homeassistant/components/zha/light.py +++ b/homeassistant/components/zha/light.py @@ -168,7 +168,7 @@ def set_level(self, value: int) -> None: self._attr_brightness = value 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.""" transition = kwargs.get(light.ATTR_TRANSITION) duration = ( diff --git a/homeassistant/components/zhong_hong/climate.py b/homeassistant/components/zhong_hong/climate.py index 0877e19834fd75..7566f5166e6852 100644 --- a/homeassistant/components/zhong_hong/climate.py +++ b/homeassistant/components/zhong_hong/climate.py @@ -2,6 +2,7 @@ from __future__ import annotations import logging +from typing import Any import voluptuous as vol from zhong_hong_hvac.hub import ZhongHongGateway @@ -141,7 +142,7 @@ def __init__(self, hub, addr_out, addr_in): self._current_fan_mode = None self.is_initialized = False - async def async_added_to_hass(self): + async def async_added_to_hass(self) -> None: """Register callbacks.""" self._device.register_update_callback(self._after_update) self.is_initialized = True @@ -219,15 +220,15 @@ def max_temp(self): """Return the maximum temperature.""" return self._device.max_temp - def turn_on(self): + def turn_on(self) -> None: """Turn on ac.""" return self._device.turn_on() - def turn_off(self): + def turn_off(self) -> None: """Turn off ac.""" return self._device.turn_off() - def set_temperature(self, **kwargs): + def set_temperature(self, **kwargs: Any) -> None: """Set new target temperature.""" if (temperature := kwargs.get(ATTR_TEMPERATURE)) is not None: self._device.set_temperature(temperature) @@ -247,6 +248,6 @@ def set_hvac_mode(self, hvac_mode: HVACMode) -> None: 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.""" self._device.set_fan_mode(fan_mode) diff --git a/homeassistant/components/ziggo_mediabox_xl/media_player.py b/homeassistant/components/ziggo_mediabox_xl/media_player.py index 42c86020d2e938..fd2ca59013a7f1 100644 --- a/homeassistant/components/ziggo_mediabox_xl/media_player.py +++ b/homeassistant/components/ziggo_mediabox_xl/media_player.py @@ -107,7 +107,7 @@ def __init__(self, mediabox, host, name, available): self._available = available self._state = None - def update(self): + def update(self) -> None: """Retrieve the state of the device.""" try: if self._mediabox.test_connection(): @@ -153,25 +153,25 @@ def source_list(self): for c in sorted(self._mediabox.channels().keys()) ] - def turn_on(self): + def turn_on(self) -> None: """Turn the media player on.""" self.send_keys(["POWER"]) - def turn_off(self): + def turn_off(self) -> None: """Turn off media player.""" self.send_keys(["POWER"]) - def media_play(self): + def media_play(self) -> None: """Send play command.""" self.send_keys(["PLAY"]) self._state = STATE_PLAYING - def media_pause(self): + def media_pause(self) -> None: """Send pause command.""" self.send_keys(["PAUSE"]) self._state = STATE_PAUSED - def media_play_pause(self): + def media_play_pause(self) -> None: """Simulate play pause media player.""" self.send_keys(["PAUSE"]) if self._state == STATE_PAUSED: @@ -179,12 +179,12 @@ def media_play_pause(self): else: self._state = STATE_PAUSED - def media_next_track(self): + def media_next_track(self) -> None: """Channel up.""" self.send_keys(["CHAN_UP"]) self._state = STATE_PLAYING - def media_previous_track(self): + def media_previous_track(self) -> None: """Channel down.""" self.send_keys(["CHAN_DOWN"]) self._state = STATE_PLAYING diff --git a/homeassistant/components/zoneminder/binary_sensor.py b/homeassistant/components/zoneminder/binary_sensor.py index 21f4588555c200..a091c5fd308f9b 100644 --- a/homeassistant/components/zoneminder/binary_sensor.py +++ b/homeassistant/components/zoneminder/binary_sensor.py @@ -49,6 +49,6 @@ def device_class(self): """Return the class of this device, from component DEVICE_CLASSES.""" return BinarySensorDeviceClass.CONNECTIVITY - def update(self): + def update(self) -> None: """Update the state of this sensor (availability of ZoneMinder).""" self._state = self._client.is_available diff --git a/homeassistant/components/zoneminder/camera.py b/homeassistant/components/zoneminder/camera.py index a627f64d0bf004..7c0c8b9d453d2a 100644 --- a/homeassistant/components/zoneminder/camera.py +++ b/homeassistant/components/zoneminder/camera.py @@ -50,7 +50,7 @@ def __init__(self, monitor, verify_ssl): self._is_available = None self._monitor = monitor - def update(self): + def update(self) -> None: """Update our recording state from the ZM API.""" _LOGGER.debug("Updating camera state for monitor %i", self._monitor.id) self._is_recording = self._monitor.is_recording diff --git a/homeassistant/components/zoneminder/sensor.py b/homeassistant/components/zoneminder/sensor.py index 53ed16c037ba98..a7534604514dfe 100644 --- a/homeassistant/components/zoneminder/sensor.py +++ b/homeassistant/components/zoneminder/sensor.py @@ -116,7 +116,7 @@ def available(self): """Return True if Monitor is available.""" return self._is_available - def update(self): + def update(self) -> None: """Update the sensor.""" if not (state := self._monitor.function): self._state = None @@ -143,7 +143,7 @@ def name(self): """Return the name of the sensor.""" return f"{self._monitor.name} {self.time_period.title}" - def update(self): + def update(self) -> None: """Update the sensor.""" self._attr_native_value = self._monitor.get_events( self.time_period, self._include_archived @@ -174,7 +174,7 @@ def available(self): """Return True if ZoneMinder is available.""" return self._is_available - def update(self): + def update(self) -> None: """Update the sensor.""" self._state = self._client.get_active_state() self._is_available = self._client.is_available diff --git a/homeassistant/components/zoneminder/switch.py b/homeassistant/components/zoneminder/switch.py index bd7f55915d1cf3..fc153ca81d8741 100644 --- a/homeassistant/components/zoneminder/switch.py +++ b/homeassistant/components/zoneminder/switch.py @@ -2,6 +2,7 @@ from __future__ import annotations import logging +from typing import Any import voluptuous as vol from zoneminder.monitor import MonitorState @@ -64,7 +65,7 @@ def name(self): """Return the name of the switch.""" return f"{self._monitor.name} State" - def update(self): + def update(self) -> None: """Update the switch value.""" self._state = self._monitor.function == self._on_state @@ -73,10 +74,10 @@ def is_on(self): """Return True if entity is on.""" return self._state - def turn_on(self, **kwargs): + def turn_on(self, **kwargs: Any) -> None: """Turn the entity on.""" self._monitor.function = self._on_state - def turn_off(self, **kwargs): + def turn_off(self, **kwargs: Any) -> None: """Turn the entity off.""" self._monitor.function = self._off_state diff --git a/homeassistant/components/zwave_me/climate.py b/homeassistant/components/zwave_me/climate.py index 373dbec28366ef..63903478b511ad 100644 --- a/homeassistant/components/zwave_me/climate.py +++ b/homeassistant/components/zwave_me/climate.py @@ -1,6 +1,8 @@ """Representation of a thermostat.""" from __future__ import annotations +from typing import Any + from zwave_me_ws import ZWaveMeData from homeassistant.components.climate import ClimateEntity @@ -52,7 +54,7 @@ class ZWaveMeClimate(ZWaveMeEntity, ClimateEntity): _attr_hvac_modes = [HVACMode.HEAT] _attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE - def set_temperature(self, **kwargs) -> None: + def set_temperature(self, **kwargs: Any) -> None: """Set new target temperature.""" if (temperature := kwargs.get(ATTR_TEMPERATURE)) is None: return