Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve entity type hints [z] #77890

Merged
merged 1 commit into from Sep 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion homeassistant/components/zabbix/sensor.py
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/zamg/sensor.py
Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/zamg/weather.py
Expand Up @@ -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()
6 changes: 3 additions & 3 deletions homeassistant/components/zha/binary_sensor.py
Expand Up @@ -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(
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down
9 changes: 5 additions & 4 deletions homeassistant/components/zha/climate.py
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/zha/device_tracker.py
Expand Up @@ -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:
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/zha/fan.py
Expand Up @@ -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(
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/zha/light.py
Expand Up @@ -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 = (
Expand Down
11 changes: 6 additions & 5 deletions homeassistant/components/zhong_hong/climate.py
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
16 changes: 8 additions & 8 deletions homeassistant/components/ziggo_mediabox_xl/media_player.py
Expand Up @@ -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():
Expand Down Expand Up @@ -153,38 +153,38 @@ 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:
self._state = STATE_PLAYING
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
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/zoneminder/binary_sensor.py
Expand Up @@ -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
2 changes: 1 addition & 1 deletion homeassistant/components/zoneminder/camera.py
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions homeassistant/components/zoneminder/sensor.py
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
7 changes: 4 additions & 3 deletions homeassistant/components/zoneminder/switch.py
Expand Up @@ -2,6 +2,7 @@
from __future__ import annotations

import logging
from typing import Any

import voluptuous as vol
from zoneminder.monitor import MonitorState
Expand Down Expand Up @@ -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

Expand All @@ -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
4 changes: 3 additions & 1 deletion 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
Expand Down Expand Up @@ -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
Expand Down