Improve entity type hints [o] (#77826)

pull/77880/head
epenet 2022-09-06 10:25:35 +02:00 committed by GitHub
parent d6ca3544ee
commit ea71a462d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 68 additions and 58 deletions

View File

@ -127,7 +127,7 @@ class OASATelematicsSensor(SensorEntity):
"""Icon to use in the frontend, if any."""
return ICON
def update(self):
def update(self) -> None:
"""Get the latest data from OASA API and update the states."""
self.data.update()
self._times = self.data.info

View File

@ -146,7 +146,7 @@ class ObihaiServiceSensors(SensorEntity):
return "mdi:restart-alert"
return "mdi:phone"
def update(self):
def update(self) -> None:
"""Update the sensor."""
services = self._pyobihai.get_state()

View File

@ -1,6 +1,8 @@
"""OpenEnergyMonitor Thermostat Support."""
from __future__ import annotations
from typing import Any
from oemthermostat import Thermostat
import requests
import voluptuous as vol
@ -122,12 +124,12 @@ class ThermostatDevice(ClimateEntity):
elif hvac_mode == HVACMode.OFF:
self.thermostat.mode = 0
def set_temperature(self, **kwargs):
def set_temperature(self, **kwargs: Any) -> None:
"""Set the temperature."""
temp = kwargs.get(ATTR_TEMPERATURE)
self.thermostat.setpoint = temp
def update(self):
def update(self) -> None:
"""Update local state."""
self._setpoint = self.thermostat.setpoint
self._temperature = self.thermostat.temperature

View File

@ -70,7 +70,7 @@ class OhmconnectSensor(SensorEntity):
return {"Address": self._data.get("address"), "ID": self._ohmid}
@Throttle(MIN_TIME_BETWEEN_UPDATES)
def update(self):
def update(self) -> None:
"""Get the latest data from OhmConnect."""
try:
url = f"https://login.ohmconnect.com/verify-ohm-hour/{self._ohmid}"

View File

@ -45,7 +45,7 @@ class OmbiSensor(SensorEntity):
self._attr_name = f"Ombi {description.name}"
def update(self):
def update(self) -> None:
"""Update the sensor."""
try:
sensor_type = self.entity_description.key

View File

@ -2,6 +2,7 @@
from __future__ import annotations
import logging
from typing import Any
import eiscp
from eiscp import eISCP
@ -295,7 +296,7 @@ class OnkyoDevice(MediaPlayerEntity):
_LOGGER.debug("Result for %s: %s", command, result)
return result
def update(self):
def update(self) -> None:
"""Get the latest state from the device."""
status = self.command("system-power query")
@ -396,11 +397,11 @@ class OnkyoDevice(MediaPlayerEntity):
"""Return device specific state attributes."""
return self._attributes
def turn_off(self):
def turn_off(self) -> None:
"""Turn the media player off."""
self.command("system-power standby")
def set_volume_level(self, volume):
def set_volume_level(self, volume: float) -> None:
"""
Set volume level, input is range 0..1.
@ -414,32 +415,32 @@ class OnkyoDevice(MediaPlayerEntity):
f"volume {int(volume * (self._max_volume / 100) * self._receiver_max_volume)}"
)
def volume_up(self):
def volume_up(self) -> None:
"""Increase volume by 1 step."""
self.command("volume level-up")
def volume_down(self):
def volume_down(self) -> None:
"""Decrease volume by 1 step."""
self.command("volume level-down")
def mute_volume(self, mute):
def mute_volume(self, mute: bool) -> None:
"""Mute (true) or unmute (false) media player."""
if mute:
self.command("audio-muting on")
else:
self.command("audio-muting off")
def turn_on(self):
def turn_on(self) -> None:
"""Turn the media player on."""
self.command("system-power on")
def select_source(self, source):
def select_source(self, source: str) -> None:
"""Set the input source."""
if source in self._source_list:
source = self._reverse_mapping[source]
self.command(f"input-selector {source}")
def play_media(self, media_type, media_id, **kwargs):
def play_media(self, media_type: str, media_id: str, **kwargs: Any) -> None:
"""Play radio station by preset number."""
source = self._reverse_mapping[self._current_source]
if media_type.lower() == "radio" and source in DEFAULT_PLAYABLE_SOURCES:
@ -506,7 +507,7 @@ class OnkyoDeviceZone(OnkyoDevice):
self._supports_volume = True
super().__init__(receiver, sources, name, max_volume, receiver_max_volume)
def update(self):
def update(self) -> None:
"""Get the latest state from the device."""
status = self.command(f"zone{self._zone}.power=query")
@ -563,11 +564,11 @@ class OnkyoDeviceZone(OnkyoDevice):
return SUPPORT_ONKYO
return SUPPORT_ONKYO_WO_VOLUME
def turn_off(self):
def turn_off(self) -> None:
"""Turn the media player off."""
self.command(f"zone{self._zone}.power=standby")
def set_volume_level(self, volume):
def set_volume_level(self, volume: float) -> None:
"""
Set volume level, input is range 0..1.
@ -581,26 +582,26 @@ class OnkyoDeviceZone(OnkyoDevice):
f"zone{self._zone}.volume={int(volume * (self._max_volume / 100) * self._receiver_max_volume)}"
)
def volume_up(self):
def volume_up(self) -> None:
"""Increase volume by 1 step."""
self.command(f"zone{self._zone}.volume=level-up")
def volume_down(self):
def volume_down(self) -> None:
"""Decrease volume by 1 step."""
self.command(f"zone{self._zone}.volume=level-down")
def mute_volume(self, mute):
def mute_volume(self, mute: bool) -> None:
"""Mute (true) or unmute (false) media player."""
if mute:
self.command(f"zone{self._zone}.muting=on")
else:
self.command(f"zone{self._zone}.muting=off")
def turn_on(self):
def turn_on(self) -> None:
"""Turn the media player on."""
self.command(f"zone{self._zone}.power=on")
def select_source(self, source):
def select_source(self, source: str) -> None:
"""Set the input source."""
if source in self._source_list:
source = self._reverse_mapping[source]

