From 6355e682fa4aeb526570597d919ad1fb76755b9a Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Mon, 5 Sep 2022 10:59:36 +0200 Subject: [PATCH] Improve entity type hints [m] (#77816) --- .../components/magicseaweed/sensor.py | 2 +- .../components/maxcube/binary_sensor.py | 2 +- homeassistant/components/maxcube/climate.py | 7 +-- homeassistant/components/mazda/switch.py | 6 ++- homeassistant/components/meater/sensor.py | 2 +- .../components/mediaroom/media_player.py | 22 ++++----- homeassistant/components/melcloud/climate.py | 6 +-- homeassistant/components/melcloud/sensor.py | 2 +- .../components/melcloud/water_heater.py | 8 ++-- homeassistant/components/melissa/climate.py | 7 +-- homeassistant/components/mfi/sensor.py | 2 +- homeassistant/components/mfi/switch.py | 7 +-- homeassistant/components/mill/climate.py | 8 ++-- homeassistant/components/min_max/sensor.py | 2 +- .../components/mobile_app/device_tracker.py | 4 +- .../components/moehlenhoff_alpha2/climate.py | 3 +- .../components/mold_indicator/sensor.py | 4 +- .../components/monoprice/media_player.py | 18 +++---- .../components/motion_blinds/sensor.py | 12 ++--- homeassistant/components/mpd/media_player.py | 48 +++++++++++-------- homeassistant/components/mqtt/scene.py | 3 +- homeassistant/components/mqtt_room/sensor.py | 4 +- homeassistant/components/mvglive/sensor.py | 2 +- homeassistant/components/mystrom/switch.py | 7 +-- 24 files changed, 103 insertions(+), 85 deletions(-) diff --git a/homeassistant/components/magicseaweed/sensor.py b/homeassistant/components/magicseaweed/sensor.py index 38559f607a4..b0b2e92ada5 100644 --- a/homeassistant/components/magicseaweed/sensor.py +++ b/homeassistant/components/magicseaweed/sensor.py @@ -157,7 +157,7 @@ class MagicSeaweedSensor(SensorEntity): """Return the unit system of this entity.""" return self._unit_system - def update(self): + def update(self) -> None: """Get the latest data from Magicseaweed and updates the states.""" self.data.update() if self.hour is None: diff --git a/homeassistant/components/maxcube/binary_sensor.py b/homeassistant/components/maxcube/binary_sensor.py index f674ec38d37..c6c9ba8ebb0 100644 --- a/homeassistant/components/maxcube/binary_sensor.py +++ b/homeassistant/components/maxcube/binary_sensor.py @@ -43,7 +43,7 @@ class MaxCubeBinarySensorBase(BinarySensorEntity): self._device = device self._room = handler.cube.room_by_id(device.room_id) - def update(self): + def update(self) -> None: """Get latest data from MAX! Cube.""" self._cubehandle.update() diff --git a/homeassistant/components/maxcube/climate.py b/homeassistant/components/maxcube/climate.py index c5d04ae599c..61abde40a37 100644 --- a/homeassistant/components/maxcube/climate.py +++ b/homeassistant/components/maxcube/climate.py @@ -3,6 +3,7 @@ from __future__ import annotations import logging import socket +from typing import Any from maxcube.device import ( MAX_DEVICE_MODE_AUTOMATIC, @@ -183,7 +184,7 @@ class MaxCubeClimate(ClimateEntity): return None return temp - def set_temperature(self, **kwargs): + def set_temperature(self, **kwargs: Any) -> None: """Set new target temperatures.""" if (temp := kwargs.get(ATTR_TEMPERATURE)) is None: raise ValueError( @@ -207,7 +208,7 @@ class MaxCubeClimate(ClimateEntity): return PRESET_AWAY return PRESET_NONE - def set_preset_mode(self, preset_mode): + def set_preset_mode(self, preset_mode: str) -> None: """Set new operation mode.""" if preset_mode == PRESET_COMFORT: self._set_target(MAX_DEVICE_MODE_MANUAL, self._device.comfort_temperature) @@ -231,6 +232,6 @@ class MaxCubeClimate(ClimateEntity): return {} return {ATTR_VALVE_POSITION: self._device.valve_position} - def update(self): + def update(self) -> None: """Get latest data from MAX! Cube.""" self._cubehandle.update() diff --git a/homeassistant/components/mazda/switch.py b/homeassistant/components/mazda/switch.py index 844585720d7..7097237bc5d 100644 --- a/homeassistant/components/mazda/switch.py +++ b/homeassistant/components/mazda/switch.py @@ -1,4 +1,6 @@ """Platform for Mazda switch integration.""" +from typing import Any + from pymazda import Client as MazdaAPIClient from homeassistant.components.switch import SwitchEntity @@ -57,13 +59,13 @@ class MazdaChargingSwitch(MazdaEntity, SwitchEntity): self.async_write_ha_state() - async def async_turn_on(self, **kwargs): + async def async_turn_on(self, **kwargs: Any) -> None: """Start charging the vehicle.""" await self.client.start_charging(self.vehicle_id) await self.refresh_status_and_write_state() - async def async_turn_off(self, **kwargs): + async def async_turn_off(self, **kwargs: Any) -> None: """Stop charging the vehicle.""" await self.client.stop_charging(self.vehicle_id) diff --git a/homeassistant/components/meater/sensor.py b/homeassistant/components/meater/sensor.py index a2753a42307..8322b9a0202 100644 --- a/homeassistant/components/meater/sensor.py +++ b/homeassistant/components/meater/sensor.py @@ -215,7 +215,7 @@ class MeaterProbeTemperature( return self.entity_description.value(device) @property - def available(self): + def available(self) -> bool: """Return if entity is available.""" # See if the device was returned from the API. If not, it's offline return ( diff --git a/homeassistant/components/mediaroom/media_player.py b/homeassistant/components/mediaroom/media_player.py index f3139f9c491..6dd267e7a12 100644 --- a/homeassistant/components/mediaroom/media_player.py +++ b/homeassistant/components/mediaroom/media_player.py @@ -170,7 +170,7 @@ class MediaroomDevice(MediaPlayerEntity): """Return True if entity is available.""" return self._available - async def async_added_to_hass(self): + async def async_added_to_hass(self) -> None: """Retrieve latest state.""" async def async_notify_received(notify): @@ -247,7 +247,7 @@ class MediaroomDevice(MediaPlayerEntity): """Channel currently playing.""" return self._channel - async def async_turn_on(self): + async def async_turn_on(self) -> None: """Turn on the receiver.""" try: @@ -259,7 +259,7 @@ class MediaroomDevice(MediaPlayerEntity): self._available = False self.async_write_ha_state() - async def async_turn_off(self): + async def async_turn_off(self) -> None: """Turn off the receiver.""" try: @@ -271,7 +271,7 @@ class MediaroomDevice(MediaPlayerEntity): self._available = False self.async_write_ha_state() - async def async_media_play(self): + async def async_media_play(self) -> None: """Send play command.""" try: @@ -284,7 +284,7 @@ class MediaroomDevice(MediaPlayerEntity): self._available = False self.async_write_ha_state() - async def async_media_pause(self): + async def async_media_pause(self) -> None: """Send pause command.""" try: @@ -296,7 +296,7 @@ class MediaroomDevice(MediaPlayerEntity): self._available = False self.async_write_ha_state() - async def async_media_stop(self): + async def async_media_stop(self) -> None: """Send stop command.""" try: @@ -308,7 +308,7 @@ class MediaroomDevice(MediaPlayerEntity): self._available = False self.async_write_ha_state() - async def async_media_previous_track(self): + async def async_media_previous_track(self) -> None: """Send Program Down command.""" try: @@ -320,7 +320,7 @@ class MediaroomDevice(MediaPlayerEntity): self._available = False self.async_write_ha_state() - async def async_media_next_track(self): + async def async_media_next_track(self) -> None: """Send Program Up command.""" try: @@ -332,7 +332,7 @@ class MediaroomDevice(MediaPlayerEntity): self._available = False self.async_write_ha_state() - async def async_volume_up(self): + async def async_volume_up(self) -> None: """Send volume up command.""" try: @@ -342,7 +342,7 @@ class MediaroomDevice(MediaPlayerEntity): self._available = False self.async_write_ha_state() - async def async_volume_down(self): + async def async_volume_down(self) -> None: """Send volume up command.""" try: @@ -351,7 +351,7 @@ class MediaroomDevice(MediaPlayerEntity): self._available = False self.async_write_ha_state() - async def async_mute_volume(self, mute): + async def async_mute_volume(self, mute: bool) -> None: """Send mute command.""" try: diff --git a/homeassistant/components/melcloud/climate.py b/homeassistant/components/melcloud/climate.py index a0ffe3a68bb..7f2e2e5c6ca 100644 --- a/homeassistant/components/melcloud/climate.py +++ b/homeassistant/components/melcloud/climate.py @@ -105,7 +105,7 @@ class MelCloudClimate(ClimateEntity): self.api = device self._base_device = self.api.device - async def async_update(self): + async def async_update(self) -> None: """Update state from MELCloud.""" await self.api.async_update() @@ -257,7 +257,7 @@ class AtaDeviceClimate(MelCloudClimate): """Return vertical vane position or mode.""" return self._device.vane_vertical - async def async_set_swing_mode(self, swing_mode) -> None: + async def async_set_swing_mode(self, swing_mode: str) -> None: """Set vertical vane position or mode.""" await self.async_set_vane_vertical(swing_mode) @@ -362,7 +362,7 @@ class AtwDeviceZoneClimate(MelCloudClimate): """Return the temperature we try to reach.""" return self._zone.target_temperature - async def async_set_temperature(self, **kwargs) -> None: + async def async_set_temperature(self, **kwargs: Any) -> None: """Set new target temperature.""" await self._zone.set_target_temperature( kwargs.get("temperature", self.target_temperature) diff --git a/homeassistant/components/melcloud/sensor.py b/homeassistant/components/melcloud/sensor.py index ed0eac98989..f9fdfa3a161 100644 --- a/homeassistant/components/melcloud/sensor.py +++ b/homeassistant/components/melcloud/sensor.py @@ -165,7 +165,7 @@ class MelDeviceSensor(SensorEntity): """Return the state of the sensor.""" return self.entity_description.value_fn(self._api) - async def async_update(self): + async def async_update(self) -> None: """Retrieve latest state.""" await self._api.async_update() diff --git a/homeassistant/components/melcloud/water_heater.py b/homeassistant/components/melcloud/water_heater.py index 58da39b1a61..49c642d562d 100644 --- a/homeassistant/components/melcloud/water_heater.py +++ b/homeassistant/components/melcloud/water_heater.py @@ -1,6 +1,8 @@ """Platform for water_heater integration.""" from __future__ import annotations +from typing import Any + from pymelcloud import DEVICE_TYPE_ATW, AtwDevice from pymelcloud.atw_device import ( PROPERTY_OPERATION_MODE, @@ -51,7 +53,7 @@ class AtwWaterHeater(WaterHeaterEntity): self._device = device self._name = device.name - async def async_update(self): + async def async_update(self) -> None: """Update state from MELCloud.""" await self._api.async_update() @@ -109,7 +111,7 @@ class AtwWaterHeater(WaterHeaterEntity): """Return the temperature we try to reach.""" return self._device.target_tank_temperature - async def async_set_temperature(self, **kwargs): + async def async_set_temperature(self, **kwargs: Any) -> None: """Set new target temperature.""" await self._device.set( { @@ -119,7 +121,7 @@ class AtwWaterHeater(WaterHeaterEntity): } ) - async def async_set_operation_mode(self, operation_mode): + async def async_set_operation_mode(self, operation_mode: str) -> None: """Set new target operation mode.""" await self._device.set({PROPERTY_OPERATION_MODE: operation_mode}) diff --git a/homeassistant/components/melissa/climate.py b/homeassistant/components/melissa/climate.py index 7dae7c2dad6..56278710fd2 100644 --- a/homeassistant/components/melissa/climate.py +++ b/homeassistant/components/melissa/climate.py @@ -2,6 +2,7 @@ from __future__ import annotations import logging +from typing import Any from homeassistant.components.climate import ClimateEntity from homeassistant.components.climate.const import ( @@ -135,12 +136,12 @@ class MelissaClimate(ClimateEntity): """Return the maximum supported temperature for the thermostat.""" return 30 - async def async_set_temperature(self, **kwargs): + async def async_set_temperature(self, **kwargs: Any) -> None: """Set new target temperature.""" temp = kwargs.get(ATTR_TEMPERATURE) await self.async_send({self._api.TEMP: temp}) - async def async_set_fan_mode(self, fan_mode): + async def async_set_fan_mode(self, fan_mode: str) -> None: """Set fan mode.""" melissa_fan_mode = self.hass_fan_to_melissa(fan_mode) await self.async_send({self._api.FAN: melissa_fan_mode}) @@ -168,7 +169,7 @@ class MelissaClimate(ClimateEntity): ): self._cur_settings = old_value - async def async_update(self): + async def async_update(self) -> None: """Get latest data from Melissa.""" try: self._data = (await self._api.async_status(cached=True))[ diff --git a/homeassistant/components/mfi/sensor.py b/homeassistant/components/mfi/sensor.py index 34a56641d2d..de7e661d9d2 100644 --- a/homeassistant/components/mfi/sensor.py +++ b/homeassistant/components/mfi/sensor.py @@ -143,6 +143,6 @@ class MfiSensor(SensorEntity): return "State" return tag - def update(self): + def update(self) -> None: """Get the latest data.""" self._port.refresh() diff --git a/homeassistant/components/mfi/switch.py b/homeassistant/components/mfi/switch.py index 76a55e46ba1..a25d0dfc87b 100644 --- a/homeassistant/components/mfi/switch.py +++ b/homeassistant/components/mfi/switch.py @@ -2,6 +2,7 @@ from __future__ import annotations import logging +from typing import Any from mficlient.client import FailedToLogin, MFiClient import requests @@ -94,19 +95,19 @@ class MfiSwitch(SwitchEntity): """Return true if the device is on.""" return self._port.output - def update(self): + def update(self) -> None: """Get the latest state and update the state.""" self._port.refresh() if self._target_state is not None: self._port.data["output"] = float(self._target_state) self._target_state = None - def turn_on(self, **kwargs): + def turn_on(self, **kwargs: Any) -> None: """Turn the switch on.""" self._port.control(True) self._target_state = True - def turn_off(self, **kwargs): + def turn_off(self, **kwargs: Any) -> None: """Turn the switch off.""" self._port.control(False) self._target_state = False diff --git a/homeassistant/components/mill/climate.py b/homeassistant/components/mill/climate.py index 44c7f980274..fbe4ad44710 100644 --- a/homeassistant/components/mill/climate.py +++ b/homeassistant/components/mill/climate.py @@ -1,4 +1,6 @@ """Support for mill wifi-enabled home heaters.""" +from typing import Any + import mill import voluptuous as vol @@ -123,7 +125,7 @@ class MillHeater(CoordinatorEntity, ClimateEntity): self._update_attr(heater) - 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 @@ -132,7 +134,7 @@ class MillHeater(CoordinatorEntity, ClimateEntity): ) await self.coordinator.async_request_refresh() - 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.""" fan_status = 1 if fan_mode == FAN_ON else 0 await self.coordinator.mill_data_connection.heater_control( @@ -221,7 +223,7 @@ class LocalMillHeater(CoordinatorEntity, ClimateEntity): self._update_attr() - 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 diff --git a/homeassistant/components/min_max/sensor.py b/homeassistant/components/min_max/sensor.py index c5a51cdda7a..615aebc8e39 100644 --- a/homeassistant/components/min_max/sensor.py +++ b/homeassistant/components/min_max/sensor.py @@ -184,7 +184,7 @@ class MinMaxSensor(SensorEntity): self.count_sensors = len(self._entity_ids) self.states = {} - async def async_added_to_hass(self): + async def async_added_to_hass(self) -> None: """Handle added to Hass.""" self.async_on_remove( async_track_state_change_event( diff --git a/homeassistant/components/mobile_app/device_tracker.py b/homeassistant/components/mobile_app/device_tracker.py index d0f1db6caff..ef1acdaf32d 100644 --- a/homeassistant/components/mobile_app/device_tracker.py +++ b/homeassistant/components/mobile_app/device_tracker.py @@ -112,7 +112,7 @@ class MobileAppEntity(TrackerEntity, RestoreEntity): """Return the device info.""" return device_info(self._entry.data) - 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() self._dispatch_unsub = async_dispatcher_connect( @@ -138,7 +138,7 @@ class MobileAppEntity(TrackerEntity, RestoreEntity): data.update({key: attr[key] for key in attr if key in ATTR_KEYS}) self._data = data - async def async_will_remove_from_hass(self): + async def async_will_remove_from_hass(self) -> None: """Call when entity is being removed from hass.""" await super().async_will_remove_from_hass() diff --git a/homeassistant/components/moehlenhoff_alpha2/climate.py b/homeassistant/components/moehlenhoff_alpha2/climate.py index e14f4801661..b68e48f83c7 100644 --- a/homeassistant/components/moehlenhoff_alpha2/climate.py +++ b/homeassistant/components/moehlenhoff_alpha2/climate.py @@ -1,5 +1,6 @@ """Support for Alpha2 room control unit via Alpha2 base.""" import logging +from typing import Any from homeassistant.components.climate import ClimateEntity from homeassistant.components.climate.const import ( @@ -110,7 +111,7 @@ class Alpha2Climate(CoordinatorEntity[Alpha2BaseCoordinator], ClimateEntity): self.coordinator.data["heat_areas"][self.heat_area_id].get("T_TARGET", 0.0) ) - async def async_set_temperature(self, **kwargs) -> None: + async def async_set_temperature(self, **kwargs: Any) -> None: """Set new target temperatures.""" if (target_temperature := kwargs.get(ATTR_TEMPERATURE)) is None: return diff --git a/homeassistant/components/mold_indicator/sensor.py b/homeassistant/components/mold_indicator/sensor.py index db4f8d069ab..23c5e639d7f 100644 --- a/homeassistant/components/mold_indicator/sensor.py +++ b/homeassistant/components/mold_indicator/sensor.py @@ -112,7 +112,7 @@ class MoldIndicator(SensorEntity): self._indoor_hum = None self._crit_temp = None - async def async_added_to_hass(self): + async def async_added_to_hass(self) -> None: """Register callbacks.""" @callback @@ -273,7 +273,7 @@ class MoldIndicator(SensorEntity): return hum - async def async_update(self): + async def async_update(self) -> None: """Calculate latest state.""" _LOGGER.debug("Update state for %s", self.entity_id) # check all sensors diff --git a/homeassistant/components/monoprice/media_player.py b/homeassistant/components/monoprice/media_player.py index 627d95427e2..19692b43854 100644 --- a/homeassistant/components/monoprice/media_player.py +++ b/homeassistant/components/monoprice/media_player.py @@ -142,7 +142,7 @@ class MonopriceZone(MediaPlayerEntity): self._mute = None self._update_success = True - def update(self): + def update(self) -> None: """Retrieve latest state.""" try: state = self._monoprice.zone_status(self._zone_id) @@ -165,7 +165,7 @@ class MonopriceZone(MediaPlayerEntity): self._source = None @property - def entity_registry_enabled_default(self): + def entity_registry_enabled_default(self) -> bool: """Return if the entity should be enabled when first added to the entity registry.""" return self._zone_id < 20 or self._update_success @@ -231,36 +231,36 @@ class MonopriceZone(MediaPlayerEntity): self._monoprice.restore_zone(self._snapshot) self.schedule_update_ha_state(True) - def select_source(self, source): + def select_source(self, source: str) -> None: """Set input source.""" if source not in self._source_name_id: return idx = self._source_name_id[source] self._monoprice.set_source(self._zone_id, idx) - def turn_on(self): + def turn_on(self) -> None: """Turn the media player on.""" self._monoprice.set_power(self._zone_id, True) - def turn_off(self): + def turn_off(self) -> None: """Turn the media player off.""" self._monoprice.set_power(self._zone_id, False) - def mute_volume(self, mute): + def mute_volume(self, mute: bool) -> None: """Mute (true) or unmute (false) media player.""" self._monoprice.set_mute(self._zone_id, mute) - def set_volume_level(self, volume): + def set_volume_level(self, volume: float) -> None: """Set volume level, range 0..1.""" self._monoprice.set_volume(self._zone_id, int(volume * 38)) - def volume_up(self): + def volume_up(self) -> None: """Volume up the media player.""" if self._volume is None: return self._monoprice.set_volume(self._zone_id, min(self._volume + 1, 38)) - def volume_down(self): + def volume_down(self) -> None: """Volume down media player.""" if self._volume is None: return diff --git a/homeassistant/components/motion_blinds/sensor.py b/homeassistant/components/motion_blinds/sensor.py index 3a6f775092e..04b7a91fe31 100644 --- a/homeassistant/components/motion_blinds/sensor.py +++ b/homeassistant/components/motion_blinds/sensor.py @@ -61,7 +61,7 @@ class MotionBatterySensor(CoordinatorEntity, SensorEntity): self._attr_unique_id = f"{blind.mac}-battery" @property - def available(self): + def available(self) -> bool: """Return True if entity is available.""" if self.coordinator.data is None: return False @@ -81,12 +81,12 @@ class MotionBatterySensor(CoordinatorEntity, SensorEntity): """Return device specific state attributes.""" return {ATTR_BATTERY_VOLTAGE: self._blind.battery_voltage} - async def async_added_to_hass(self): + async def async_added_to_hass(self) -> None: """Subscribe to multicast pushes.""" self._blind.Register_callback(self.unique_id, self.schedule_update_ha_state) await super().async_added_to_hass() - async def async_will_remove_from_hass(self): + async def async_will_remove_from_hass(self) -> None: """Unsubscribe when removed.""" self._blind.Remove_callback(self.unique_id) await super().async_will_remove_from_hass() @@ -145,7 +145,7 @@ class MotionSignalStrengthSensor(CoordinatorEntity, SensorEntity): self._attr_name = name @property - def available(self): + def available(self) -> bool: """Return True if entity is available.""" if self.coordinator.data is None: return False @@ -164,12 +164,12 @@ class MotionSignalStrengthSensor(CoordinatorEntity, SensorEntity): """Return the state of the sensor.""" return self._device.RSSI - async def async_added_to_hass(self): + async def async_added_to_hass(self) -> None: """Subscribe to multicast pushes.""" self._device.Register_callback(self.unique_id, self.schedule_update_ha_state) await super().async_added_to_hass() - async def async_will_remove_from_hass(self): + async def async_will_remove_from_hass(self) -> None: """Unsubscribe when removed.""" self._device.Remove_callback(self.unique_id) await super().async_will_remove_from_hass() diff --git a/homeassistant/components/mpd/media_player.py b/homeassistant/components/mpd/media_player.py index ecee057a653..4680870c3ec 100644 --- a/homeassistant/components/mpd/media_player.py +++ b/homeassistant/components/mpd/media_player.py @@ -6,6 +6,7 @@ from datetime import timedelta import hashlib import logging import os +from typing import Any import mpd from mpd.asyncio import MPDClient @@ -18,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 ( @@ -164,7 +166,7 @@ class MpdDevice(MediaPlayerEntity): """Return true if MPD is available and connected.""" return self._is_connected - async def async_update(self): + async def async_update(self) -> None: """Get the latest data and update the state.""" try: if not self._is_connected: @@ -273,7 +275,7 @@ class MpdDevice(MediaPlayerEntity): """Hash value for media image.""" return self._media_image_hash - async def async_get_media_image(self): + async def async_get_media_image(self) -> tuple[bytes | None, str | None]: """Fetch media image of current playing track.""" if not (file := self._currentsong.get("file")): return None, None @@ -380,12 +382,12 @@ class MpdDevice(MediaPlayerEntity): """Return the list of available input sources.""" return self._playlists - async def async_select_source(self, source): + async def async_select_source(self, source: str) -> None: """Choose a different available playlist and play it.""" await self.async_play_media(MEDIA_TYPE_PLAYLIST, source) @Throttle(PLAYLIST_UPDATE_INTERVAL) - async def _update_playlists(self, **kwargs): + async def _update_playlists(self, **kwargs: Any) -> None: """Update available MPD playlists.""" try: self._playlists = [] @@ -395,12 +397,12 @@ class MpdDevice(MediaPlayerEntity): self._playlists = None _LOGGER.warning("Playlists could not be updated: %s:", error) - async def async_set_volume_level(self, volume): + async def async_set_volume_level(self, volume: float) -> None: """Set volume of media player.""" if "volume" in self._status: await self._client.setvol(int(volume * 100)) - async def async_volume_up(self): + async def async_volume_up(self) -> None: """Service to send the MPD the command for volume up.""" if "volume" in self._status: current_volume = int(self._status["volume"]) @@ -408,7 +410,7 @@ class MpdDevice(MediaPlayerEntity): if current_volume <= 100: self._client.setvol(current_volume + 5) - async def async_volume_down(self): + async def async_volume_down(self) -> None: """Service to send the MPD the command for volume down.""" if "volume" in self._status: current_volume = int(self._status["volume"]) @@ -416,30 +418,30 @@ class MpdDevice(MediaPlayerEntity): if current_volume >= 0: await self._client.setvol(current_volume - 5) - async def async_media_play(self): + async def async_media_play(self) -> None: """Service to send the MPD the command for play/pause.""" if self._status["state"] == "pause": await self._client.pause(0) else: await self._client.play() - async def async_media_pause(self): + async def async_media_pause(self) -> None: """Service to send the MPD the command for play/pause.""" await self._client.pause(1) - async def async_media_stop(self): + async def async_media_stop(self) -> None: """Service to send the MPD the command for stop.""" await self._client.stop() - async def async_media_next_track(self): + async def async_media_next_track(self) -> None: """Service to send the MPD the command for next track.""" await self._client.next() - async def async_media_previous_track(self): + async def async_media_previous_track(self) -> None: """Service to send the MPD the command for previous track.""" await self._client.previous() - async def async_mute_volume(self, mute): + async def async_mute_volume(self, mute: bool) -> None: """Mute. Emulated with set_volume_level.""" if "volume" in self._status: if mute: @@ -449,7 +451,9 @@ class MpdDevice(MediaPlayerEntity): await self.async_set_volume_level(self._muted_volume) self._muted = mute - 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 media player the command for playing a playlist.""" if media_source.is_media_source_id(media_id): media_type = MEDIA_TYPE_MUSIC @@ -483,7 +487,7 @@ class MpdDevice(MediaPlayerEntity): return REPEAT_MODE_ALL return REPEAT_MODE_OFF - async def async_set_repeat(self, repeat): + async def async_set_repeat(self, repeat: str) -> None: """Set repeat mode.""" if repeat == REPEAT_MODE_OFF: await self._client.repeat(0) @@ -500,28 +504,30 @@ class MpdDevice(MediaPlayerEntity): """Boolean if shuffle is enabled.""" return bool(int(self._status["random"])) - async def async_set_shuffle(self, shuffle): + async def async_set_shuffle(self, shuffle: bool) -> None: """Enable/disable shuffle mode.""" await self._client.random(int(shuffle)) - async def async_turn_off(self): + async def async_turn_off(self) -> None: """Service to send the MPD the command to stop playing.""" await self._client.stop() - async def async_turn_on(self): + async def async_turn_on(self) -> None: """Service to send the MPD the command to start playing.""" await self._client.play() await self._update_playlists(no_throttle=True) - async def async_clear_playlist(self): + async def async_clear_playlist(self) -> None: """Clear players playlist.""" await self._client.clear() - async def async_media_seek(self, position): + async def async_media_seek(self, position: float) -> None: """Send seek command.""" await self._client.seekcur(position) - 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, diff --git a/homeassistant/components/mqtt/scene.py b/homeassistant/components/mqtt/scene.py index 62de54505eb..70a4cad7f37 100644 --- a/homeassistant/components/mqtt/scene.py +++ b/homeassistant/components/mqtt/scene.py @@ -2,6 +2,7 @@ from __future__ import annotations import functools +from typing import Any import voluptuous as vol @@ -125,7 +126,7 @@ class MqttScene( async def _subscribe_topics(self): """(Re)Subscribe to topics.""" - async def async_activate(self, **kwargs): + async def async_activate(self, **kwargs: Any) -> None: """Activate the scene. This method is a coroutine. diff --git a/homeassistant/components/mqtt_room/sensor.py b/homeassistant/components/mqtt_room/sensor.py index 276695d8edd..c1461157886 100644 --- a/homeassistant/components/mqtt_room/sensor.py +++ b/homeassistant/components/mqtt_room/sensor.py @@ -95,7 +95,7 @@ class MQTTRoomSensor(SensorEntity): self._distance = None self._updated = None - async def async_added_to_hass(self): + async def async_added_to_hass(self) -> None: """Subscribe to MQTT events.""" @callback @@ -152,7 +152,7 @@ class MQTTRoomSensor(SensorEntity): """Return the current room of the entity.""" return self._state - def update(self): + def update(self) -> None: """Update the state for absent devices.""" if ( self._updated diff --git a/homeassistant/components/mvglive/sensor.py b/homeassistant/components/mvglive/sensor.py index d3405d0cce7..089d7ac5fbc 100644 --- a/homeassistant/components/mvglive/sensor.py +++ b/homeassistant/components/mvglive/sensor.py @@ -141,7 +141,7 @@ class MVGLiveSensor(SensorEntity): """Return the unit this state is expressed in.""" return TIME_MINUTES - def update(self): + def update(self) -> None: """Get the latest data and update the state.""" self.data.update() if not self.data.departures: diff --git a/homeassistant/components/mystrom/switch.py b/homeassistant/components/mystrom/switch.py index 41303b25a9f..7bce3000424 100644 --- a/homeassistant/components/mystrom/switch.py +++ b/homeassistant/components/mystrom/switch.py @@ -2,6 +2,7 @@ from __future__ import annotations import logging +from typing import Any from pymystrom.exceptions import MyStromConnectionError from pymystrom.switch import MyStromSwitch as _MyStromSwitch @@ -77,21 +78,21 @@ class MyStromSwitch(SwitchEntity): """Could the device be accessed during the last update call.""" return self._available - async def async_turn_on(self, **kwargs): + async def async_turn_on(self, **kwargs: Any) -> None: """Turn the switch on.""" try: await self.plug.turn_on() except MyStromConnectionError: _LOGGER.error("No route to myStrom plug") - async def async_turn_off(self, **kwargs): + async def async_turn_off(self, **kwargs: Any) -> None: """Turn the switch off.""" try: await self.plug.turn_off() except MyStromConnectionError: _LOGGER.error("No route to myStrom plug") - async def async_update(self): + async def async_update(self) -> None: """Get the latest data from the device and update the data.""" try: await self.plug.get_state()