From d1ecd74a1a153b85b829acf45b5c6a5ea79df5c1 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Thu, 1 Sep 2022 14:14:31 +0200 Subject: [PATCH] Improve entity type hints [l] (#77655) --- .../components/landisgyr_heat_meter/sensor.py | 2 +- .../components/lg_netcast/media_player.py | 29 ++++++++++--------- .../components/lg_soundbar/media_player.py | 14 ++++----- homeassistant/components/lightwave/climate.py | 6 ++-- homeassistant/components/lightwave/sensor.py | 2 +- homeassistant/components/lightwave/switch.py | 6 ++-- .../components/linode/binary_sensor.py | 2 +- homeassistant/components/linode/switch.py | 7 +++-- .../components/linux_battery/sensor.py | 2 +- homeassistant/components/litejet/switch.py | 9 +++--- .../components/locative/device_tracker.py | 4 +-- .../components/logi_circle/camera.py | 10 +++---- .../components/logi_circle/sensor.py | 2 +- homeassistant/components/london_air/sensor.py | 2 +- homeassistant/components/lupusec/switch.py | 5 ++-- homeassistant/components/lutron/__init__.py | 4 +-- homeassistant/components/lutron/scene.py | 2 +- homeassistant/components/lutron/switch.py | 16 +++++----- .../components/lutron_caseta/binary_sensor.py | 2 +- .../components/lutron_caseta/switch.py | 8 +++-- 20 files changed, 73 insertions(+), 61 deletions(-) diff --git a/homeassistant/components/landisgyr_heat_meter/sensor.py b/homeassistant/components/landisgyr_heat_meter/sensor.py index 1d38b1f5816..23a6e217458 100644 --- a/homeassistant/components/landisgyr_heat_meter/sensor.py +++ b/homeassistant/components/landisgyr_heat_meter/sensor.py @@ -73,7 +73,7 @@ class HeatMeterSensor(CoordinatorEntity, RestoreSensor): self._attr_device_info = device self._attr_should_poll = bool(self.key in ("heat_usage", "heat_previous_year")) - async def async_added_to_hass(self): + async def async_added_to_hass(self) -> None: """Call when entity about to be added to hass.""" await super().async_added_to_hass() state = await self.async_get_last_sensor_data() diff --git a/homeassistant/components/lg_netcast/media_player.py b/homeassistant/components/lg_netcast/media_player.py index a36ac83d37c..19046316803 100644 --- a/homeassistant/components/lg_netcast/media_player.py +++ b/homeassistant/components/lg_netcast/media_player.py @@ -2,6 +2,7 @@ from __future__ import annotations from datetime import datetime +from typing import Any from pylgnetcast import LgNetCastClient, LgNetCastError from requests import RequestException @@ -106,7 +107,7 @@ class LgTVDevice(MediaPlayerEntity): except (LgNetCastError, RequestException): self._state = STATE_OFF - def update(self): + def update(self) -> None: """Retrieve the latest data from the LG TV.""" try: @@ -219,63 +220,63 @@ class LgTVDevice(MediaPlayerEntity): f"{self._client.url}data?target=screen_image&_={datetime.now().timestamp()}" ) - def turn_off(self): + def turn_off(self) -> None: """Turn off media player.""" self.send_command(1) - def turn_on(self): + def turn_on(self) -> None: """Turn on the media player.""" if self._on_action_script: self._on_action_script.run(context=self._context) - def volume_up(self): + def volume_up(self) -> None: """Volume up the media player.""" self.send_command(24) - def volume_down(self): + def volume_down(self) -> None: """Volume down media player.""" self.send_command(25) - def set_volume_level(self, volume): + def set_volume_level(self, volume: float) -> None: """Set volume level, range 0..1.""" self._client.set_volume(float(volume * 100)) - def mute_volume(self, mute): + def mute_volume(self, mute: bool) -> None: """Send mute command.""" self.send_command(26) - def select_source(self, source): + def select_source(self, source: str) -> None: """Select input source.""" self._client.change_channel(self._sources[source]) - def media_play_pause(self): + def media_play_pause(self) -> None: """Simulate play pause media player.""" if self._playing: self.media_pause() else: self.media_play() - def media_play(self): + def media_play(self) -> None: """Send play command.""" self._playing = True self._state = STATE_PLAYING self.send_command(33) - def media_pause(self): + def media_pause(self) -> None: """Send media pause command to media player.""" self._playing = False self._state = STATE_PAUSED self.send_command(34) - def media_next_track(self): + def media_next_track(self) -> None: """Send next track command.""" self.send_command(36) - def media_previous_track(self): + def media_previous_track(self) -> None: """Send the previous track command.""" self.send_command(37) - def play_media(self, media_type, media_id, **kwargs): + def play_media(self, media_type: str, media_id: str, **kwargs: Any) -> None: """Tune to channel.""" if media_type != MEDIA_TYPE_CHANNEL: raise ValueError(f"Invalid media type: {media_type}") diff --git a/homeassistant/components/lg_soundbar/media_player.py b/homeassistant/components/lg_soundbar/media_player.py index 941042d5bce..5ff5f63a544 100644 --- a/homeassistant/components/lg_soundbar/media_player.py +++ b/homeassistant/components/lg_soundbar/media_player.py @@ -65,11 +65,11 @@ class LGDevice(MediaPlayerEntity): self._treble = 0 self._device = None - async def async_added_to_hass(self): + async def async_added_to_hass(self) -> None: """Register the callback after hass is ready for it.""" await self.hass.async_add_executor_job(self._connect) - def _connect(self): + def _connect(self) -> None: """Perform the actual devices setup.""" self._device = temescal.temescal( self._host, port=self._port, callback=self.handle_event @@ -126,7 +126,7 @@ class LGDevice(MediaPlayerEntity): self.schedule_update_ha_state() - def update(self): + def update(self) -> None: """Trigger updates from the device.""" self._device.get_eq() self._device.get_info() @@ -182,19 +182,19 @@ class LGDevice(MediaPlayerEntity): sources.append(temescal.functions[function]) return sorted(sources) - def set_volume_level(self, volume): + def set_volume_level(self, volume: float) -> None: """Set volume level, range 0..1.""" volume = volume * self._volume_max self._device.set_volume(int(volume)) - def mute_volume(self, mute): + def mute_volume(self, mute: bool) -> None: """Mute (true) or unmute (false) media player.""" self._device.set_mute(mute) - def select_source(self, source): + def select_source(self, source: str) -> None: """Select input source.""" self._device.set_func(temescal.functions.index(source)) - def select_sound_mode(self, sound_mode): + def select_sound_mode(self, sound_mode: str) -> None: """Set Sound Mode for Receiver..""" self._device.set_eq(temescal.equalisers.index(sound_mode)) diff --git a/homeassistant/components/lightwave/climate.py b/homeassistant/components/lightwave/climate.py index 8076cbc058b..968d67bbcd2 100644 --- a/homeassistant/components/lightwave/climate.py +++ b/homeassistant/components/lightwave/climate.py @@ -1,6 +1,8 @@ """Support for LightwaveRF TRVs.""" from __future__ import annotations +from typing import Any + from homeassistant.components.climate import ( DEFAULT_MAX_TEMP, DEFAULT_MIN_TEMP, @@ -61,7 +63,7 @@ class LightwaveTrv(ClimateEntity): # inhibit is used to prevent race condition on update. If non zero, skip next update cycle. self._inhibit = 0 - def update(self): + def update(self) -> None: """Communicate with a Lightwave RTF Proxy to get state.""" (temp, targ, _, trv_output) = self._lwlink.read_trv_status(self._serial) if temp is not None: @@ -95,7 +97,7 @@ class LightwaveTrv(ClimateEntity): self._attr_target_temperature = self._inhibit return self._attr_target_temperature - def set_temperature(self, **kwargs): + def set_temperature(self, **kwargs: Any) -> None: """Set TRV target temperature.""" if ATTR_TEMPERATURE in kwargs: self._attr_target_temperature = kwargs[ATTR_TEMPERATURE] diff --git a/homeassistant/components/lightwave/sensor.py b/homeassistant/components/lightwave/sensor.py index 14ea3bb85a8..dac591aea34 100644 --- a/homeassistant/components/lightwave/sensor.py +++ b/homeassistant/components/lightwave/sensor.py @@ -50,7 +50,7 @@ class LightwaveBattery(SensorEntity): self._serial = serial self._attr_unique_id = f"{serial}-trv-battery" - def update(self): + def update(self) -> None: """Communicate with a Lightwave RTF Proxy to get state.""" (dummy_temp, dummy_targ, battery, dummy_output) = self._lwlink.read_trv_status( self._serial diff --git a/homeassistant/components/lightwave/switch.py b/homeassistant/components/lightwave/switch.py index 80cc80510a4..67b69d0e5c4 100644 --- a/homeassistant/components/lightwave/switch.py +++ b/homeassistant/components/lightwave/switch.py @@ -1,6 +1,8 @@ """Support for LightwaveRF switches.""" from __future__ import annotations +from typing import Any + from homeassistant.components.switch import SwitchEntity from homeassistant.const import CONF_NAME from homeassistant.core import HomeAssistant @@ -41,13 +43,13 @@ class LWRFSwitch(SwitchEntity): self._device_id = device_id self._lwlink = lwlink - async def async_turn_on(self, **kwargs): + async def async_turn_on(self, **kwargs: Any) -> None: """Turn the LightWave switch on.""" self._attr_is_on = True self._lwlink.turn_on_switch(self._device_id, self._attr_name) self.async_write_ha_state() - async def async_turn_off(self, **kwargs): + async def async_turn_off(self, **kwargs: Any) -> None: """Turn the LightWave switch off.""" self._attr_is_on = False self._lwlink.turn_off(self._device_id, self._attr_name) diff --git a/homeassistant/components/linode/binary_sensor.py b/homeassistant/components/linode/binary_sensor.py index 67ccde764e1..2c63bbc0bc8 100644 --- a/homeassistant/components/linode/binary_sensor.py +++ b/homeassistant/components/linode/binary_sensor.py @@ -68,7 +68,7 @@ class LinodeBinarySensor(BinarySensorEntity): self._attr_extra_state_attributes = {} self._attr_name = None - def update(self): + def update(self) -> None: """Update state of sensor.""" data = None self._linode.update() diff --git a/homeassistant/components/linode/switch.py b/homeassistant/components/linode/switch.py index 76cd95e5bca..183abbc068c 100644 --- a/homeassistant/components/linode/switch.py +++ b/homeassistant/components/linode/switch.py @@ -2,6 +2,7 @@ from __future__ import annotations import logging +from typing import Any import voluptuous as vol @@ -63,17 +64,17 @@ class LinodeSwitch(SwitchEntity): self.data = None self._attr_extra_state_attributes = {} - def turn_on(self, **kwargs): + def turn_on(self, **kwargs: Any) -> None: """Boot-up the Node.""" if self.data.status != "running": self.data.boot() - def turn_off(self, **kwargs): + def turn_off(self, **kwargs: Any) -> None: """Shutdown the nodes.""" if self.data.status == "running": self.data.shutdown() - def update(self): + def update(self) -> None: """Get the latest data from the device and update the data.""" self._linode.update() if self._linode.data is not None: diff --git a/homeassistant/components/linux_battery/sensor.py b/homeassistant/components/linux_battery/sensor.py index ec747778b7b..765e0d79537 100644 --- a/homeassistant/components/linux_battery/sensor.py +++ b/homeassistant/components/linux_battery/sensor.py @@ -124,7 +124,7 @@ class LinuxBatterySensor(SensorEntity): ATTR_VOLTAGE_NOW: self._battery_stat.voltage_now, } - def update(self): + def update(self) -> None: """Get the latest data and updates the states.""" self._battery.update() self._battery_stat = self._battery.stat[self._battery_id] diff --git a/homeassistant/components/litejet/switch.py b/homeassistant/components/litejet/switch.py index 66b68a345f2..375e3dd9f46 100644 --- a/homeassistant/components/litejet/switch.py +++ b/homeassistant/components/litejet/switch.py @@ -1,5 +1,6 @@ """Support for LiteJet switch.""" import logging +from typing import Any from homeassistant.components.switch import SwitchEntity from homeassistant.config_entries import ConfigEntry @@ -45,12 +46,12 @@ class LiteJetSwitch(SwitchEntity): self._state = False self._name = name - async def async_added_to_hass(self): + async def async_added_to_hass(self) -> None: """Run when this Entity has been added to HA.""" self._lj.on_switch_pressed(self._index, self._on_switch_pressed) self._lj.on_switch_released(self._index, self._on_switch_released) - async def async_will_remove_from_hass(self): + async def async_will_remove_from_hass(self) -> None: """Entity being removed from hass.""" self._lj.unsubscribe(self._on_switch_pressed) self._lj.unsubscribe(self._on_switch_released) @@ -85,11 +86,11 @@ class LiteJetSwitch(SwitchEntity): """Return the device-specific state attributes.""" return {ATTR_NUMBER: self._index} - def turn_on(self, **kwargs): + def turn_on(self, **kwargs: Any) -> None: """Press the switch.""" self._lj.press_switch(self._index) - def turn_off(self, **kwargs): + def turn_off(self, **kwargs: Any) -> None: """Release the switch.""" self._lj.release_switch(self._index) diff --git a/homeassistant/components/locative/device_tracker.py b/homeassistant/components/locative/device_tracker.py index cd927aace38..f8fa1671034 100644 --- a/homeassistant/components/locative/device_tracker.py +++ b/homeassistant/components/locative/device_tracker.py @@ -64,13 +64,13 @@ class LocativeEntity(TrackerEntity): """Return the source type, eg gps or router, of the device.""" return SourceType.GPS - async def async_added_to_hass(self): + async def async_added_to_hass(self) -> None: """Register state update callback.""" self._unsub_dispatcher = async_dispatcher_connect( self.hass, TRACKER_UPDATE, self._async_receive_data ) - async def async_will_remove_from_hass(self): + async def async_will_remove_from_hass(self) -> None: """Clean up after entity before removal.""" self._unsub_dispatcher() diff --git a/homeassistant/components/logi_circle/camera.py b/homeassistant/components/logi_circle/camera.py index 231de83a135..733e49ca0bf 100644 --- a/homeassistant/components/logi_circle/camera.py +++ b/homeassistant/components/logi_circle/camera.py @@ -75,7 +75,7 @@ class LogiCam(Camera): self._ffmpeg = ffmpeg self._listeners = [] - async def async_added_to_hass(self): + async def async_added_to_hass(self) -> None: """Connect camera methods to signals.""" def _dispatch_proxy(method): @@ -111,7 +111,7 @@ class LogiCam(Camera): ] ) - async def async_will_remove_from_hass(self): + async def async_will_remove_from_hass(self) -> None: """Disconnect dispatcher listeners when removed.""" for detach in self._listeners: detach() @@ -161,11 +161,11 @@ class LogiCam(Camera): """Return a still image from the camera.""" return await self._camera.live_stream.download_jpeg() - async def async_turn_off(self): + async def async_turn_off(self) -> None: """Disable streaming mode for this camera.""" await self._camera.set_config("streaming", False) - async def async_turn_on(self): + async def async_turn_on(self) -> None: """Enable streaming mode for this camera.""" await self._camera.set_config("streaming", True) @@ -210,6 +210,6 @@ class LogiCam(Camera): filename=snapshot_file, refresh=True ) - async def async_update(self): + async def async_update(self) -> None: """Update camera entity and refresh attributes.""" await self._camera.update() diff --git a/homeassistant/components/logi_circle/sensor.py b/homeassistant/components/logi_circle/sensor.py index da115f789da..baf6d933916 100644 --- a/homeassistant/components/logi_circle/sensor.py +++ b/homeassistant/components/logi_circle/sensor.py @@ -112,7 +112,7 @@ class LogiSensor(SensorEntity): ) return self.entity_description.icon - async def async_update(self): + async def async_update(self) -> None: """Get the latest data and updates the state.""" _LOGGER.debug("Pulling data from %s sensor", self.name) await self._camera.update() diff --git a/homeassistant/components/london_air/sensor.py b/homeassistant/components/london_air/sensor.py index 23bf3bb2e64..33fe1d4d7fb 100644 --- a/homeassistant/components/london_air/sensor.py +++ b/homeassistant/components/london_air/sensor.py @@ -141,7 +141,7 @@ class AirSensor(SensorEntity): attrs["data"] = self._site_data return attrs - def update(self): + def update(self) -> None: """Update the sensor.""" sites_status = [] self._api_data.update() diff --git a/homeassistant/components/lupusec/switch.py b/homeassistant/components/lupusec/switch.py index 4b5f38a81b3..546f96fd0a6 100644 --- a/homeassistant/components/lupusec/switch.py +++ b/homeassistant/components/lupusec/switch.py @@ -2,6 +2,7 @@ from __future__ import annotations from datetime import timedelta +from typing import Any import lupupy.constants as CONST @@ -39,11 +40,11 @@ def setup_platform( class LupusecSwitch(LupusecDevice, SwitchEntity): """Representation of a Lupusec switch.""" - def turn_on(self, **kwargs): + def turn_on(self, **kwargs: Any) -> None: """Turn on the device.""" self._device.switch_on() - def turn_off(self, **kwargs): + def turn_off(self, **kwargs: Any) -> None: """Turn off the device.""" self._device.switch_off() diff --git a/homeassistant/components/lutron/__init__.py b/homeassistant/components/lutron/__init__.py index 75561dd275b..d8ccce8a6bc 100644 --- a/homeassistant/components/lutron/__init__.py +++ b/homeassistant/components/lutron/__init__.py @@ -124,7 +124,7 @@ class LutronDevice(Entity): self._controller = controller self._area_name = area_name - async def async_added_to_hass(self): + async def async_added_to_hass(self) -> None: """Register callbacks.""" self._lutron_device.subscribe(self._update_callback, None) @@ -133,7 +133,7 @@ class LutronDevice(Entity): self.schedule_update_ha_state() @property - def name(self): + def name(self) -> str: """Return the name of the device.""" return f"{self._area_name} {self._lutron_device.name}" diff --git a/homeassistant/components/lutron/scene.py b/homeassistant/components/lutron/scene.py index 68d1a4805fc..f2d008a1187 100644 --- a/homeassistant/components/lutron/scene.py +++ b/homeassistant/components/lutron/scene.py @@ -43,6 +43,6 @@ class LutronScene(LutronDevice, Scene): self._lutron_device.press() @property - def name(self): + def name(self) -> str: """Return the name of the device.""" return f"{self._area_name} {self._keypad_name}: {self._lutron_device.name}" diff --git a/homeassistant/components/lutron/switch.py b/homeassistant/components/lutron/switch.py index 49d4181a8e0..8595f809035 100644 --- a/homeassistant/components/lutron/switch.py +++ b/homeassistant/components/lutron/switch.py @@ -1,6 +1,8 @@ """Support for Lutron switches.""" from __future__ import annotations +from typing import Any + from homeassistant.components.switch import SwitchEntity from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -43,11 +45,11 @@ class LutronSwitch(LutronDevice, SwitchEntity): self._prev_state = None super().__init__(area_name, lutron_device, controller) - def turn_on(self, **kwargs): + def turn_on(self, **kwargs: Any) -> None: """Turn the switch on.""" self._lutron_device.level = 100 - def turn_off(self, **kwargs): + def turn_off(self, **kwargs: Any) -> None: """Turn the switch off.""" self._lutron_device.level = 0 @@ -61,7 +63,7 @@ class LutronSwitch(LutronDevice, SwitchEntity): """Return true if device is on.""" return self._lutron_device.last_level() > 0 - def update(self): + def update(self) -> None: """Call when forcing a refresh of the device.""" if self._prev_state is None: self._prev_state = self._lutron_device.level > 0 @@ -76,11 +78,11 @@ class LutronLed(LutronDevice, SwitchEntity): self._scene_name = scene_device.name super().__init__(area_name, led_device, controller) - def turn_on(self, **kwargs): + def turn_on(self, **kwargs: Any) -> None: """Turn the LED on.""" self._lutron_device.state = 1 - def turn_off(self, **kwargs): + def turn_off(self, **kwargs: Any) -> None: """Turn the LED off.""" self._lutron_device.state = 0 @@ -99,11 +101,11 @@ class LutronLed(LutronDevice, SwitchEntity): return self._lutron_device.last_state @property - def name(self): + def name(self) -> str: """Return the name of the LED.""" return f"{self._area_name} {self._keypad_name}: {self._scene_name} LED" - def update(self): + def update(self) -> None: """Call when forcing a refresh of the device.""" if self._lutron_device.last_state is not None: return diff --git a/homeassistant/components/lutron_caseta/binary_sensor.py b/homeassistant/components/lutron_caseta/binary_sensor.py index 4b1c53d194b..20fc221cdef 100644 --- a/homeassistant/components/lutron_caseta/binary_sensor.py +++ b/homeassistant/components/lutron_caseta/binary_sensor.py @@ -61,7 +61,7 @@ class LutronOccupancySensor(LutronCasetaDevice, BinarySensorEntity): """Return the brightness of the light.""" return self._device["status"] == OCCUPANCY_GROUP_OCCUPIED - async def async_added_to_hass(self): + async def async_added_to_hass(self) -> None: """Register callbacks.""" self._smartbridge.add_occupancy_subscriber( self.device_id, self.async_write_ha_state diff --git a/homeassistant/components/lutron_caseta/switch.py b/homeassistant/components/lutron_caseta/switch.py index 062c8891672..92ec6b35f98 100644 --- a/homeassistant/components/lutron_caseta/switch.py +++ b/homeassistant/components/lutron_caseta/switch.py @@ -1,5 +1,7 @@ """Support for Lutron Caseta switches.""" +from typing import Any + from homeassistant.components.switch import DOMAIN, SwitchEntity from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant @@ -33,15 +35,15 @@ async def async_setup_entry( class LutronCasetaLight(LutronCasetaDeviceUpdatableEntity, SwitchEntity): """Representation of a Lutron Caseta switch.""" - async def async_turn_on(self, **kwargs): + async def async_turn_on(self, **kwargs: Any) -> None: """Turn the switch on.""" await self._smartbridge.turn_on(self.device_id) - async def async_turn_off(self, **kwargs): + async def async_turn_off(self, **kwargs: Any) -> None: """Turn the switch off.""" await self._smartbridge.turn_off(self.device_id) @property - def is_on(self): + def is_on(self) -> bool: """Return true if device is on.""" return self._device["current_state"] > 0