From a6b6949793e2571bf46cdca2e541ddf64cb1fc71 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Tue, 6 Sep 2022 13:59:37 +0200 Subject: [PATCH] Improve entity type hints [w] (#77886) --- homeassistant/components/w800rf32/binary_sensor.py | 2 +- homeassistant/components/wake_on_lan/switch.py | 7 ++++--- homeassistant/components/waqi/sensor.py | 2 +- homeassistant/components/waterfurnace/sensor.py | 2 +- .../components/waze_travel_time/sensor.py | 2 +- .../components/wirelesstag/binary_sensor.py | 2 +- homeassistant/components/wirelesstag/sensor.py | 2 +- homeassistant/components/wirelesstag/switch.py | 6 ++++-- homeassistant/components/worldtidesinfo/sensor.py | 2 +- homeassistant/components/worxlandroid/sensor.py | 2 +- homeassistant/components/ws66i/media_player.py | 14 +++++++------- homeassistant/components/wsdot/sensor.py | 2 +- 12 files changed, 24 insertions(+), 21 deletions(-) diff --git a/homeassistant/components/w800rf32/binary_sensor.py b/homeassistant/components/w800rf32/binary_sensor.py index 2473d193197..ef8e02803f6 100644 --- a/homeassistant/components/w800rf32/binary_sensor.py +++ b/homeassistant/components/w800rf32/binary_sensor.py @@ -138,6 +138,6 @@ class W800rf32BinarySensor(BinarySensorEntity): self._state = state self.async_write_ha_state() - async def async_added_to_hass(self): + async def async_added_to_hass(self) -> None: """Register update callback.""" async_dispatcher_connect(self.hass, self._signal, self.binary_sensor_update) diff --git a/homeassistant/components/wake_on_lan/switch.py b/homeassistant/components/wake_on_lan/switch.py index 2f019ca6158..1b3904f63e6 100644 --- a/homeassistant/components/wake_on_lan/switch.py +++ b/homeassistant/components/wake_on_lan/switch.py @@ -3,6 +3,7 @@ from __future__ import annotations import logging import subprocess as sp +from typing import Any import voluptuous as vol import wakeonlan @@ -125,7 +126,7 @@ class WolSwitch(SwitchEntity): """Return the unique id of this switch.""" return self._unique_id - def turn_on(self, **kwargs): + def turn_on(self, **kwargs: Any) -> None: """Turn the device on.""" service_kwargs = {} if self._broadcast_address is not None: @@ -146,7 +147,7 @@ class WolSwitch(SwitchEntity): self._state = True self.async_write_ha_state() - def turn_off(self, **kwargs): + def turn_off(self, **kwargs: Any) -> None: """Turn the device off if an off action is present.""" if self._off_script is not None: self._off_script.run(context=self._context) @@ -155,7 +156,7 @@ class WolSwitch(SwitchEntity): self._state = False self.async_write_ha_state() - def update(self): + def update(self) -> None: """Check if device is on and update the state. Only called if assumed state is false.""" ping_cmd = [ "ping", diff --git a/homeassistant/components/waqi/sensor.py b/homeassistant/components/waqi/sensor.py index 499233717b6..c9cc527387a 100644 --- a/homeassistant/components/waqi/sensor.py +++ b/homeassistant/components/waqi/sensor.py @@ -183,7 +183,7 @@ class WaqiSensor(SensorEntity): except (IndexError, KeyError): return {ATTR_ATTRIBUTION: ATTRIBUTION} - async def async_update(self): + async def async_update(self) -> None: """Get the latest data and updates the states.""" if self.uid: result = await self._client.get_station_by_number(self.uid) diff --git a/homeassistant/components/waterfurnace/sensor.py b/homeassistant/components/waterfurnace/sensor.py index c6ef9610bca..454e73f5f7a 100644 --- a/homeassistant/components/waterfurnace/sensor.py +++ b/homeassistant/components/waterfurnace/sensor.py @@ -133,7 +133,7 @@ class WaterFurnaceSensor(SensorEntity): """Return the units of measurement.""" return self._unit_of_measurement - async def async_added_to_hass(self): + async def async_added_to_hass(self) -> None: """Register callbacks.""" self.async_on_remove( async_dispatcher_connect( diff --git a/homeassistant/components/waze_travel_time/sensor.py b/homeassistant/components/waze_travel_time/sensor.py index 3471099b588..4992fc07db5 100644 --- a/homeassistant/components/waze_travel_time/sensor.py +++ b/homeassistant/components/waze_travel_time/sensor.py @@ -161,7 +161,7 @@ class WazeTravelTime(SensorEntity): await self.hass.async_add_executor_job(self.update) self.async_write_ha_state() - def update(self): + def update(self) -> None: """Fetch new state data for the sensor.""" _LOGGER.debug("Fetching Route for %s", self._attr_name) self._waze_data.origin = find_coordinates(self.hass, self._origin) diff --git a/homeassistant/components/wirelesstag/binary_sensor.py b/homeassistant/components/wirelesstag/binary_sensor.py index dde1a22f622..82c3a25590a 100644 --- a/homeassistant/components/wirelesstag/binary_sensor.py +++ b/homeassistant/components/wirelesstag/binary_sensor.py @@ -101,7 +101,7 @@ class WirelessTagBinarySensor(WirelessTagBaseSensor, BinarySensorEntity): self._sensor_type = sensor_type self._name = f"{self._tag.name} {self.event.human_readable_name}" - async def async_added_to_hass(self): + async def async_added_to_hass(self) -> None: """Register callbacks.""" tag_id = self.tag_id event_type = self.device_class diff --git a/homeassistant/components/wirelesstag/sensor.py b/homeassistant/components/wirelesstag/sensor.py index 9cec276f26a..fb54c90cc1f 100644 --- a/homeassistant/components/wirelesstag/sensor.py +++ b/homeassistant/components/wirelesstag/sensor.py @@ -109,7 +109,7 @@ class WirelessTagSensor(WirelessTagBaseSensor, SensorEntity): f"sensor.{WIRELESSTAG_DOMAIN}_{self.underscored_name}_{self._sensor_type}" ) - async def async_added_to_hass(self): + async def async_added_to_hass(self) -> None: """Register callbacks.""" self.async_on_remove( async_dispatcher_connect( diff --git a/homeassistant/components/wirelesstag/switch.py b/homeassistant/components/wirelesstag/switch.py index a6e4a85559c..9829cffd2b5 100644 --- a/homeassistant/components/wirelesstag/switch.py +++ b/homeassistant/components/wirelesstag/switch.py @@ -1,6 +1,8 @@ """Switch implementation for Wireless Sensor Tags (wirelesstag.net).""" from __future__ import annotations +from typing import Any + import voluptuous as vol from homeassistant.components.switch import ( @@ -81,11 +83,11 @@ class WirelessTagSwitch(WirelessTagBaseSensor, SwitchEntity): self.entity_description = description self._name = f"{self._tag.name} {description.name}" - def turn_on(self, **kwargs): + def turn_on(self, **kwargs: Any) -> None: """Turn on the switch.""" self._api.arm(self) - def turn_off(self, **kwargs): + def turn_off(self, **kwargs: Any) -> None: """Turn on the switch.""" self._api.disarm(self) diff --git a/homeassistant/components/worldtidesinfo/sensor.py b/homeassistant/components/worldtidesinfo/sensor.py index 2433a9f678e..776f6c6e20f 100644 --- a/homeassistant/components/worldtidesinfo/sensor.py +++ b/homeassistant/components/worldtidesinfo/sensor.py @@ -110,7 +110,7 @@ class WorldTidesInfoSensor(SensorEntity): return None return None - def update(self): + def update(self) -> None: """Get the latest data from WorldTidesInfo API.""" start = int(time.time()) resource = ( diff --git a/homeassistant/components/worxlandroid/sensor.py b/homeassistant/components/worxlandroid/sensor.py index 47617dc609e..d15a33e9e17 100644 --- a/homeassistant/components/worxlandroid/sensor.py +++ b/homeassistant/components/worxlandroid/sensor.py @@ -89,7 +89,7 @@ class WorxLandroidSensor(SensorEntity): return PERCENTAGE return None - async def async_update(self): + async def async_update(self) -> None: """Update the sensor data from the mower.""" connection_error = False diff --git a/homeassistant/components/ws66i/media_player.py b/homeassistant/components/ws66i/media_player.py index 7cd897e9c1a..05fd4133885 100644 --- a/homeassistant/components/ws66i/media_player.py +++ b/homeassistant/components/ws66i/media_player.py @@ -106,7 +106,7 @@ class Ws66iZone(CoordinatorEntity[Ws66iDataUpdateCoordinator], MediaPlayerEntity self._set_attrs_from_status() self.async_write_ha_state() - async def async_select_source(self, source): + async def async_select_source(self, source: str) -> None: """Set input source.""" idx = self._ws66i_data.sources.name_id[source] await self.hass.async_add_executor_job( @@ -115,7 +115,7 @@ class Ws66iZone(CoordinatorEntity[Ws66iDataUpdateCoordinator], MediaPlayerEntity self._status.source = idx self._async_update_attrs_write_ha_state() - async def async_turn_on(self): + async def async_turn_on(self) -> None: """Turn the media player on.""" await self.hass.async_add_executor_job( self._ws66i.set_power, self._zone_id, True @@ -123,7 +123,7 @@ class Ws66iZone(CoordinatorEntity[Ws66iDataUpdateCoordinator], MediaPlayerEntity self._status.power = True self._async_update_attrs_write_ha_state() - async def async_turn_off(self): + async def async_turn_off(self) -> None: """Turn the media player off.""" await self.hass.async_add_executor_job( self._ws66i.set_power, self._zone_id, False @@ -131,7 +131,7 @@ class Ws66iZone(CoordinatorEntity[Ws66iDataUpdateCoordinator], MediaPlayerEntity self._status.power = False self._async_update_attrs_write_ha_state() - async def async_mute_volume(self, mute): + async def async_mute_volume(self, mute: bool) -> None: """Mute (true) or unmute (false) media player.""" await self.hass.async_add_executor_job( self._ws66i.set_mute, self._zone_id, mute @@ -139,19 +139,19 @@ class Ws66iZone(CoordinatorEntity[Ws66iDataUpdateCoordinator], MediaPlayerEntity self._status.mute = bool(mute) self._async_update_attrs_write_ha_state() - async def async_set_volume_level(self, volume): + async def async_set_volume_level(self, volume: float) -> None: """Set volume level, range 0..1.""" await self.hass.async_add_executor_job(self._set_volume, int(volume * MAX_VOL)) self._async_update_attrs_write_ha_state() - async def async_volume_up(self): + async def async_volume_up(self) -> None: """Volume up the media player.""" await self.hass.async_add_executor_job( self._set_volume, min(self._status.volume + 1, MAX_VOL) ) self._async_update_attrs_write_ha_state() - async def async_volume_down(self): + async def async_volume_down(self) -> None: """Volume down media player.""" await self.hass.async_add_executor_job( self._set_volume, max(self._status.volume - 1, 0) diff --git a/homeassistant/components/wsdot/sensor.py b/homeassistant/components/wsdot/sensor.py index 76d1b92b476..b8c362e56a5 100644 --- a/homeassistant/components/wsdot/sensor.py +++ b/homeassistant/components/wsdot/sensor.py @@ -113,7 +113,7 @@ class WashingtonStateTravelTimeSensor(WashingtonStateTransportSensor): self._travel_time_id = travel_time_id WashingtonStateTransportSensor.__init__(self, name, access_code) - def update(self): + def update(self) -> None: """Get the latest data from WSDOT.""" params = { ATTR_ACCESS_CODE: self._access_code,