mirror of https://github.com/home-assistant/core
Improve entity type hints [g] (#77145)
This commit is contained in:
parent
452ee0284a
commit
b043053aad
|
@ -59,7 +59,7 @@ class GC100BinarySensor(BinarySensorEntity):
|
|||
"""Return the state of the entity."""
|
||||
return self._state
|
||||
|
||||
def update(self):
|
||||
def update(self) -> None:
|
||||
"""Update the sensor state."""
|
||||
self._gc100.read_sensor(self._port_addr, self.set_state)
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
"""Support for switches using GC100."""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.switch import PLATFORM_SCHEMA, SwitchEntity
|
||||
|
@ -54,15 +56,15 @@ class GC100Switch(SwitchEntity):
|
|||
"""Return the state of the entity."""
|
||||
return self._state
|
||||
|
||||
def turn_on(self, **kwargs):
|
||||
def turn_on(self, **kwargs: Any) -> None:
|
||||
"""Turn the device on."""
|
||||
self._gc100.write_switch(self._port_addr, 1, self.set_state)
|
||||
|
||||
def turn_off(self, **kwargs):
|
||||
def turn_off(self, **kwargs: Any) -> None:
|
||||
"""Turn the device off."""
|
||||
self._gc100.write_switch(self._port_addr, 0, self.set_state)
|
||||
|
||||
def update(self):
|
||||
def update(self) -> None:
|
||||
"""Update the sensor state."""
|
||||
self._gc100.read_sensor(self._port_addr, self.set_state)
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ class GdacsSensor(SensorEntity):
|
|||
self._removed = None
|
||||
self._remove_signal_status = None
|
||||
|
||||
async def async_added_to_hass(self):
|
||||
async def async_added_to_hass(self) -> None:
|
||||
"""Call when entity is added to hass."""
|
||||
self._remove_signal_status = async_dispatcher_connect(
|
||||
self.hass,
|
||||
|
@ -81,7 +81,7 @@ class GdacsSensor(SensorEntity):
|
|||
_LOGGER.debug("Received status update for %s", self._config_entry_id)
|
||||
self.async_schedule_update_ha_state(True)
|
||||
|
||||
async def async_update(self):
|
||||
async def async_update(self) -> None:
|
||||
"""Update this entity from the data held in the feed manager."""
|
||||
_LOGGER.debug("Updating %s", self._config_entry_id)
|
||||
if self._manager:
|
||||
|
|
|
@ -4,6 +4,7 @@ from __future__ import annotations
|
|||
import asyncio
|
||||
import logging
|
||||
import math
|
||||
from typing import Any
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
|
@ -366,7 +367,7 @@ class GenericThermostat(ClimateEntity, RestoreEntity):
|
|||
"""List of available operation modes."""
|
||||
return self._hvac_list
|
||||
|
||||
async def async_set_hvac_mode(self, hvac_mode):
|
||||
async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
|
||||
"""Set hvac mode."""
|
||||
if hvac_mode == HVACMode.HEAT:
|
||||
self._hvac_mode = HVACMode.HEAT
|
||||
|
@ -384,7 +385,7 @@ class GenericThermostat(ClimateEntity, RestoreEntity):
|
|||
# Ensure we update the current operation after changing the mode
|
||||
self.async_write_ha_state()
|
||||
|
||||
async def async_set_temperature(self, **kwargs):
|
||||
async def async_set_temperature(self, **kwargs: Any) -> None:
|
||||
"""Set new target temperature."""
|
||||
if (temperature := kwargs.get(ATTR_TEMPERATURE)) is None:
|
||||
return
|
||||
|
@ -537,7 +538,7 @@ class GenericThermostat(ClimateEntity, RestoreEntity):
|
|||
HA_DOMAIN, SERVICE_TURN_OFF, data, context=self._context
|
||||
)
|
||||
|
||||
async def async_set_preset_mode(self, preset_mode: str):
|
||||
async def async_set_preset_mode(self, preset_mode: str) -> None:
|
||||
"""Set new preset mode."""
|
||||
if preset_mode not in (self._attr_preset_modes or []):
|
||||
raise ValueError(
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from datetime import timedelta
|
||||
from typing import Any
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
|
@ -71,13 +72,13 @@ class GeniusSwitch(GeniusZone, SwitchEntity):
|
|||
"""
|
||||
return self._zone.data["mode"] == "override" and self._zone.data["setpoint"]
|
||||
|
||||
async def async_turn_off(self, **kwargs) -> None:
|
||||
async def async_turn_off(self, **kwargs: Any) -> None:
|
||||
"""Send the zone to Timer mode.
|
||||
|
||||
The zone is deemed 'off' in this mode, although the plugs may actually be on.
|
||||
"""
|
||||
await self._zone.set_mode("timer")
|
||||
|
||||
async def async_turn_on(self, **kwargs) -> None:
|
||||
async def async_turn_on(self, **kwargs: Any) -> None:
|
||||
"""Set the zone to override/on ({'setpoint': true}) for x seconds."""
|
||||
await self._zone.set_override(1, kwargs.get(ATTR_DURATION, 3600))
|
||||
|
|
|
@ -78,6 +78,6 @@ class GeniusWaterHeater(GeniusHeatingZone, WaterHeaterEntity):
|
|||
"""Return the current operation mode."""
|
||||
return GH_STATE_TO_HA[self._zone.data["mode"]] # type: ignore[return-value]
|
||||
|
||||
async def async_set_operation_mode(self, operation_mode) -> None:
|
||||
async def async_set_operation_mode(self, operation_mode: str) -> None:
|
||||
"""Set a new operation mode for this boiler."""
|
||||
await self._zone.set_mode(HA_OPMODE_TO_GH[operation_mode])
|
||||
|
|
|
@ -150,7 +150,7 @@ class GeoRssServiceSensor(SensorEntity):
|
|||
"""Return the state attributes."""
|
||||
return self._state_attributes
|
||||
|
||||
def update(self):
|
||||
def update(self) -> None:
|
||||
"""Update this sensor from the GeoRSS service."""
|
||||
|
||||
status, feed_entries = self._feed.update()
|
||||
|
|
|
@ -100,7 +100,7 @@ class GeofencyEntity(TrackerEntity, RestoreEntity):
|
|||
"""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."""
|
||||
await super().async_added_to_hass()
|
||||
self._unsub_dispatcher = async_dispatcher_connect(
|
||||
|
@ -117,7 +117,7 @@ class GeofencyEntity(TrackerEntity, RestoreEntity):
|
|||
attr = state.attributes
|
||||
self._gps = (attr.get(ATTR_LATITUDE), attr.get(ATTR_LONGITUDE))
|
||||
|
||||
async def async_will_remove_from_hass(self):
|
||||
async def async_will_remove_from_hass(self) -> None:
|
||||
"""Clean up after entity before removal."""
|
||||
await super().async_will_remove_from_hass()
|
||||
self._unsub_dispatcher()
|
||||
|
|
|
@ -60,7 +60,7 @@ class GeonetnzQuakesSensor(SensorEntity):
|
|||
self._removed = None
|
||||
self._remove_signal_status = None
|
||||
|
||||
async def async_added_to_hass(self):
|
||||
async def async_added_to_hass(self) -> None:
|
||||
"""Call when entity is added to hass."""
|
||||
self._remove_signal_status = async_dispatcher_connect(
|
||||
self.hass,
|
||||
|
@ -82,7 +82,7 @@ class GeonetnzQuakesSensor(SensorEntity):
|
|||
_LOGGER.debug("Received status update for %s", self._config_entry_id)
|
||||
self.async_schedule_update_ha_state(True)
|
||||
|
||||
async def async_update(self):
|
||||
async def async_update(self) -> None:
|
||||
"""Update this entity from the data held in the feed manager."""
|
||||
_LOGGER.debug("Updating %s", self._config_entry_id)
|
||||
if self._manager:
|
||||
|
|
|
@ -81,7 +81,7 @@ class GeonetnzVolcanoSensor(SensorEntity):
|
|||
self._feed_last_update_successful = None
|
||||
self._remove_signal_update = None
|
||||
|
||||
async def async_added_to_hass(self):
|
||||
async def async_added_to_hass(self) -> None:
|
||||
"""Call when entity is added to hass."""
|
||||
self._remove_signal_update = async_dispatcher_connect(
|
||||
self.hass,
|
||||
|
@ -99,7 +99,7 @@ class GeonetnzVolcanoSensor(SensorEntity):
|
|||
"""Call update method."""
|
||||
self.async_schedule_update_ha_state(True)
|
||||
|
||||
async def async_update(self):
|
||||
async def async_update(self) -> None:
|
||||
"""Update this entity from the data held in the feed manager."""
|
||||
_LOGGER.debug("Updating %s", self._external_id)
|
||||
feed_entry = self._feed_manager.get_entry(self._external_id)
|
||||
|
|
|
@ -126,7 +126,7 @@ class GitLabSensor(SensorEntity):
|
|||
return ICON_SAD
|
||||
return ICON_OTHER
|
||||
|
||||
def update(self):
|
||||
def update(self) -> None:
|
||||
"""Collect updated data from GitLab API."""
|
||||
self._gitlab_data.update()
|
||||
|
||||
|
|
|
@ -98,7 +98,7 @@ class GitterSensor(SensorEntity):
|
|||
"""Return the icon to use in the frontend, if any."""
|
||||
return ICON
|
||||
|
||||
def update(self):
|
||||
def update(self) -> None:
|
||||
"""Get the latest data and updates the state."""
|
||||
|
||||
try:
|
||||
|
|
|
@ -20,7 +20,7 @@ from homeassistant.const import (
|
|||
TEMP_CELSIUS,
|
||||
Platform,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.core import CALLBACK_TYPE, HomeAssistant, callback
|
||||
from homeassistant.helpers import entity_registry
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
|
@ -330,7 +330,7 @@ class GlancesSensor(SensorEntity):
|
|||
self.glances_data = glances_data
|
||||
self._sensor_name_prefix = sensor_name_prefix
|
||||
self._state = None
|
||||
self.unsub_update = None
|
||||
self.unsub_update: CALLBACK_TYPE | None = None
|
||||
|
||||
self.entity_description = description
|
||||
self._attr_name = f"{sensor_name_prefix} {description.name_suffix}"
|
||||
|
@ -342,7 +342,7 @@ class GlancesSensor(SensorEntity):
|
|||
self._attr_unique_id = f"{self.glances_data.config_entry.entry_id}-{sensor_name_prefix}-{description.key}"
|
||||
|
||||
@property
|
||||
def available(self):
|
||||
def available(self) -> bool:
|
||||
"""Could the device be accessed during the last update call."""
|
||||
return self.glances_data.available
|
||||
|
||||
|
@ -351,7 +351,7 @@ class GlancesSensor(SensorEntity):
|
|||
"""Return the state of the resources."""
|
||||
return self._state
|
||||
|
||||
async def async_added_to_hass(self):
|
||||
async def async_added_to_hass(self) -> None:
|
||||
"""Handle entity which will be added."""
|
||||
self.unsub_update = async_dispatcher_connect(
|
||||
self.hass, DATA_UPDATED, self._schedule_immediate_update
|
||||
|
|
|
@ -186,7 +186,7 @@ class GoogleTravelTimeSensor(SensorEntity):
|
|||
await self.hass.async_add_executor_job(self.update)
|
||||
self.async_write_ha_state()
|
||||
|
||||
def update(self):
|
||||
def update(self) -> None:
|
||||
"""Get the latest data from Google."""
|
||||
options_copy = self._config_entry.options.copy()
|
||||
dtime = options_copy.get(CONF_DEPARTURE_TIME)
|
||||
|
|
|
@ -136,18 +136,23 @@ class GoogleWifiSensor(SensorEntity):
|
|||
|
||||
entity_description: GoogleWifiSensorEntityDescription
|
||||
|
||||
def __init__(self, api, name, description: GoogleWifiSensorEntityDescription):
|
||||
def __init__(
|
||||
self,
|
||||
api: GoogleWifiAPI,
|
||||
name: str,
|
||||
description: GoogleWifiSensorEntityDescription,
|
||||
) -> None:
|
||||
"""Initialize a Google Wifi sensor."""
|
||||
self.entity_description = description
|
||||
self._api = api
|
||||
self._attr_name = f"{name}_{description.key}"
|
||||
|
||||
@property
|
||||
def available(self):
|
||||
def available(self) -> bool:
|
||||
"""Return availability of Google Wifi API."""
|
||||
return self._api.available
|
||||
|
||||
def update(self):
|
||||
def update(self) -> None:
|
||||
"""Get the latest data from the Google Wifi API."""
|
||||
self._api.update()
|
||||
if self.available:
|
||||
|
|
|
@ -122,7 +122,7 @@ class GPSLoggerEntity(TrackerEntity, RestoreEntity):
|
|||
"""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."""
|
||||
await super().async_added_to_hass()
|
||||
self._unsub_dispatcher = async_dispatcher_connect(
|
||||
|
@ -158,7 +158,7 @@ class GPSLoggerEntity(TrackerEntity, RestoreEntity):
|
|||
}
|
||||
self._battery = attr.get(ATTR_BATTERY_LEVEL)
|
||||
|
||||
async def async_will_remove_from_hass(self):
|
||||
async def async_will_remove_from_hass(self) -> None:
|
||||
"""Clean up after entity before removal."""
|
||||
await super().async_will_remove_from_hass()
|
||||
self._unsub_dispatcher()
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
from typing import Any
|
||||
|
||||
from greeclimate.device import (
|
||||
TEMP_MAX,
|
||||
|
@ -166,7 +167,7 @@ class GreeClimateEntity(CoordinatorEntity, ClimateEntity):
|
|||
"""Return the target temperature for the device."""
|
||||
return self.coordinator.device.target_temperature
|
||||
|
||||
async def async_set_temperature(self, **kwargs):
|
||||
async def async_set_temperature(self, **kwargs: Any) -> None:
|
||||
"""Set new target temperature."""
|
||||
if ATTR_TEMPERATURE not in kwargs:
|
||||
raise ValueError(f"Missing parameter {ATTR_TEMPERATURE}")
|
||||
|
@ -265,7 +266,7 @@ class GreeClimateEntity(CoordinatorEntity, ClimateEntity):
|
|||
return PRESET_BOOST
|
||||
return PRESET_NONE
|
||||
|
||||
async def async_set_preset_mode(self, preset_mode):
|
||||
async def async_set_preset_mode(self, preset_mode: str) -> None:
|
||||
"""Set new preset mode."""
|
||||
if preset_mode not in PRESET_MODES:
|
||||
raise ValueError(f"Invalid preset mode: {preset_mode}")
|
||||
|
@ -304,7 +305,7 @@ class GreeClimateEntity(CoordinatorEntity, ClimateEntity):
|
|||
speed = self.coordinator.device.fan_speed
|
||||
return FAN_MODES.get(speed)
|
||||
|
||||
async def async_set_fan_mode(self, fan_mode):
|
||||
async def async_set_fan_mode(self, fan_mode: str) -> None:
|
||||
"""Set new target fan mode."""
|
||||
if fan_mode not in FAN_MODES_REVERSE:
|
||||
raise ValueError(f"Invalid fan mode: {fan_mode}")
|
||||
|
@ -332,7 +333,7 @@ class GreeClimateEntity(CoordinatorEntity, ClimateEntity):
|
|||
return SWING_VERTICAL
|
||||
return SWING_OFF
|
||||
|
||||
async def async_set_swing_mode(self, swing_mode):
|
||||
async def async_set_swing_mode(self, swing_mode: str) -> None:
|
||||
"""Set new target swing operation."""
|
||||
if swing_mode not in SWING_MODES:
|
||||
raise ValueError(f"Invalid swing mode: {swing_mode}")
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
"""Support for interface with a Gree climate systems."""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.components.switch import SwitchDeviceClass, SwitchEntity
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
|
@ -60,13 +62,13 @@ class GreePanelLightSwitchEntity(GreeEntity, SwitchEntity):
|
|||
"""Return if the light is turned on."""
|
||||
return self.coordinator.device.light
|
||||
|
||||
async def async_turn_on(self, **kwargs):
|
||||
async def async_turn_on(self, **kwargs: Any) -> None:
|
||||
"""Turn the entity on."""
|
||||
self.coordinator.device.light = True
|
||||
await self.coordinator.push_state_update()
|
||||
self.async_write_ha_state()
|
||||
|
||||
async def async_turn_off(self, **kwargs):
|
||||
async def async_turn_off(self, **kwargs: Any) -> None:
|
||||
"""Turn the entity off."""
|
||||
self.coordinator.device.light = False
|
||||
await self.coordinator.push_state_update()
|
||||
|
@ -90,13 +92,13 @@ class GreeQuietModeSwitchEntity(GreeEntity, SwitchEntity):
|
|||
"""Return if the state is turned on."""
|
||||
return self.coordinator.device.quiet
|
||||
|
||||
async def async_turn_on(self, **kwargs):
|
||||
async def async_turn_on(self, **kwargs: Any) -> None:
|
||||
"""Turn the entity on."""
|
||||
self.coordinator.device.quiet = True
|
||||
await self.coordinator.push_state_update()
|
||||
self.async_write_ha_state()
|
||||
|
||||
async def async_turn_off(self, **kwargs):
|
||||
async def async_turn_off(self, **kwargs: Any) -> None:
|
||||
"""Turn the entity off."""
|
||||
self.coordinator.device.quiet = False
|
||||
await self.coordinator.push_state_update()
|
||||
|
@ -120,13 +122,13 @@ class GreeFreshAirSwitchEntity(GreeEntity, SwitchEntity):
|
|||
"""Return if the state is turned on."""
|
||||
return self.coordinator.device.fresh_air
|
||||
|
||||
async def async_turn_on(self, **kwargs):
|
||||
async def async_turn_on(self, **kwargs: Any) -> None:
|
||||
"""Turn the entity on."""
|
||||
self.coordinator.device.fresh_air = True
|
||||
await self.coordinator.push_state_update()
|
||||
self.async_write_ha_state()
|
||||
|
||||
async def async_turn_off(self, **kwargs):
|
||||
async def async_turn_off(self, **kwargs: Any) -> None:
|
||||
"""Turn the entity off."""
|
||||
self.coordinator.device.fresh_air = False
|
||||
await self.coordinator.push_state_update()
|
||||
|
@ -150,13 +152,13 @@ class GreeXFanSwitchEntity(GreeEntity, SwitchEntity):
|
|||
"""Return if the state is turned on."""
|
||||
return self.coordinator.device.xfan
|
||||
|
||||
async def async_turn_on(self, **kwargs):
|
||||
async def async_turn_on(self, **kwargs: Any) -> None:
|
||||
"""Turn the entity on."""
|
||||
self.coordinator.device.xfan = True
|
||||
await self.coordinator.push_state_update()
|
||||
self.async_write_ha_state()
|
||||
|
||||
async def async_turn_off(self, **kwargs):
|
||||
async def async_turn_off(self, **kwargs: Any) -> None:
|
||||
"""Turn the entity off."""
|
||||
self.coordinator.device.xfan = False
|
||||
await self.coordinator.push_state_update()
|
||||
|
|
|
@ -171,7 +171,7 @@ class GrowattInverter(SensorEntity):
|
|||
return self.probe.get_data("currency")
|
||||
return super().native_unit_of_measurement
|
||||
|
||||
def update(self):
|
||||
def update(self) -> None:
|
||||
"""Get the latest data from the Growat API and updates the state."""
|
||||
self.probe.update()
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
from typing import Any
|
||||
|
||||
from gsp import GstreamerPlayer
|
||||
import voluptuous as vol
|
||||
|
@ -78,7 +79,7 @@ class GstreamerDevice(MediaPlayerEntity):
|
|||
self._artist = None
|
||||
self._album = None
|
||||
|
||||
def update(self):
|
||||
def update(self) -> None:
|
||||
"""Update properties."""
|
||||
self._state = self._player.state
|
||||
self._volume = self._player.volume
|
||||
|
@ -88,11 +89,13 @@ class GstreamerDevice(MediaPlayerEntity):
|
|||
self._album = self._player.album
|
||||
self._artist = self._player.artist
|
||||
|
||||
def set_volume_level(self, volume):
|
||||
def set_volume_level(self, volume: float) -> None:
|
||||
"""Set the volume level."""
|
||||
self._player.volume = volume
|
||||
|
||||
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:
|
||||
"""Play media."""
|
||||
# Handle media_source
|
||||
if media_source.is_media_source_id(media_id):
|
||||
|
@ -109,15 +112,15 @@ class GstreamerDevice(MediaPlayerEntity):
|
|||
|
||||
await self.hass.async_add_executor_job(self._player.queue, media_id)
|
||||
|
||||
def media_play(self):
|
||||
def media_play(self) -> None:
|
||||
"""Play."""
|
||||
self._player.play()
|
||||
|
||||
def media_pause(self):
|
||||
def media_pause(self) -> None:
|
||||
"""Pause."""
|
||||
self._player.pause()
|
||||
|
||||
def media_next_track(self):
|
||||
def media_next_track(self) -> None:
|
||||
"""Next track."""
|
||||
self._player.next()
|
||||
|
||||
|
@ -167,7 +170,7 @@ class GstreamerDevice(MediaPlayerEntity):
|
|||
return self._album
|
||||
|
||||
async def async_browse_media(
|
||||
self, media_content_type=None, media_content_id=None
|
||||
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(
|
||||
|
|
Loading…
Reference in New Issue