Improve entity type hints [l] (#77655)

pull/77666/head
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_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()

View File

@ -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}")

View File

@ -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))

View File

@ -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]

View File

@ -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

View File

@ -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)

View File

@ -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()

View File

@ -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:

View File

@ -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]

View File

@ -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)

View File

@ -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()

View File

@ -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()

View File

@ -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()

View File

@ -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()

View File

@ -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()

View File

@ -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}"

View File

@ -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}"

View File

@ -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

View File

@ -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

View File

@ -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