Improve entity type hints [l] (#77655)

This commit is contained in:
epenet 2022-09-01 14:14:31 +02:00 committed by GitHub
parent 08ab10d470
commit d1ecd74a1a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 73 additions and 61 deletions

View file

@ -73,7 +73,7 @@ class HeatMeterSensor(CoordinatorEntity, RestoreSensor):
self._attr_device_info = device self._attr_device_info = device
self._attr_should_poll = bool(self.key in ("heat_usage", "heat_previous_year")) 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.""" """Call when entity about to be added to hass."""
await super().async_added_to_hass() await super().async_added_to_hass()
state = await self.async_get_last_sensor_data() state = await self.async_get_last_sensor_data()

View file

@ -2,6 +2,7 @@
from __future__ import annotations from __future__ import annotations
from datetime import datetime from datetime import datetime
from typing import Any
from pylgnetcast import LgNetCastClient, LgNetCastError from pylgnetcast import LgNetCastClient, LgNetCastError
from requests import RequestException from requests import RequestException
@ -106,7 +107,7 @@ class LgTVDevice(MediaPlayerEntity):
except (LgNetCastError, RequestException): except (LgNetCastError, RequestException):
self._state = STATE_OFF self._state = STATE_OFF
def update(self): def update(self) -> None:
"""Retrieve the latest data from the LG TV.""" """Retrieve the latest data from the LG TV."""
try: try:
@ -219,63 +220,63 @@ class LgTVDevice(MediaPlayerEntity):
f"{self._client.url}data?target=screen_image&_={datetime.now().timestamp()}" f"{self._client.url}data?target=screen_image&_={datetime.now().timestamp()}"
) )
def turn_off(self): def turn_off(self) -> None:
"""Turn off media player.""" """Turn off media player."""
self.send_command(1) self.send_command(1)
def turn_on(self): def turn_on(self) -> None:
"""Turn on the media player.""" """Turn on the media player."""
if self._on_action_script: if self._on_action_script:
self._on_action_script.run(context=self._context) self._on_action_script.run(context=self._context)
def volume_up(self): def volume_up(self) -> None:
"""Volume up the media player.""" """Volume up the media player."""
self.send_command(24) self.send_command(24)
def volume_down(self): def volume_down(self) -> None:
"""Volume down media player.""" """Volume down media player."""
self.send_command(25) self.send_command(25)
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."""
self._client.set_volume(float(volume * 100)) self._client.set_volume(float(volume * 100))
def mute_volume(self, mute): def mute_volume(self, mute: bool) -> None:
"""Send mute command.""" """Send mute command."""
self.send_command(26) self.send_command(26)
def select_source(self, source): def select_source(self, source: str) -> None:
"""Select input source.""" """Select input source."""
self._client.change_channel(self._sources[source]) self._client.change_channel(self._sources[source])
def media_play_pause(self): def media_play_pause(self) -> None:
"""Simulate play pause media player.""" """Simulate play pause media player."""
if self._playing: if self._playing:
self.media_pause() self.media_pause()
else: else:
self.media_play() self.media_play()
def media_play(self): def media_play(self) -> None:
"""Send play command.""" """Send play command."""
self._playing = True self._playing = True
self._state = STATE_PLAYING self._state = STATE_PLAYING
self.send_command(33) self.send_command(33)
def media_pause(self): def media_pause(self) -> None:
"""Send media pause command to media player.""" """Send media pause command to media player."""
self._playing = False self._playing = False
self._state = STATE_PAUSED self._state = STATE_PAUSED
self.send_command(34) self.send_command(34)
def media_next_track(self): def media_next_track(self) -> None:
"""Send next track command.""" """Send next track command."""
self.send_command(36) self.send_command(36)
def media_previous_track(self): def media_previous_track(self) -> None:
"""Send the previous track command.""" """Send the previous track command."""
self.send_command(37) 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.""" """Tune to channel."""
if media_type != MEDIA_TYPE_CHANNEL: if media_type != MEDIA_TYPE_CHANNEL:
raise ValueError(f"Invalid media type: {media_type}") raise ValueError(f"Invalid media type: {media_type}")

View file

@ -65,11 +65,11 @@ class LGDevice(MediaPlayerEntity):
self._treble = 0 self._treble = 0
self._device = None 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.""" """Register the callback after hass is ready for it."""
await self.hass.async_add_executor_job(self._connect) await self.hass.async_add_executor_job(self._connect)
def _connect(self): def _connect(self) -> None:
"""Perform the actual devices setup.""" """Perform the actual devices setup."""
self._device = temescal.temescal( self._device = temescal.temescal(
self._host, port=self._port, callback=self.handle_event self._host, port=self._port, callback=self.handle_event
@ -126,7 +126,7 @@ class LGDevice(MediaPlayerEntity):
self.schedule_update_ha_state() self.schedule_update_ha_state()
def update(self): def update(self) -> None:
"""Trigger updates from the device.""" """Trigger updates from the device."""
self._device.get_eq() self._device.get_eq()
self._device.get_info() self._device.get_info()
@ -182,19 +182,19 @@ class LGDevice(MediaPlayerEntity):
sources.append(temescal.functions[function]) sources.append(temescal.functions[function])
return sorted(sources) return sorted(sources)
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."""
volume = volume * self._volume_max volume = volume * self._volume_max
self._device.set_volume(int(volume)) 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.""" """Mute (true) or unmute (false) media player."""
self._device.set_mute(mute) self._device.set_mute(mute)
def select_source(self, source): def select_source(self, source: str) -> None:
"""Select input source.""" """Select input source."""
self._device.set_func(temescal.functions.index(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..""" """Set Sound Mode for Receiver.."""
self._device.set_eq(temescal.equalisers.index(sound_mode)) self._device.set_eq(temescal.equalisers.index(sound_mode))

View file

@ -1,6 +1,8 @@
"""Support for LightwaveRF TRVs.""" """Support for LightwaveRF TRVs."""
from __future__ import annotations from __future__ import annotations
from typing import Any
from homeassistant.components.climate import ( from homeassistant.components.climate import (
DEFAULT_MAX_TEMP, DEFAULT_MAX_TEMP,
DEFAULT_MIN_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. # inhibit is used to prevent race condition on update. If non zero, skip next update cycle.
self._inhibit = 0 self._inhibit = 0
def update(self): def update(self) -> None:
"""Communicate with a Lightwave RTF Proxy to get state.""" """Communicate with a Lightwave RTF Proxy to get state."""
(temp, targ, _, trv_output) = self._lwlink.read_trv_status(self._serial) (temp, targ, _, trv_output) = self._lwlink.read_trv_status(self._serial)
if temp is not None: if temp is not None:
@ -95,7 +97,7 @@ class LightwaveTrv(ClimateEntity):
self._attr_target_temperature = self._inhibit self._attr_target_temperature = self._inhibit
return self._attr_target_temperature return self._attr_target_temperature
def set_temperature(self, **kwargs): def set_temperature(self, **kwargs: Any) -> None:
"""Set TRV target temperature.""" """Set TRV target temperature."""
if ATTR_TEMPERATURE in kwargs: if ATTR_TEMPERATURE in kwargs:
self._attr_target_temperature = kwargs[ATTR_TEMPERATURE] self._attr_target_temperature = kwargs[ATTR_TEMPERATURE]

View file

@ -50,7 +50,7 @@ class LightwaveBattery(SensorEntity):
self._serial = serial self._serial = serial
self._attr_unique_id = f"{serial}-trv-battery" self._attr_unique_id = f"{serial}-trv-battery"
def update(self): def update(self) -> None:
"""Communicate with a Lightwave RTF Proxy to get state.""" """Communicate with a Lightwave RTF Proxy to get state."""
(dummy_temp, dummy_targ, battery, dummy_output) = self._lwlink.read_trv_status( (dummy_temp, dummy_targ, battery, dummy_output) = self._lwlink.read_trv_status(
self._serial self._serial

View file

@ -1,6 +1,8 @@
"""Support for LightwaveRF switches.""" """Support for LightwaveRF 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.const import CONF_NAME from homeassistant.const import CONF_NAME
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
@ -41,13 +43,13 @@ class LWRFSwitch(SwitchEntity):
self._device_id = device_id self._device_id = device_id
self._lwlink = lwlink self._lwlink = lwlink
async def async_turn_on(self, **kwargs): async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn the LightWave switch on.""" """Turn the LightWave switch on."""
self._attr_is_on = True self._attr_is_on = True
self._lwlink.turn_on_switch(self._device_id, self._attr_name) self._lwlink.turn_on_switch(self._device_id, self._attr_name)
self.async_write_ha_state() 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.""" """Turn the LightWave switch off."""
self._attr_is_on = False self._attr_is_on = False
self._lwlink.turn_off(self._device_id, self._attr_name) self._lwlink.turn_off(self._device_id, self._attr_name)

View file

@ -68,7 +68,7 @@ class LinodeBinarySensor(BinarySensorEntity):
self._attr_extra_state_attributes = {} self._attr_extra_state_attributes = {}
self._attr_name = None self._attr_name = None
def update(self): def update(self) -> None:
"""Update state of sensor.""" """Update state of sensor."""
data = None data = None
self._linode.update() self._linode.update()

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
@ -63,17 +64,17 @@ class LinodeSwitch(SwitchEntity):
self.data = None self.data = None
self._attr_extra_state_attributes = {} self._attr_extra_state_attributes = {}
def turn_on(self, **kwargs): def turn_on(self, **kwargs: Any) -> None:
"""Boot-up the Node.""" """Boot-up the Node."""
if self.data.status != "running": if self.data.status != "running":
self.data.boot() self.data.boot()
def turn_off(self, **kwargs): def turn_off(self, **kwargs: Any) -> None:
"""Shutdown the nodes.""" """Shutdown the nodes."""
if self.data.status == "running": if self.data.status == "running":
self.data.shutdown() self.data.shutdown()
def update(self): def update(self) -> None:
"""Get the latest data from the device and update the data.""" """Get the latest data from the device and update the data."""
self._linode.update() self._linode.update()
if self._linode.data is not None: if self._linode.data is not None:

View file

@ -124,7 +124,7 @@ class LinuxBatterySensor(SensorEntity):
ATTR_VOLTAGE_NOW: self._battery_stat.voltage_now, ATTR_VOLTAGE_NOW: self._battery_stat.voltage_now,
} }
def update(self): def update(self) -> None:
"""Get the latest data and updates the states.""" """Get the latest data and updates the states."""
self._battery.update() self._battery.update()
self._battery_stat = self._battery.stat[self._battery_id] self._battery_stat = self._battery.stat[self._battery_id]

View file

@ -1,5 +1,6 @@
"""Support for LiteJet switch.""" """Support for LiteJet switch."""
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
@ -45,12 +46,12 @@ class LiteJetSwitch(SwitchEntity):
self._state = False self._state = False
self._name = name 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.""" """Run when this Entity has been added to HA."""
self._lj.on_switch_pressed(self._index, self._on_switch_pressed) self._lj.on_switch_pressed(self._index, self._on_switch_pressed)
self._lj.on_switch_released(self._index, self._on_switch_released) 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.""" """Entity being removed from hass."""
self._lj.unsubscribe(self._on_switch_pressed) self._lj.unsubscribe(self._on_switch_pressed)
self._lj.unsubscribe(self._on_switch_released) self._lj.unsubscribe(self._on_switch_released)
@ -85,11 +86,11 @@ class LiteJetSwitch(SwitchEntity):
"""Return the device-specific state attributes.""" """Return the device-specific state attributes."""
return {ATTR_NUMBER: self._index} return {ATTR_NUMBER: self._index}
def turn_on(self, **kwargs): def turn_on(self, **kwargs: Any) -> None:
"""Press the switch.""" """Press the switch."""
self._lj.press_switch(self._index) self._lj.press_switch(self._index)
def turn_off(self, **kwargs): def turn_off(self, **kwargs: Any) -> None:
"""Release the switch.""" """Release the switch."""
self._lj.release_switch(self._index) self._lj.release_switch(self._index)

View file

@ -64,13 +64,13 @@ class LocativeEntity(TrackerEntity):
"""Return the source type, eg gps or router, of the device.""" """Return the source type, eg gps or router, of the device."""
return SourceType.GPS return SourceType.GPS
async def async_added_to_hass(self): async def async_added_to_hass(self) -> None:
"""Register state update callback.""" """Register state update callback."""
self._unsub_dispatcher = async_dispatcher_connect( self._unsub_dispatcher = async_dispatcher_connect(
self.hass, TRACKER_UPDATE, self._async_receive_data 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.""" """Clean up after entity before removal."""
self._unsub_dispatcher() self._unsub_dispatcher()

View file

@ -75,7 +75,7 @@ class LogiCam(Camera):
self._ffmpeg = ffmpeg self._ffmpeg = ffmpeg
self._listeners = [] self._listeners = []
async def async_added_to_hass(self): async def async_added_to_hass(self) -> None:
"""Connect camera methods to signals.""" """Connect camera methods to signals."""
def _dispatch_proxy(method): 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.""" """Disconnect dispatcher listeners when removed."""
for detach in self._listeners: for detach in self._listeners:
detach() detach()
@ -161,11 +161,11 @@ class LogiCam(Camera):
"""Return a still image from the camera.""" """Return a still image from the camera."""
return await self._camera.live_stream.download_jpeg() 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.""" """Disable streaming mode for this camera."""
await self._camera.set_config("streaming", False) 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.""" """Enable streaming mode for this camera."""
await self._camera.set_config("streaming", True) await self._camera.set_config("streaming", True)
@ -210,6 +210,6 @@ class LogiCam(Camera):
filename=snapshot_file, refresh=True filename=snapshot_file, refresh=True
) )
async def async_update(self): async def async_update(self) -> None:
"""Update camera entity and refresh attributes.""" """Update camera entity and refresh attributes."""
await self._camera.update() await self._camera.update()

View file

@ -112,7 +112,7 @@ class LogiSensor(SensorEntity):
) )
return self.entity_description.icon return self.entity_description.icon
async def async_update(self): async def async_update(self) -> None:
"""Get the latest data and updates the state.""" """Get the latest data and updates the state."""
_LOGGER.debug("Pulling data from %s sensor", self.name) _LOGGER.debug("Pulling data from %s sensor", self.name)
await self._camera.update() await self._camera.update()

View file

@ -141,7 +141,7 @@ class AirSensor(SensorEntity):
attrs["data"] = self._site_data attrs["data"] = self._site_data
return attrs return attrs
def update(self): def update(self) -> None:
"""Update the sensor.""" """Update the sensor."""
sites_status = [] sites_status = []
self._api_data.update() self._api_data.update()

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
import lupupy.constants as CONST import lupupy.constants as CONST
@ -39,11 +40,11 @@ def setup_platform(
class LupusecSwitch(LupusecDevice, SwitchEntity): class LupusecSwitch(LupusecDevice, SwitchEntity):
"""Representation of a Lupusec switch.""" """Representation of a Lupusec switch."""
def turn_on(self, **kwargs): def turn_on(self, **kwargs: Any) -> None:
"""Turn on the device.""" """Turn on the device."""
self._device.switch_on() self._device.switch_on()
def turn_off(self, **kwargs): def turn_off(self, **kwargs: Any) -> None:
"""Turn off the device.""" """Turn off the device."""
self._device.switch_off() self._device.switch_off()

View file

@ -124,7 +124,7 @@ class LutronDevice(Entity):
self._controller = controller self._controller = controller
self._area_name = area_name self._area_name = area_name
async def async_added_to_hass(self): async def async_added_to_hass(self) -> None:
"""Register callbacks.""" """Register callbacks."""
self._lutron_device.subscribe(self._update_callback, None) self._lutron_device.subscribe(self._update_callback, None)
@ -133,7 +133,7 @@ class LutronDevice(Entity):
self.schedule_update_ha_state() self.schedule_update_ha_state()
@property @property
def name(self): def name(self) -> str:
"""Return the name of the device.""" """Return the name of the device."""
return f"{self._area_name} {self._lutron_device.name}" return f"{self._area_name} {self._lutron_device.name}"

View file

@ -43,6 +43,6 @@ class LutronScene(LutronDevice, Scene):
self._lutron_device.press() self._lutron_device.press()
@property @property
def name(self): def name(self) -> str:
"""Return the name of the device.""" """Return the name of the device."""
return f"{self._area_name} {self._keypad_name}: {self._lutron_device.name}" return f"{self._area_name} {self._keypad_name}: {self._lutron_device.name}"

View file

@ -1,6 +1,8 @@
"""Support for Lutron switches.""" """Support for Lutron 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
@ -43,11 +45,11 @@ class LutronSwitch(LutronDevice, SwitchEntity):
self._prev_state = None self._prev_state = None
super().__init__(area_name, lutron_device, controller) super().__init__(area_name, lutron_device, controller)
def turn_on(self, **kwargs): def turn_on(self, **kwargs: Any) -> None:
"""Turn the switch on.""" """Turn the switch on."""
self._lutron_device.level = 100 self._lutron_device.level = 100
def turn_off(self, **kwargs): def turn_off(self, **kwargs: Any) -> None:
"""Turn the switch off.""" """Turn the switch off."""
self._lutron_device.level = 0 self._lutron_device.level = 0
@ -61,7 +63,7 @@ class LutronSwitch(LutronDevice, SwitchEntity):
"""Return true if device is on.""" """Return true if device is on."""
return self._lutron_device.last_level() > 0 return self._lutron_device.last_level() > 0
def update(self): def update(self) -> None:
"""Call when forcing a refresh of the device.""" """Call when forcing a refresh of the device."""
if self._prev_state is None: if self._prev_state is None:
self._prev_state = self._lutron_device.level > 0 self._prev_state = self._lutron_device.level > 0
@ -76,11 +78,11 @@ class LutronLed(LutronDevice, SwitchEntity):
self._scene_name = scene_device.name self._scene_name = scene_device.name
super().__init__(area_name, led_device, controller) super().__init__(area_name, led_device, controller)
def turn_on(self, **kwargs): def turn_on(self, **kwargs: Any) -> None:
"""Turn the LED on.""" """Turn the LED on."""
self._lutron_device.state = 1 self._lutron_device.state = 1
def turn_off(self, **kwargs): def turn_off(self, **kwargs: Any) -> None:
"""Turn the LED off.""" """Turn the LED off."""
self._lutron_device.state = 0 self._lutron_device.state = 0
@ -99,11 +101,11 @@ class LutronLed(LutronDevice, SwitchEntity):
return self._lutron_device.last_state return self._lutron_device.last_state
@property @property
def name(self): def name(self) -> str:
"""Return the name of the LED.""" """Return the name of the LED."""
return f"{self._area_name} {self._keypad_name}: {self._scene_name} 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.""" """Call when forcing a refresh of the device."""
if self._lutron_device.last_state is not None: if self._lutron_device.last_state is not None:
return return

View file

@ -61,7 +61,7 @@ class LutronOccupancySensor(LutronCasetaDevice, BinarySensorEntity):
"""Return the brightness of the light.""" """Return the brightness of the light."""
return self._device["status"] == OCCUPANCY_GROUP_OCCUPIED return self._device["status"] == OCCUPANCY_GROUP_OCCUPIED
async def async_added_to_hass(self): async def async_added_to_hass(self) -> None:
"""Register callbacks.""" """Register callbacks."""
self._smartbridge.add_occupancy_subscriber( self._smartbridge.add_occupancy_subscriber(
self.device_id, self.async_write_ha_state self.device_id, self.async_write_ha_state

View file

@ -1,5 +1,7 @@
"""Support for Lutron Caseta switches.""" """Support for Lutron Caseta switches."""
from typing import Any
from homeassistant.components.switch import DOMAIN, SwitchEntity from homeassistant.components.switch import DOMAIN, SwitchEntity
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
@ -33,15 +35,15 @@ async def async_setup_entry(
class LutronCasetaLight(LutronCasetaDeviceUpdatableEntity, SwitchEntity): class LutronCasetaLight(LutronCasetaDeviceUpdatableEntity, SwitchEntity):
"""Representation of a Lutron Caseta switch.""" """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.""" """Turn the switch on."""
await self._smartbridge.turn_on(self.device_id) 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.""" """Turn the switch off."""
await self._smartbridge.turn_off(self.device_id) await self._smartbridge.turn_off(self.device_id)
@property @property
def is_on(self): def is_on(self) -> bool:
"""Return true if device is on.""" """Return true if device is on."""
return self._device["current_state"] > 0 return self._device["current_state"] > 0