View File

@ -82,7 +82,7 @@ class ONVIFBinarySensor(ONVIFBaseEntity, RestoreEntity, BinarySensorEntity):
return event.value
return self._attr_is_on
async def async_added_to_hass(self):
async def async_added_to_hass(self) -> None:
"""Connect to dispatcher listening for entity data notifications."""
self.async_on_remove(
self.device.events.async_add_listener(self.async_write_ha_state)

View File

@ -81,7 +81,7 @@ class ONVIFSensor(ONVIFBaseEntity, RestoreSensor):
return event.value
return self._attr_native_value
async def async_added_to_hass(self):
async def async_added_to_hass(self) -> None:
"""Connect to dispatcher listening for entity data notifications."""
self.async_on_remove(
self.device.events.async_add_listener(self.async_write_ha_state)

View File

@ -58,7 +58,7 @@ class OpenERZSensor(SensorEntity):
"""Return the state of the sensor."""
return self._state
def update(self):
def update(self) -> None:
"""Fetch new state data for the sensor.
This is the only method that should fetch new data for Home Assistant.

View File

@ -118,7 +118,7 @@ class OpenEVSESensor(SensorEntity):
self.entity_description = description
self.charger = charger
def update(self):
def update(self) -> None:
"""Get the monitored data from the charger."""
try:
sensor_type = self.entity_description.key

View File

@ -91,7 +91,7 @@ class OpenHardwareMonitorDevice(SensorEntity):
"""In some locales a decimal numbers uses ',' instead of '.'."""
return string.replace(",", ".")
def update(self):
def update(self) -> None:
"""Update the device from a new JSON object."""
self._data.update()

View File

@ -19,6 +19,7 @@ from homeassistant.components.media_player import (
MediaPlayerEntityFeature,
)
from homeassistant.components.media_player.browse_media import (
BrowseMedia,
async_process_play_media_url,
)
from homeassistant.components.media_player.const import MEDIA_TYPE_MUSIC
@ -133,7 +134,7 @@ class OpenhomeDevice(MediaPlayerEntity):
"""Device is available."""
return self._available
async def async_update(self):
async def async_update(self) -> None:
"""Update state of device."""
try:
self._in_standby = await self._device.is_in_standby()
@ -195,17 +196,19 @@ class OpenhomeDevice(MediaPlayerEntity):
self._available = False
@catch_request_errors()
async def async_turn_on(self):
async def async_turn_on(self) -> None:
"""Bring device out of standby."""
await self._device.set_standby(False)
@catch_request_errors()
async def async_turn_off(self):
async def async_turn_off(self) -> None:
"""Put device in standby."""
await self._device.set_standby(True)
@catch_request_errors()
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:
"""Send the play_media command to the media player."""
if media_source.is_media_source_id(media_id):
media_type = MEDIA_TYPE_MUSIC
@ -228,32 +231,32 @@ class OpenhomeDevice(MediaPlayerEntity):
await self._device.play_media(track_details)
@catch_request_errors()
async def async_media_pause(self):
async def async_media_pause(self) -> None:
"""Send pause command."""
await self._device.pause()
@catch_request_errors()
async def async_media_stop(self):
async def async_media_stop(self) -> None:
"""Send stop command."""
await self._device.stop()
@catch_request_errors()
async def async_media_play(self):
async def async_media_play(self) -> None:
"""Send play command."""
await self._device.play()
@catch_request_errors()
async def async_media_next_track(self):
async def async_media_next_track(self) -> None:
"""Send next track command."""
await self._device.skip(1)
@catch_request_errors()
async def async_media_previous_track(self):
async def async_media_previous_track(self) -> None:
"""Send previous track command."""
await self._device.skip(-1)
@catch_request_errors()
async def async_select_source(self, source):
async def async_select_source(self, source: str) -> None:
"""Select input source."""
await self._device.set_source(self._source_index[source])
@ -325,26 +328,28 @@ class OpenhomeDevice(MediaPlayerEntity):
return self._volume_muted
@catch_request_errors()
async def async_volume_up(self):
async def async_volume_up(self) -> None:
"""Volume up media player."""
await self._device.increase_volume()
@catch_request_errors()
async def async_volume_down(self):
async def async_volume_down(self) -> None:
"""Volume down media player."""
await self._device.decrease_volume()
@catch_request_errors()
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._device.set_volume(int(volume * 100))
@catch_request_errors()
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._device.set_mute(mute)
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."""
return await media_source.async_browse_media(
self.hass,

View File

@ -102,14 +102,14 @@ class OpenThermBinarySensor(BinarySensorEntity):
self._friendly_name = friendly_name_format.format(gw_dev.name)
self._unsub_updates = None
async def async_added_to_hass(self):
async def async_added_to_hass(self) -> None:
"""Subscribe to updates from the component."""
_LOGGER.debug("Added OpenTherm Gateway binary sensor %s", self._friendly_name)
self._unsub_updates = async_dispatcher_connect(
self.hass, self._gateway.update_signal, self.receive_report
)
async def async_will_remove_from_hass(self):
async def async_will_remove_from_hass(self) -> None:
"""Unsubscribe from updates from the component."""
_LOGGER.debug(
"Removing OpenTherm Gateway binary sensor %s", self._friendly_name

View File

@ -2,6 +2,7 @@
from __future__ import annotations
import logging
from typing import Any
from pyotgw import vars as gw_vars
@ -101,7 +102,7 @@ class OpenThermClimate(ClimateEntity):
self.temporary_ovrd_mode = entry.options[CONF_TEMPORARY_OVRD_MODE]
self.async_write_ha_state()
async def async_added_to_hass(self):
async def async_added_to_hass(self) -> None:
"""Connect to the OpenTherm Gateway device."""
_LOGGER.debug("Added OpenTherm Gateway climate device %s", self.friendly_name)
self._unsub_updates = async_dispatcher_connect(
@ -111,7 +112,7 @@ class OpenThermClimate(ClimateEntity):
self.hass, self._gateway.options_update_signal, self.update_options
)
async def async_will_remove_from_hass(self):
async def async_will_remove_from_hass(self) -> None:
"""Unsubscribe from updates from the component."""
_LOGGER.debug("Removing OpenTherm Gateway climate %s", self.friendly_name)
self._unsub_options()
@ -261,11 +262,11 @@ class OpenThermClimate(ClimateEntity):
"""Available preset modes to set."""
return []
def set_preset_mode(self, preset_mode):
def set_preset_mode(self, preset_mode: str) -> None:
"""Set the preset mode."""
_LOGGER.warning("Changing preset mode is not supported")
async def async_set_temperature(self, **kwargs):
async def async_set_temperature(self, **kwargs: Any) -> None:
"""Set new target temperature."""
if ATTR_TEMPERATURE in kwargs:
temp = float(kwargs[ATTR_TEMPERATURE])

View File

@ -106,14 +106,14 @@ class OpenThermSensor(SensorEntity):
self._friendly_name = friendly_name_format.format(gw_dev.name)
self._unsub_updates = None
async def async_added_to_hass(self):
async def async_added_to_hass(self) -> None:
"""Subscribe to updates from the component."""
_LOGGER.debug("Added OpenTherm Gateway sensor %s", self._friendly_name)
self._unsub_updates = async_dispatcher_connect(
self.hass, self._gateway.update_signal, self.receive_report
)
async def async_will_remove_from_hass(self):
async def async_will_remove_from_hass(self) -> None:
"""Unsubscribe from updates from the component."""
_LOGGER.debug("Removing OpenTherm Gateway sensor %s", self._friendly_name)
self._unsub_updates()

View File

@ -69,7 +69,7 @@ class OppleLight(LightEntity):
self._color_temp = None
@property
def available(self):
def available(self) -> bool:
"""Return True if light is available."""
return self._device.is_online

View File

@ -75,7 +75,7 @@ class CurrentEnergyUsageSensor(SensorEntity):
"""Return the state of the sensor."""
return self._state
def update(self):
def update(self) -> None:
"""Fetch new state data for the sensor."""
try:
last_read = self.meter.last_read()

View File

@ -2,6 +2,7 @@
from __future__ import annotations
import logging
from typing import Any
from orvibo.s20 import S20, S20Exception, discover
import voluptuous as vol
@ -93,21 +94,21 @@ class S20Switch(SwitchEntity):
"""Return true if device is on."""
return self._state
def update(self):
def update(self) -> None:
"""Update device state."""
try:
self._state = self._s20.on
except self._exc:
_LOGGER.exception("Error while fetching S20 state")
def turn_on(self, **kwargs):
def turn_on(self, **kwargs: Any) -> None:
"""Turn the device on."""
try:
self._s20.on = True
except self._exc:
_LOGGER.exception("Error while turning on S20")
def turn_off(self, **kwargs):
def turn_off(self, **kwargs: Any) -> None:
"""Turn the device off."""
try:
self._s20.on = False

View File

@ -53,7 +53,7 @@ class TOTPSensor(SensorEntity):
self._state = None
self._next_expiration = None
async def async_added_to_hass(self):
async def async_added_to_hass(self) -> None:
"""Handle when an entity is about to be added to Home Assistant."""
self._call_loop()

View File

@ -124,7 +124,7 @@ class OwnTracksEntity(TrackerEntity, RestoreEntity):
"""Return the device info."""
return DeviceInfo(identifiers={(OT_DOMAIN, self._dev_id)}, name=self.name)
async def async_added_to_hass(self):
async def async_added_to_hass(self) -> None:
"""Call when entity about to be added to Home Assistant."""
await super().async_added_to_hass()