Improve entity type hints [h] (#77468)

This commit is contained in:
epenet 2022-08-30 20:55:01 +02:00 committed by GitHub
parent 05264cedfa
commit a1374963d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
38 changed files with 153 additions and 124 deletions

View File

@ -154,7 +154,7 @@ class HabitipySensor(SensorEntity):
self._state = None self._state = None
self._updater = updater self._updater = updater
async def async_update(self): async def async_update(self) -> None:
"""Update Condition and Forecast.""" """Update Condition and Forecast."""
await self._updater.update() await self._updater.update()
data = self._updater.data data = self._updater.data
@ -194,7 +194,7 @@ class HabitipyTaskSensor(SensorEntity):
self._state = None self._state = None
self._updater = updater self._updater = updater
async def async_update(self): async def async_update(self) -> None:
"""Update Condition and Forecast.""" """Update Condition and Forecast."""
await self._updater.update() await self._updater.update()
all_tasks = self._updater.tasks all_tasks = self._updater.tasks

View File

@ -69,7 +69,7 @@ class HkAvrDevice(MediaPlayerEntity):
self._muted = avr.muted self._muted = avr.muted
self._current_source = avr.current_source self._current_source = avr.current_source
def update(self): def update(self) -> None:
"""Update the state of this media_player.""" """Update the state of this media_player."""
if self._avr.is_on(): if self._avr.is_on():
self._state = STATE_ON self._state = STATE_ON
@ -106,26 +106,26 @@ class HkAvrDevice(MediaPlayerEntity):
"""Available sources.""" """Available sources."""
return self._source_list return self._source_list
def turn_on(self): def turn_on(self) -> None:
"""Turn the AVR on.""" """Turn the AVR on."""
self._avr.power_on() self._avr.power_on()
def turn_off(self): def turn_off(self) -> None:
"""Turn off the AVR.""" """Turn off the AVR."""
self._avr.power_off() self._avr.power_off()
def select_source(self, source): def select_source(self, source: str) -> None:
"""Select input source.""" """Select input source."""
return self._avr.select_source(source) return self._avr.select_source(source)
def volume_up(self): def volume_up(self) -> None:
"""Volume up the AVR.""" """Volume up the AVR."""
return self._avr.volume_up() return self._avr.volume_up()
def volume_down(self): def volume_down(self) -> None:
"""Volume down AVR.""" """Volume down AVR."""
return self._avr.volume_down() return self._avr.volume_down()
def mute_volume(self, mute): def mute_volume(self, mute: bool) -> None:
"""Send mute command.""" """Send mute command."""
return self._avr.mute(mute) return self._avr.mute(mute)

View File

@ -1,6 +1,8 @@
"""Support for Harmony Hub devices.""" """Support for Harmony Hub devices."""
from collections.abc import Iterable
import json import json
import logging import logging
from typing import Any
import voluptuous as vol import voluptuous as vol
@ -124,7 +126,7 @@ class HarmonyRemote(HarmonyEntity, RemoteEntity, RestoreEntity):
self._activity_starting = None self._activity_starting = None
self.async_write_ha_state() self.async_write_ha_state()
async def async_added_to_hass(self): async def async_added_to_hass(self) -> None:
"""Complete the initialization.""" """Complete the initialization."""
await super().async_added_to_hass() await super().async_added_to_hass()
@ -205,7 +207,7 @@ class HarmonyRemote(HarmonyEntity, RemoteEntity, RestoreEntity):
self.async_new_activity(self._data.current_activity) self.async_new_activity(self._data.current_activity)
await self.hass.async_add_executor_job(self.write_config_file) await self.hass.async_add_executor_job(self.write_config_file)
async def async_turn_on(self, **kwargs): async def async_turn_on(self, **kwargs: Any) -> None:
"""Start an activity from the Harmony device.""" """Start an activity from the Harmony device."""
_LOGGER.debug("%s: Turn On", self.name) _LOGGER.debug("%s: Turn On", self.name)
@ -223,11 +225,11 @@ class HarmonyRemote(HarmonyEntity, RemoteEntity, RestoreEntity):
else: else:
_LOGGER.error("%s: No activity specified with turn_on service", self.name) _LOGGER.error("%s: No activity specified with turn_on service", self.name)
async def async_turn_off(self, **kwargs): async def async_turn_off(self, **kwargs: Any) -> None:
"""Start the PowerOff activity.""" """Start the PowerOff activity."""
await self._data.async_power_off() await self._data.async_power_off()
async def async_send_command(self, command, **kwargs): async def async_send_command(self, command: Iterable[str], **kwargs: Any) -> None:
"""Send a list of commands to one device.""" """Send a list of commands to one device."""
_LOGGER.debug("%s: Send Command", self.name) _LOGGER.debug("%s: Send Command", self.name)
if (device := kwargs.get(ATTR_DEVICE)) is None: if (device := kwargs.get(ATTR_DEVICE)) is None:

View File

@ -1,5 +1,6 @@
"""Support for Harmony Hub activities.""" """Support for Harmony Hub activities."""
import logging import logging
from typing import Any
from homeassistant.components.switch import SwitchEntity from homeassistant.components.switch import SwitchEntity
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
@ -50,11 +51,11 @@ class HarmonyActivitySwitch(HarmonyEntity, SwitchEntity):
_, activity_name = self._data.current_activity _, activity_name = self._data.current_activity
return activity_name == self._activity_name return activity_name == self._activity_name
async def async_turn_on(self, **kwargs): async def async_turn_on(self, **kwargs: Any) -> None:
"""Start this activity.""" """Start this activity."""
await self._data.async_start_activity(self._activity_name) await self._data.async_start_activity(self._activity_name)
async def async_turn_off(self, **kwargs): async def async_turn_off(self, **kwargs: Any) -> None:
"""Stop this activity.""" """Stop this activity."""
await self._data.async_power_off() await self._data.async_power_off()

View File

@ -101,7 +101,7 @@ class SupervisorAddonUpdateEntity(HassioAddonEntity, UpdateEntity):
return self.coordinator.data[DATA_KEY_ADDONS][self._addon_slug] return self.coordinator.data[DATA_KEY_ADDONS][self._addon_slug]
@property @property
def auto_update(self): def auto_update(self) -> bool:
"""Return true if auto-update is enabled for the add-on.""" """Return true if auto-update is enabled for the add-on."""
return self._addon_data[ATTR_AUTO_UPDATE] return self._addon_data[ATTR_AUTO_UPDATE]
@ -159,7 +159,7 @@ class SupervisorAddonUpdateEntity(HassioAddonEntity, UpdateEntity):
async def async_install( async def async_install(
self, self,
version: str | None = None, version: str | None = None,
backup: bool | None = False, backup: bool = False,
**kwargs: Any, **kwargs: Any,
) -> None: ) -> None:
"""Install an update.""" """Install an update."""

View File

@ -100,7 +100,7 @@ class HaveIBeenPwnedSensor(SensorEntity):
return val return val
async def async_added_to_hass(self): async def async_added_to_hass(self) -> None:
"""Get initial data.""" """Get initial data."""
# To make sure we get initial data for the sensors ignoring the normal # To make sure we get initial data for the sensors ignoring the normal
# throttle of 15 minutes but using an update throttle of 5 seconds # throttle of 15 minutes but using an update throttle of 5 seconds
@ -126,7 +126,7 @@ class HaveIBeenPwnedSensor(SensorEntity):
self._state = len(self._data.data[self._email]) self._state = len(self._data.data[self._email])
self.schedule_update_ha_state() self.schedule_update_ha_state()
def update(self): def update(self) -> None:
"""Update data and see if it contains data for our email.""" """Update data and see if it contains data for our email."""
self._data.update() self._data.update()

View File

@ -91,7 +91,7 @@ class HddTempSensor(SensorEntity):
if self._details is not None: if self._details is not None:
return {ATTR_DEVICE: self._details[0], ATTR_MODEL: self._details[1]} return {ATTR_DEVICE: self._details[0], ATTR_MODEL: self._details[1]}
def update(self): def update(self) -> None:
"""Get the latest data from HDDTemp daemon and updates the state.""" """Get the latest data from HDDTemp daemon and updates the state."""
self.hddtemp.update() self.hddtemp.update()

View File

@ -2,6 +2,7 @@
from __future__ import annotations from __future__ import annotations
import logging import logging
from typing import Any
from pycec.commands import CecCommand, KeyPressCommand, KeyReleaseCommand from pycec.commands import CecCommand, KeyPressCommand, KeyReleaseCommand
from pycec.const import ( from pycec.const import (
@ -83,69 +84,69 @@ class CecPlayerEntity(CecEntity, MediaPlayerEntity):
"""Send playback status to CEC adapter.""" """Send playback status to CEC adapter."""
self._device.async_send_command(CecCommand(key, dst=self._logical_address)) self._device.async_send_command(CecCommand(key, dst=self._logical_address))
def mute_volume(self, mute): def mute_volume(self, mute: bool) -> None:
"""Mute volume.""" """Mute volume."""
self.send_keypress(KEY_MUTE_TOGGLE) self.send_keypress(KEY_MUTE_TOGGLE)
def media_previous_track(self): def media_previous_track(self) -> None:
"""Go to previous track.""" """Go to previous track."""
self.send_keypress(KEY_BACKWARD) self.send_keypress(KEY_BACKWARD)
def turn_on(self): def turn_on(self) -> None:
"""Turn device on.""" """Turn device on."""
self._device.turn_on() self._device.turn_on()
self._state = STATE_ON self._state = STATE_ON
def clear_playlist(self): def clear_playlist(self) -> None:
"""Clear players playlist.""" """Clear players playlist."""
raise NotImplementedError() raise NotImplementedError()
def turn_off(self): def turn_off(self) -> None:
"""Turn device off.""" """Turn device off."""
self._device.turn_off() self._device.turn_off()
self._state = STATE_OFF self._state = STATE_OFF
def media_stop(self): def media_stop(self) -> None:
"""Stop playback.""" """Stop playback."""
self.send_keypress(KEY_STOP) self.send_keypress(KEY_STOP)
self._state = STATE_IDLE self._state = STATE_IDLE
def play_media(self, media_type, media_id, **kwargs): def play_media(self, media_type: str, media_id: str, **kwargs: Any) -> None:
"""Not supported.""" """Not supported."""
raise NotImplementedError() raise NotImplementedError()
def media_next_track(self): def media_next_track(self) -> None:
"""Skip to next track.""" """Skip to next track."""
self.send_keypress(KEY_FORWARD) self.send_keypress(KEY_FORWARD)
def media_seek(self, position): def media_seek(self, position: float) -> None:
"""Not supported.""" """Not supported."""
raise NotImplementedError() raise NotImplementedError()
def set_volume_level(self, volume): def set_volume_level(self, volume: float) -> None:
"""Set volume level, range 0..1.""" """Set volume level, range 0..1."""
raise NotImplementedError() raise NotImplementedError()
def media_pause(self): def media_pause(self) -> None:
"""Pause playback.""" """Pause playback."""
self.send_keypress(KEY_PAUSE) self.send_keypress(KEY_PAUSE)
self._state = STATE_PAUSED self._state = STATE_PAUSED
def select_source(self, source): def select_source(self, source: str) -> None:
"""Not supported.""" """Not supported."""
raise NotImplementedError() raise NotImplementedError()
def media_play(self): def media_play(self) -> None:
"""Start playback.""" """Start playback."""
self.send_keypress(KEY_PLAY) self.send_keypress(KEY_PLAY)
self._state = STATE_PLAYING self._state = STATE_PLAYING
def volume_up(self): def volume_up(self) -> None:
"""Increase volume.""" """Increase volume."""
_LOGGER.debug("%s: volume up", self._logical_address) _LOGGER.debug("%s: volume up", self._logical_address)
self.send_keypress(KEY_VOLUME_UP) self.send_keypress(KEY_VOLUME_UP)
def volume_down(self): def volume_down(self) -> None:
"""Decrease volume.""" """Decrease volume."""
_LOGGER.debug("%s: volume down", self._logical_address) _LOGGER.debug("%s: volume down", self._logical_address)
self.send_keypress(KEY_VOLUME_DOWN) self.send_keypress(KEY_VOLUME_DOWN)
@ -155,7 +156,7 @@ class CecPlayerEntity(CecEntity, MediaPlayerEntity):
"""Cache state of device.""" """Cache state of device."""
return self._state return self._state
def update(self): def update(self) -> None:
"""Update device status.""" """Update device status."""
device = self._device device = self._device
if device.power_status in [POWER_OFF, 3]: if device.power_status in [POWER_OFF, 3]:

View File

@ -2,6 +2,7 @@
from __future__ import annotations from __future__ import annotations
import logging import logging
from typing import Any
from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN, SwitchEntity from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN, SwitchEntity
from homeassistant.const import STATE_OFF, STATE_ON from homeassistant.const import STATE_OFF, STATE_ON
@ -40,13 +41,13 @@ class CecSwitchEntity(CecEntity, SwitchEntity):
CecEntity.__init__(self, device, logical) CecEntity.__init__(self, device, logical)
self.entity_id = f"{SWITCH_DOMAIN}.hdmi_{hex(self._logical_address)[2:]}" self.entity_id = f"{SWITCH_DOMAIN}.hdmi_{hex(self._logical_address)[2:]}"
def turn_on(self, **kwargs) -> None: def turn_on(self, **kwargs: Any) -> None:
"""Turn device on.""" """Turn device on."""
self._device.turn_on() self._device.turn_on()
self._state = STATE_ON self._state = STATE_ON
self.schedule_update_ha_state(force_refresh=False) self.schedule_update_ha_state(force_refresh=False)
def turn_off(self, **kwargs) -> None: def turn_off(self, **kwargs: Any) -> None:
"""Turn device off.""" """Turn device off."""
self._device.turn_off() self._device.turn_off()
self._state = STATE_OFF self._state = STATE_OFF

View File

@ -112,7 +112,7 @@ class HeatmiserV3Thermostat(ClimateEntity):
self._target_temperature = int(temperature) self._target_temperature = int(temperature)
self.therm.set_target_temp(self._target_temperature) self.therm.set_target_temp(self._target_temperature)
def update(self): def update(self) -> None:
"""Get the latest data.""" """Get the latest data."""
self.uh1.reopen() self.uh1.reopen()
if not self.uh1.status: if not self.uh1.status:

View File

@ -17,6 +17,7 @@ from homeassistant.components.media_player import (
MediaPlayerEntityFeature, MediaPlayerEntityFeature,
) )
from homeassistant.components.media_player.browse_media import ( from homeassistant.components.media_player.browse_media import (
BrowseMedia,
async_process_play_media_url, async_process_play_media_url,
) )
from homeassistant.components.media_player.const import ( from homeassistant.components.media_player.const import (
@ -136,11 +137,11 @@ class HeosMediaPlayer(MediaPlayerEntity):
self._media_position_updated_at = utcnow() self._media_position_updated_at = utcnow()
await self.async_update_ha_state(True) await self.async_update_ha_state(True)
async def _heos_updated(self): async def _heos_updated(self) -> None:
"""Handle sources changed.""" """Handle sources changed."""
await self.async_update_ha_state(True) await self.async_update_ha_state(True)
async def async_added_to_hass(self): async def async_added_to_hass(self) -> None:
"""Device added to hass.""" """Device added to hass."""
# Update state when attributes of the player change # Update state when attributes of the player change
self._signals.append( self._signals.append(
@ -159,7 +160,7 @@ class HeosMediaPlayer(MediaPlayerEntity):
async_dispatcher_send(self.hass, SIGNAL_HEOS_PLAYER_ADDED) async_dispatcher_send(self.hass, SIGNAL_HEOS_PLAYER_ADDED)
@log_command_error("clear playlist") @log_command_error("clear playlist")
async def async_clear_playlist(self): async def async_clear_playlist(self) -> None:
"""Clear players playlist.""" """Clear players playlist."""
await self._player.clear_queue() await self._player.clear_queue()
@ -169,37 +170,39 @@ class HeosMediaPlayer(MediaPlayerEntity):
await self._group_manager.async_join_players(self.entity_id, group_members) await self._group_manager.async_join_players(self.entity_id, group_members)
@log_command_error("pause") @log_command_error("pause")
async def async_media_pause(self): async def async_media_pause(self) -> None:
"""Send pause command.""" """Send pause command."""
await self._player.pause() await self._player.pause()
@log_command_error("play") @log_command_error("play")
async def async_media_play(self): async def async_media_play(self) -> None:
"""Send play command.""" """Send play command."""
await self._player.play() await self._player.play()
@log_command_error("move to previous track") @log_command_error("move to previous track")
async def async_media_previous_track(self): async def async_media_previous_track(self) -> None:
"""Send previous track command.""" """Send previous track command."""
await self._player.play_previous() await self._player.play_previous()
@log_command_error("move to next track") @log_command_error("move to next track")
async def async_media_next_track(self): async def async_media_next_track(self) -> None:
"""Send next track command.""" """Send next track command."""
await self._player.play_next() await self._player.play_next()
@log_command_error("stop") @log_command_error("stop")
async def async_media_stop(self): async def async_media_stop(self) -> None:
"""Send stop command.""" """Send stop command."""
await self._player.stop() await self._player.stop()
@log_command_error("set mute") @log_command_error("set mute")
async def async_mute_volume(self, mute): async def async_mute_volume(self, mute: bool) -> None:
"""Mute the volume.""" """Mute the volume."""
await self._player.set_mute(mute) await self._player.set_mute(mute)
@log_command_error("play media") @log_command_error("play media")
async def async_play_media(self, media_type, media_id, **kwargs): async def async_play_media(
self, media_type: str, media_id: str, **kwargs: Any
) -> None:
"""Play a piece of media.""" """Play a piece of media."""
if media_source.is_media_source_id(media_id): if media_source.is_media_source_id(media_id):
media_type = MEDIA_TYPE_URL media_type = MEDIA_TYPE_URL
@ -218,7 +221,7 @@ class HeosMediaPlayer(MediaPlayerEntity):
# media_id may be an int or a str # media_id may be an int or a str
selects = await self._player.get_quick_selects() selects = await self._player.get_quick_selects()
try: try:
index = int(media_id) index: int | None = int(media_id)
except ValueError: except ValueError:
# Try finding index by name # Try finding index by name
index = next( index = next(
@ -262,21 +265,21 @@ class HeosMediaPlayer(MediaPlayerEntity):
raise ValueError(f"Unsupported media type '{media_type}'") raise ValueError(f"Unsupported media type '{media_type}'")
@log_command_error("select source") @log_command_error("select source")
async def async_select_source(self, source): async def async_select_source(self, source: str) -> None:
"""Select input source.""" """Select input source."""
await self._source_manager.play_source(source, self._player) await self._source_manager.play_source(source, self._player)
@log_command_error("set shuffle") @log_command_error("set shuffle")
async def async_set_shuffle(self, shuffle): async def async_set_shuffle(self, shuffle: bool) -> None:
"""Enable/disable shuffle mode.""" """Enable/disable shuffle mode."""
await self._player.set_play_mode(self._player.repeat, shuffle) await self._player.set_play_mode(self._player.repeat, shuffle)
@log_command_error("set volume level") @log_command_error("set volume level")
async def async_set_volume_level(self, volume): async def async_set_volume_level(self, volume: float) -> None:
"""Set volume level, range 0..1.""" """Set volume level, range 0..1."""
await self._player.set_volume(int(volume * 100)) await self._player.set_volume(int(volume * 100))
async def async_update(self): async def async_update(self) -> None:
"""Update supported features of the player.""" """Update supported features of the player."""
controls = self._player.now_playing_media.supported_controls controls = self._player.now_playing_media.supported_controls
current_support = [CONTROL_TO_SUPPORT[control] for control in controls] current_support = [CONTROL_TO_SUPPORT[control] for control in controls]
@ -291,11 +294,11 @@ class HeosMediaPlayer(MediaPlayerEntity):
self._source_manager = self.hass.data[HEOS_DOMAIN][DATA_SOURCE_MANAGER] self._source_manager = self.hass.data[HEOS_DOMAIN][DATA_SOURCE_MANAGER]
@log_command_error("unjoin_player") @log_command_error("unjoin_player")
async def async_unjoin_player(self): async def async_unjoin_player(self) -> None:
"""Remove this player from any group.""" """Remove this player from any group."""
await self._group_manager.async_unjoin_player(self.entity_id) await self._group_manager.async_unjoin_player(self.entity_id)
async def async_will_remove_from_hass(self): async def async_will_remove_from_hass(self) -> None:
"""Disconnect the device when removed.""" """Disconnect the device when removed."""
for signal_remove in self._signals: for signal_remove in self._signals:
signal_remove() signal_remove()
@ -318,7 +321,7 @@ class HeosMediaPlayer(MediaPlayerEntity):
) )
@property @property
def extra_state_attributes(self) -> dict: def extra_state_attributes(self) -> dict[str, Any]:
"""Get additional attribute about the state.""" """Get additional attribute about the state."""
return { return {
"media_album_id": self._player.now_playing_media.album_id, "media_album_id": self._player.now_playing_media.album_id,
@ -434,7 +437,9 @@ class HeosMediaPlayer(MediaPlayerEntity):
"""Volume level of the media player (0..1).""" """Volume level of the media player (0..1)."""
return self._player.volume / 100 return self._player.volume / 100
async def async_browse_media(self, media_content_type=None, media_content_id=None): async def async_browse_media(
self, media_content_type: str | None = None, media_content_id: str | None = None
) -> BrowseMedia:
"""Implement the websocket media browsing helper.""" """Implement the websocket media browsing helper."""
return await media_source.async_browse_media( return await media_source.async_browse_media(
self.hass, self.hass,

View File

@ -2,6 +2,7 @@
from __future__ import annotations from __future__ import annotations
import logging import logging
from typing import Any
import hikvision.api import hikvision.api
from hikvision.error import HikvisionError, MissingParamError from hikvision.error import HikvisionError, MissingParamError
@ -88,17 +89,17 @@ class HikvisionMotionSwitch(SwitchEntity):
"""Return true if device is on.""" """Return true if device is on."""
return self._state == STATE_ON return self._state == STATE_ON
def turn_on(self, **kwargs): def turn_on(self, **kwargs: Any) -> None:
"""Turn the device on.""" """Turn the device on."""
_LOGGING.info("Turning on Motion Detection ") _LOGGING.info("Turning on Motion Detection ")
self._hikvision_cam.enable_motion_detection() self._hikvision_cam.enable_motion_detection()
def turn_off(self, **kwargs): def turn_off(self, **kwargs: Any) -> None:
"""Turn the device off.""" """Turn the device off."""
_LOGGING.info("Turning off Motion Detection ") _LOGGING.info("Turning off Motion Detection ")
self._hikvision_cam.disable_motion_detection() self._hikvision_cam.disable_motion_detection()
def update(self): def update(self) -> None:
"""Update Motion Detection state.""" """Update Motion Detection state."""
enabled = self._hikvision_cam.is_motion_detection_enabled() enabled = self._hikvision_cam.is_motion_detection_enabled()
_LOGGING.info("enabled: %s", enabled) _LOGGING.info("enabled: %s", enabled)

View File

@ -2,6 +2,7 @@
from __future__ import annotations from __future__ import annotations
import logging import logging
from typing import Any
from pyaehw4a1.aehw4a1 import AehW4a1 from pyaehw4a1.aehw4a1 import AehW4a1
import pyaehw4a1.exceptions import pyaehw4a1.exceptions
@ -168,7 +169,7 @@ class ClimateAehW4a1(ClimateEntity):
self._preset_mode = None self._preset_mode = None
self._previous_state = None self._previous_state = None
async def async_update(self): async def async_update(self) -> None:
"""Pull state from AEH-W4A1.""" """Pull state from AEH-W4A1."""
try: try:
status = await self._device.command("status_102_0") status = await self._device.command("status_102_0")
@ -300,7 +301,7 @@ class ClimateAehW4a1(ClimateEntity):
"""Return the supported step of target temperature.""" """Return the supported step of target temperature."""
return 1 return 1
async def async_set_temperature(self, **kwargs): async def async_set_temperature(self, **kwargs: Any) -> None:
"""Set new target temperatures.""" """Set new target temperatures."""
if self._on != "1": if self._on != "1":
_LOGGER.warning( _LOGGER.warning(
@ -316,7 +317,7 @@ class ClimateAehW4a1(ClimateEntity):
else: else:
await self._device.command(f"temp_{int(temp)}_F") await self._device.command(f"temp_{int(temp)}_F")
async def async_set_fan_mode(self, fan_mode): async def async_set_fan_mode(self, fan_mode: str) -> None:
"""Set new fan mode.""" """Set new fan mode."""
if self._on != "1": if self._on != "1":
_LOGGER.warning("AC at %s is off, could not set fan mode", self._unique_id) _LOGGER.warning("AC at %s is off, could not set fan mode", self._unique_id)
@ -327,7 +328,7 @@ class ClimateAehW4a1(ClimateEntity):
_LOGGER.debug("Setting fan mode of %s to %s", self._unique_id, fan_mode) _LOGGER.debug("Setting fan mode of %s to %s", self._unique_id, fan_mode)
await self._device.command(HA_FAN_MODES_TO_AC[fan_mode]) await self._device.command(HA_FAN_MODES_TO_AC[fan_mode])
async def async_set_swing_mode(self, swing_mode): async def async_set_swing_mode(self, swing_mode: str) -> None:
"""Set new target swing operation.""" """Set new target swing operation."""
if self._on != "1": if self._on != "1":
_LOGGER.warning( _LOGGER.warning(
@ -362,7 +363,7 @@ class ClimateAehW4a1(ClimateEntity):
if swing_act in (SWING_OFF, SWING_VERTICAL): if swing_act in (SWING_OFF, SWING_VERTICAL):
await self._device.command("hor_swing") await self._device.command("hor_swing")
async def async_set_preset_mode(self, preset_mode): async def async_set_preset_mode(self, preset_mode: str) -> None:
"""Set new preset mode.""" """Set new preset mode."""
if self._on != "1": if self._on != "1":
if preset_mode == PRESET_NONE: if preset_mode == PRESET_NONE:
@ -408,12 +409,12 @@ class ClimateAehW4a1(ClimateEntity):
if self._on != "1": if self._on != "1":
await self.async_turn_on() await self.async_turn_on()
async def async_turn_on(self): async def async_turn_on(self) -> None:
"""Turn on.""" """Turn on."""
_LOGGER.debug("Turning %s on", self._unique_id) _LOGGER.debug("Turning %s on", self._unique_id)
await self._device.command("on") await self._device.command("on")
async def async_turn_off(self): async def async_turn_off(self) -> None:
"""Turn off.""" """Turn off."""
_LOGGER.debug("Turning %s off", self._unique_id) _LOGGER.debug("Turning %s off", self._unique_id)
await self._device.command("off") await self._device.command("off")

View File

@ -65,7 +65,7 @@ class HiveAlarmControlPanelEntity(HiveEntity, AlarmControlPanelEntity):
"""Send arm away command.""" """Send arm away command."""
await self.hive.alarm.setMode(self.device, "away") await self.hive.alarm.setMode(self.device, "away")
async def async_alarm_trigger(self, code=None) -> None: async def async_alarm_trigger(self, code: str | None = None) -> None:
"""Send alarm trigger command.""" """Send alarm trigger command."""
await self.hive.alarm.setMode(self.device, "sos") await self.hive.alarm.setMode(self.device, "sos")

View File

@ -68,7 +68,7 @@ class HiveBinarySensorEntity(HiveEntity, BinarySensorEntity):
super().__init__(hive, hive_device) super().__init__(hive, hive_device)
self.entity_description = entity_description self.entity_description = entity_description
async def async_update(self): async def async_update(self) -> None:
"""Update all Node data from Hive.""" """Update all Node data from Hive."""
await self.hive.session.updateData(self.device) await self.hive.session.updateData(self.device)
self.device = await self.hive.sensor.getSensor(self.device) self.device = await self.hive.sensor.getSensor(self.device)

View File

@ -1,6 +1,7 @@
"""Support for the Hive climate devices.""" """Support for the Hive climate devices."""
from datetime import timedelta from datetime import timedelta
import logging import logging
from typing import Any
import voluptuous as vol import voluptuous as vol
@ -120,7 +121,7 @@ class HiveClimateEntity(HiveEntity, ClimateEntity):
await self.hive.heating.setMode(self.device, new_mode) await self.hive.heating.setMode(self.device, new_mode)
@refresh_system @refresh_system
async def async_set_temperature(self, **kwargs): async def async_set_temperature(self, **kwargs: Any) -> None:
"""Set new target temperature.""" """Set new target temperature."""
new_temperature = kwargs.get(ATTR_TEMPERATURE) new_temperature = kwargs.get(ATTR_TEMPERATURE)
if new_temperature is not None: if new_temperature is not None:
@ -153,7 +154,7 @@ class HiveClimateEntity(HiveEntity, ClimateEntity):
"""Handle boost heating service call.""" """Handle boost heating service call."""
await self.hive.heating.setBoostOff(self.device) await self.hive.heating.setBoostOff(self.device)
async def async_update(self): async def async_update(self) -> None:
"""Update all Node data from Hive.""" """Update all Node data from Hive."""
await self.hive.session.updateData(self.device) await self.hive.session.updateData(self.device)
self.device = await self.hive.heating.getClimate(self.device) self.device = await self.hive.heating.getClimate(self.device)

View File

@ -59,7 +59,7 @@ class HiveSensorEntity(HiveEntity, SensorEntity):
super().__init__(hive, hive_device) super().__init__(hive, hive_device)
self.entity_description = entity_description self.entity_description = entity_description
async def async_update(self): async def async_update(self) -> None:
"""Update all Node data from Hive.""" """Update all Node data from Hive."""
await self.hive.session.updateData(self.device) await self.hive.session.updateData(self.device)
self.device = await self.hive.sensor.getSensor(self.device) self.device = await self.hive.sensor.getSensor(self.device)

View File

@ -2,6 +2,7 @@
from __future__ import annotations from __future__ import annotations
from datetime import timedelta from datetime import timedelta
from typing import Any
from homeassistant.components.switch import SwitchEntity, SwitchEntityDescription from homeassistant.components.switch import SwitchEntity, SwitchEntityDescription
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
@ -52,16 +53,16 @@ class HiveSwitch(HiveEntity, SwitchEntity):
self.entity_description = entity_description self.entity_description = entity_description
@refresh_system @refresh_system
async def async_turn_on(self, **kwargs): async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn the switch on.""" """Turn the switch on."""
await self.hive.switch.turnOn(self.device) await self.hive.switch.turnOn(self.device)
@refresh_system @refresh_system
async def async_turn_off(self, **kwargs): async def async_turn_off(self, **kwargs: Any) -> None:
"""Turn the device off.""" """Turn the device off."""
await self.hive.switch.turnOff(self.device) await self.hive.switch.turnOff(self.device)
async def async_update(self): async def async_update(self) -> None:
"""Update all Node data from Hive.""" """Update all Node data from Hive."""
await self.hive.session.updateData(self.device) await self.hive.session.updateData(self.device)
self.device = await self.hive.switch.getSwitch(self.device) self.device = await self.hive.switch.getSwitch(self.device)

View File

@ -88,7 +88,7 @@ class HiveWaterHeater(HiveEntity, WaterHeaterEntity):
await self.hive.hotwater.setMode(self.device, "OFF") await self.hive.hotwater.setMode(self.device, "OFF")
@refresh_system @refresh_system
async def async_set_operation_mode(self, operation_mode): async def async_set_operation_mode(self, operation_mode: str) -> None:
"""Set operation mode.""" """Set operation mode."""
new_mode = HASS_TO_HIVE_STATE[operation_mode] new_mode = HASS_TO_HIVE_STATE[operation_mode]
await self.hive.hotwater.setMode(self.device, new_mode) await self.hive.hotwater.setMode(self.device, new_mode)
@ -101,7 +101,7 @@ class HiveWaterHeater(HiveEntity, WaterHeaterEntity):
elif on_off == "off": elif on_off == "off":
await self.hive.hotwater.setBoostOff(self.device) await self.hive.hotwater.setBoostOff(self.device)
async def async_update(self): async def async_update(self) -> None:
"""Update all Node data from Hive.""" """Update all Node data from Hive."""
await self.hive.session.updateData(self.device) await self.hive.session.updateData(self.device)
self.device = await self.hive.hotwater.getWaterHeater(self.device) self.device = await self.hive.hotwater.getWaterHeater(self.device)

View File

@ -1,4 +1,6 @@
"""Support for HLK-SW16 switches.""" """Support for HLK-SW16 switches."""
from typing import Any
from homeassistant.components.switch import SwitchEntity from homeassistant.components.switch import SwitchEntity
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
@ -36,10 +38,10 @@ class SW16Switch(SW16Device, SwitchEntity):
"""Return true if device is on.""" """Return true if device is on."""
return self._is_on return self._is_on
async def async_turn_on(self, **kwargs): async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn the device on.""" """Turn the device on."""
await self._client.turn_on(self._device_port) await self._client.turn_on(self._device_port)
async def async_turn_off(self, **kwargs): async def async_turn_off(self, **kwargs: Any) -> None:
"""Turn the device off.""" """Turn the device off."""
await self._client.turn_off(self._device_port) await self._client.turn_off(self._device_port)

View File

@ -72,7 +72,7 @@ class HomeConnectBinarySensor(HomeConnectEntity, BinarySensorEntity):
"""Return true if the binary sensor is available.""" """Return true if the binary sensor is available."""
return self._state is not None return self._state is not None
async def async_update(self): async def async_update(self) -> None:
"""Update the binary sensor's status.""" """Update the binary sensor's status."""
state = self.device.appliance.status.get(self._update_key, {}) state = self.device.appliance.status.get(self._update_key, {})
if not state: if not state:

View File

@ -1,6 +1,7 @@
"""Provides a light for Home Connect.""" """Provides a light for Home Connect."""
import logging import logging
from math import ceil from math import ceil
from typing import Any
from homeconnect.api import HomeConnectError from homeconnect.api import HomeConnectError
@ -153,7 +154,7 @@ class HomeConnectLight(HomeConnectEntity, LightEntity):
self.async_entity_update() self.async_entity_update()
async def async_turn_off(self, **kwargs): async def async_turn_off(self, **kwargs: Any) -> None:
"""Switch the light off.""" """Switch the light off."""
_LOGGER.debug("Switching light off for: %s", self.name) _LOGGER.debug("Switching light off for: %s", self.name)
try: try:

View File

@ -57,7 +57,7 @@ class HomeConnectSensor(HomeConnectEntity, SensorEntity):
"""Return true if the sensor is available.""" """Return true if the sensor is available."""
return self._state is not None return self._state is not None
async def async_update(self): async def async_update(self) -> None:
"""Update the sensor's status.""" """Update the sensor's status."""
status = self.device.appliance.status status = self.device.appliance.status
if self._key not in status: if self._key not in status:

View File

@ -1,5 +1,6 @@
"""Provides a switch for Home Connect.""" """Provides a switch for Home Connect."""
import logging import logging
from typing import Any
from homeconnect.api import HomeConnectError from homeconnect.api import HomeConnectError
@ -64,7 +65,7 @@ class HomeConnectProgramSwitch(HomeConnectEntity, SwitchEntity):
"""Return true if the entity is available.""" """Return true if the entity is available."""
return True return True
async def async_turn_on(self, **kwargs): async def async_turn_on(self, **kwargs: Any) -> None:
"""Start the program.""" """Start the program."""
_LOGGER.debug("Tried to turn on program %s", self.program_name) _LOGGER.debug("Tried to turn on program %s", self.program_name)
try: try:
@ -75,7 +76,7 @@ class HomeConnectProgramSwitch(HomeConnectEntity, SwitchEntity):
_LOGGER.error("Error while trying to start program: %s", err) _LOGGER.error("Error while trying to start program: %s", err)
self.async_entity_update() self.async_entity_update()
async def async_turn_off(self, **kwargs): async def async_turn_off(self, **kwargs: Any) -> None:
"""Stop the program.""" """Stop the program."""
_LOGGER.debug("Tried to stop program %s", self.program_name) _LOGGER.debug("Tried to stop program %s", self.program_name)
try: try:
@ -84,7 +85,7 @@ class HomeConnectProgramSwitch(HomeConnectEntity, SwitchEntity):
_LOGGER.error("Error while trying to stop program: %s", err) _LOGGER.error("Error while trying to stop program: %s", err)
self.async_entity_update() self.async_entity_update()
async def async_update(self): async def async_update(self) -> None:
"""Update the switch's status.""" """Update the switch's status."""
state = self.device.appliance.status.get(BSH_ACTIVE_PROGRAM, {}) state = self.device.appliance.status.get(BSH_ACTIVE_PROGRAM, {})
if state.get(ATTR_VALUE) == self.program_name: if state.get(ATTR_VALUE) == self.program_name:
@ -107,7 +108,7 @@ class HomeConnectPowerSwitch(HomeConnectEntity, SwitchEntity):
"""Return true if the switch is on.""" """Return true if the switch is on."""
return bool(self._state) return bool(self._state)
async def async_turn_on(self, **kwargs): async def async_turn_on(self, **kwargs: Any) -> None:
"""Switch the device on.""" """Switch the device on."""
_LOGGER.debug("Tried to switch on %s", self.name) _LOGGER.debug("Tried to switch on %s", self.name)
try: try:
@ -119,7 +120,7 @@ class HomeConnectPowerSwitch(HomeConnectEntity, SwitchEntity):
self._state = False self._state = False
self.async_entity_update() self.async_entity_update()
async def async_turn_off(self, **kwargs): async def async_turn_off(self, **kwargs: Any) -> None:
"""Switch the device off.""" """Switch the device off."""
_LOGGER.debug("tried to switch off %s", self.name) _LOGGER.debug("tried to switch off %s", self.name)
try: try:
@ -133,7 +134,7 @@ class HomeConnectPowerSwitch(HomeConnectEntity, SwitchEntity):
self._state = True self._state = True
self.async_entity_update() self.async_entity_update()
async def async_update(self): async def async_update(self) -> None:
"""Update the switch's status.""" """Update the switch's status."""
if ( if (
self.device.appliance.status.get(BSH_POWER_STATE, {}).get(ATTR_VALUE) self.device.appliance.status.get(BSH_POWER_STATE, {}).get(ATTR_VALUE)

View File

@ -1,5 +1,6 @@
"""Legrand Home+ Control Switch Entity Module that uses the HomeAssistant DataUpdateCoordinator.""" """Legrand Home+ Control Switch Entity Module that uses the HomeAssistant DataUpdateCoordinator."""
from functools import partial from functools import partial
from typing import Any
from homeassistant.components.switch import SwitchDeviceClass, SwitchEntity from homeassistant.components.switch import SwitchDeviceClass, SwitchEntity
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
@ -118,14 +119,14 @@ class HomeControlSwitchEntity(CoordinatorEntity, SwitchEntity):
"""Return entity state.""" """Return entity state."""
return self.module.status == "on" return self.module.status == "on"
async def async_turn_on(self, **kwargs): async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn the light on.""" """Turn the light on."""
# Do the turning on. # Do the turning on.
await self.module.turn_on() await self.module.turn_on()
# Update the data # Update the data
await self.coordinator.async_request_refresh() await self.coordinator.async_request_refresh()
async def async_turn_off(self, **kwargs): async def async_turn_off(self, **kwargs: Any) -> None:
"""Turn the entity off.""" """Turn the entity off."""
await self.module.turn_off() await self.module.turn_off()
# Update the data # Update the data

View File

@ -1,6 +1,8 @@
"""Support for Homematic thermostats.""" """Support for Homematic thermostats."""
from __future__ import annotations from __future__ import annotations
from typing import Any
from homeassistant.components.climate import ClimateEntity from homeassistant.components.climate import ClimateEntity
from homeassistant.components.climate.const import ( from homeassistant.components.climate.const import (
PRESET_BOOST, PRESET_BOOST,
@ -131,7 +133,7 @@ class HMThermostat(HMDevice, ClimateEntity):
"""Return the target temperature.""" """Return the target temperature."""
return self._data.get(self._state) return self._data.get(self._state)
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 None: if (temperature := kwargs.get(ATTR_TEMPERATURE)) is None:
return None return None

View File

@ -1,6 +1,8 @@
"""Support for HomeMatic switches.""" """Support for HomeMatic switches."""
from __future__ import annotations from __future__ import annotations
from typing import Any
from homeassistant.components.switch import SwitchEntity from homeassistant.components.switch import SwitchEntity
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -50,11 +52,11 @@ class HMSwitch(HMDevice, SwitchEntity):
return None return None
def turn_on(self, **kwargs): def turn_on(self, **kwargs: Any) -> None:
"""Turn the switch on.""" """Turn the switch on."""
self._hmdevice.on(self._channel) self._hmdevice.on(self._channel)
def turn_off(self, **kwargs): def turn_off(self, **kwargs: Any) -> None:
"""Turn the switch off.""" """Turn the switch off."""
self._hmdevice.off(self._channel) self._hmdevice.off(self._channel)

View File

@ -194,7 +194,7 @@ class HomematicipHeatingGroup(HomematicipGenericEntity, ClimateEntity):
"""Return the maximum temperature.""" """Return the maximum temperature."""
return self._device.maxTemperature return self._device.maxTemperature
async def async_set_temperature(self, **kwargs) -> None: async def async_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

View File

@ -106,11 +106,11 @@ class HomematicipMultiSwitch(HomematicipGenericEntity, SwitchEntity):
"""Return true if switch is on.""" """Return true if switch is on."""
return self._device.functionalChannels[self._channel].on return self._device.functionalChannels[self._channel].on
async def async_turn_on(self, **kwargs) -> None: async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn the switch on.""" """Turn the switch on."""
await self._device.turn_on(self._channel) await self._device.turn_on(self._channel)
async def async_turn_off(self, **kwargs) -> None: async def async_turn_off(self, **kwargs: Any) -> None:
"""Turn the switch off.""" """Turn the switch off."""
await self._device.turn_off(self._channel) await self._device.turn_off(self._channel)
@ -155,11 +155,11 @@ class HomematicipGroupSwitch(HomematicipGenericEntity, SwitchEntity):
return state_attr return state_attr
async def async_turn_on(self, **kwargs) -> None: async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn the group on.""" """Turn the group on."""
await self._device.turn_on() await self._device.turn_on()
async def async_turn_off(self, **kwargs) -> None: async def async_turn_off(self, **kwargs: Any) -> None:
"""Turn the group off.""" """Turn the group off."""
await self._device.turn_off() await self._device.turn_off()

View File

@ -252,7 +252,7 @@ class HoneywellUSThermostat(ClimateEntity):
except somecomfort.SomeComfortError: except somecomfort.SomeComfortError:
_LOGGER.error("Temperature %.1f out of range", temperature) _LOGGER.error("Temperature %.1f out of range", temperature)
def set_temperature(self, **kwargs) -> None: def set_temperature(self, **kwargs: Any) -> None:
"""Set new target temperature.""" """Set new target temperature."""
if {HVACMode.COOL, HVACMode.HEAT} & set(self._hvac_mode_map): if {HVACMode.COOL, HVACMode.HEAT} & set(self._hvac_mode_map):
self._set_temperature(**kwargs) self._set_temperature(**kwargs)
@ -352,6 +352,6 @@ class HoneywellUSThermostat(ClimateEntity):
else: else:
self.set_hvac_mode(HVACMode.OFF) self.set_hvac_mode(HVACMode.OFF)
async def async_update(self): async def async_update(self) -> None:
"""Get the latest state from the service.""" """Get the latest state from the service."""
await self._data.async_update() await self._data.async_update()

View File

@ -3,6 +3,7 @@ from __future__ import annotations
from datetime import timedelta from datetime import timedelta
import logging import logging
from typing import Any
from horimote import Client, keys from horimote import Client, keys
from horimote.exceptions import AuthenticationError from horimote.exceptions import AuthenticationError
@ -105,7 +106,7 @@ class HorizonDevice(MediaPlayerEntity):
return self._state return self._state
@util.Throttle(MIN_TIME_BETWEEN_SCANS, MIN_TIME_BETWEEN_FORCED_SCANS) @util.Throttle(MIN_TIME_BETWEEN_SCANS, MIN_TIME_BETWEEN_FORCED_SCANS)
def update(self): def update(self) -> None:
"""Update State using the media server running on the Horizon.""" """Update State using the media server running on the Horizon."""
try: try:
if self._client.is_powered_on(): if self._client.is_powered_on():
@ -115,37 +116,37 @@ class HorizonDevice(MediaPlayerEntity):
except OSError: except OSError:
self._state = STATE_OFF self._state = STATE_OFF
def turn_on(self): def turn_on(self) -> None:
"""Turn the device on.""" """Turn the device on."""
if self._state == STATE_OFF: if self._state == STATE_OFF:
self._send_key(self._keys.POWER) self._send_key(self._keys.POWER)
def turn_off(self): def turn_off(self) -> None:
"""Turn the device off.""" """Turn the device off."""
if self._state != STATE_OFF: if self._state != STATE_OFF:
self._send_key(self._keys.POWER) self._send_key(self._keys.POWER)
def media_previous_track(self): def media_previous_track(self) -> None:
"""Channel down.""" """Channel down."""
self._send_key(self._keys.CHAN_DOWN) self._send_key(self._keys.CHAN_DOWN)
self._state = STATE_PLAYING self._state = STATE_PLAYING
def media_next_track(self): def media_next_track(self) -> None:
"""Channel up.""" """Channel up."""
self._send_key(self._keys.CHAN_UP) self._send_key(self._keys.CHAN_UP)
self._state = STATE_PLAYING self._state = STATE_PLAYING
def media_play(self): def media_play(self) -> None:
"""Send play command.""" """Send play command."""
self._send_key(self._keys.PAUSE) self._send_key(self._keys.PAUSE)
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_key(self._keys.PAUSE) self._send_key(self._keys.PAUSE)
self._state = STATE_PAUSED self._state = STATE_PAUSED
def media_play_pause(self): def media_play_pause(self) -> None:
"""Send play/pause command.""" """Send play/pause command."""
self._send_key(self._keys.PAUSE) self._send_key(self._keys.PAUSE)
if self._state == STATE_PAUSED: if self._state == STATE_PAUSED:
@ -153,7 +154,7 @@ class HorizonDevice(MediaPlayerEntity):
else: else:
self._state = STATE_PAUSED self._state = STATE_PAUSED
def play_media(self, media_type, media_id, **kwargs): def play_media(self, media_type: str, media_id: str, **kwargs: Any) -> None:
"""Play media / switch to channel.""" """Play media / switch to channel."""
if MEDIA_TYPE_CHANNEL == media_type: if MEDIA_TYPE_CHANNEL == media_type:
try: try:

View File

@ -157,7 +157,7 @@ class HpIloSensor(SensorEntity):
"""Return the device state attributes.""" """Return the device state attributes."""
return self._state_attributes return self._state_attributes
def update(self): def update(self) -> None:
"""Get the latest data from HP iLO and updates the states.""" """Get the latest data from HP iLO and updates the states."""
# Call the API for new data. Each sensor will re-trigger this # Call the API for new data. Each sensor will re-trigger this
# same exact call, but that's fine. Results should be cached for # same exact call, but that's fine. Results should be cached for

View File

@ -69,20 +69,20 @@ class PowerViewShadeBatterySensor(ShadeEntity, SensorEntity):
return f"{self._shade_name} Battery" return f"{self._shade_name} Battery"
@property @property
def native_value(self): def native_value(self) -> int:
"""Get the current value in percentage.""" """Get the current value in percentage."""
return round( return round(
self._shade.raw_data[SHADE_BATTERY_LEVEL] / SHADE_BATTERY_LEVEL_MAX * 100 self._shade.raw_data[SHADE_BATTERY_LEVEL] / SHADE_BATTERY_LEVEL_MAX * 100
) )
async def async_added_to_hass(self): async def async_added_to_hass(self) -> None:
"""When entity is added to hass.""" """When entity is added to hass."""
self.async_on_remove( self.async_on_remove(
self.coordinator.async_add_listener(self._async_update_shade_from_group) self.coordinator.async_add_listener(self._async_update_shade_from_group)
) )
@callback @callback
def _async_update_shade_from_group(self): def _async_update_shade_from_group(self) -> None:
"""Update with new data from the coordinator.""" """Update with new data from the coordinator."""
self._shade.raw_data = self.data.get_raw_data(self._shade.id) self._shade.raw_data = self.data.get_raw_data(self._shade.id)
self.async_write_ha_state() self.async_write_ha_state()

View File

@ -1,6 +1,9 @@
"""Binary sensor platform for hvv_departures.""" """Binary sensor platform for hvv_departures."""
from __future__ import annotations
from datetime import timedelta from datetime import timedelta
import logging import logging
from typing import Any
from aiohttp import ClientConnectorError from aiohttp import ClientConnectorError
import async_timeout import async_timeout
@ -136,7 +139,7 @@ class HvvDepartureBinarySensor(CoordinatorEntity, BinarySensorEntity):
return self.coordinator.data[self.idx]["state"] return self.coordinator.data[self.idx]["state"]
@property @property
def available(self): def available(self) -> bool:
"""Return if entity is available.""" """Return if entity is available."""
return ( return (
self.coordinator.last_update_success self.coordinator.last_update_success
@ -175,7 +178,7 @@ class HvvDepartureBinarySensor(CoordinatorEntity, BinarySensorEntity):
return BinarySensorDeviceClass.PROBLEM return BinarySensorDeviceClass.PROBLEM
@property @property
def extra_state_attributes(self): def extra_state_attributes(self) -> dict[str, Any] | None:
"""Return the state attributes.""" """Return the state attributes."""
if not ( if not (
self.coordinator.last_update_success self.coordinator.last_update_success
@ -188,13 +191,13 @@ class HvvDepartureBinarySensor(CoordinatorEntity, BinarySensorEntity):
if v is not None if v is not None
} }
async def async_added_to_hass(self): async def async_added_to_hass(self) -> None:
"""When entity is added to hass.""" """When entity is added to hass."""
self.async_on_remove( self.async_on_remove(
self.coordinator.async_add_listener(self.async_write_ha_state) self.coordinator.async_add_listener(self.async_write_ha_state)
) )
async def async_update(self): async def async_update(self) -> None:
"""Update the entity. """Update the entity.
Only used by the generic entity update service. Only used by the generic entity update service.

View File

@ -1,6 +1,7 @@
"""Sensor platform for hvv.""" """Sensor platform for hvv."""
from datetime import timedelta from datetime import timedelta
import logging import logging
from typing import Any
from aiohttp import ClientConnectorError from aiohttp import ClientConnectorError
from pygti.exceptions import InvalidAuth from pygti.exceptions import InvalidAuth
@ -66,7 +67,7 @@ class HVVDepartureSensor(SensorEntity):
self.gti = hub.gti self.gti = hub.gti
@Throttle(MIN_TIME_BETWEEN_UPDATES) @Throttle(MIN_TIME_BETWEEN_UPDATES)
async def async_update(self, **kwargs): async def async_update(self, **kwargs: Any) -> None:
"""Update the sensor.""" """Update the sensor."""
departure_time = utcnow() + timedelta( departure_time = utcnow() + timedelta(
minutes=self.config_entry.options.get("offset", 0) minutes=self.config_entry.options.get("offset", 0)

View File

@ -80,7 +80,7 @@ def setup_platform(
class HydrawiseBinarySensor(HydrawiseEntity, BinarySensorEntity): class HydrawiseBinarySensor(HydrawiseEntity, BinarySensorEntity):
"""A sensor implementation for Hydrawise device.""" """A sensor implementation for Hydrawise device."""
def update(self): def update(self) -> None:
"""Get the latest data and updates the state.""" """Get the latest data and updates the state."""
_LOGGER.debug("Updating Hydrawise binary sensor: %s", self.name) _LOGGER.debug("Updating Hydrawise binary sensor: %s", self.name)
mydata = self.hass.data[DATA_HYDRAWISE].data mydata = self.hass.data[DATA_HYDRAWISE].data

View File

@ -73,7 +73,7 @@ def setup_platform(
class HydrawiseSensor(HydrawiseEntity, SensorEntity): class HydrawiseSensor(HydrawiseEntity, SensorEntity):
"""A sensor implementation for Hydrawise device.""" """A sensor implementation for Hydrawise device."""
def update(self): def update(self) -> None:
"""Get the latest data and updates the states.""" """Get the latest data and updates the states."""
mydata = self.hass.data[DATA_HYDRAWISE].data mydata = self.hass.data[DATA_HYDRAWISE].data
_LOGGER.debug("Updating Hydrawise sensor: %s", self.name) _LOGGER.debug("Updating Hydrawise sensor: %s", self.name)

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
@ -85,7 +86,7 @@ class HydrawiseSwitch(HydrawiseEntity, SwitchEntity):
super().__init__(data, description) super().__init__(data, description)
self._default_watering_timer = default_watering_timer self._default_watering_timer = default_watering_timer
def turn_on(self, **kwargs): def turn_on(self, **kwargs: Any) -> None:
"""Turn the device on.""" """Turn the device on."""
relay_data = self.data["relay"] - 1 relay_data = self.data["relay"] - 1
if self.entity_description.key == "manual_watering": if self.entity_description.key == "manual_watering":
@ -95,7 +96,7 @@ class HydrawiseSwitch(HydrawiseEntity, SwitchEntity):
elif self.entity_description.key == "auto_watering": elif self.entity_description.key == "auto_watering":
self.hass.data[DATA_HYDRAWISE].data.suspend_zone(0, relay_data) self.hass.data[DATA_HYDRAWISE].data.suspend_zone(0, relay_data)
def turn_off(self, **kwargs): def turn_off(self, **kwargs: Any) -> None:
"""Turn the device off.""" """Turn the device off."""
relay_data = self.data["relay"] - 1 relay_data = self.data["relay"] - 1
if self.entity_description.key == "manual_watering": if self.entity_description.key == "manual_watering":
@ -103,7 +104,7 @@ class HydrawiseSwitch(HydrawiseEntity, SwitchEntity):
elif self.entity_description.key == "auto_watering": elif self.entity_description.key == "auto_watering":
self.hass.data[DATA_HYDRAWISE].data.suspend_zone(365, relay_data) self.hass.data[DATA_HYDRAWISE].data.suspend_zone(365, relay_data)
def update(self): def update(self) -> None:
"""Update device state.""" """Update device state."""
relay_data = self.data["relay"] - 1 relay_data = self.data["relay"] - 1
mydata = self.hass.data[DATA_HYDRAWISE].data mydata = self.hass.data[DATA_HYDRAWISE].data