Improve entity type hints [s] (part 1/2) (#77881)

This commit is contained in:
epenet 2022-09-06 13:35:14 +02:00 committed by GitHub
parent 34da463df0
commit 0c767bd0d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 86 additions and 70 deletions

View File

@ -167,7 +167,7 @@ class SabnzbdSensor(SensorEntity):
name=DEFAULT_NAME, name=DEFAULT_NAME,
) )
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."""
self.async_on_remove( self.async_on_remove(
async_dispatcher_connect( async_dispatcher_connect(

View File

@ -73,7 +73,7 @@ class SatelIntegraBinarySensor(BinarySensorEntity):
self._react_to_signal = react_to_signal self._react_to_signal = react_to_signal
self._satel = controller self._satel = controller
async def async_added_to_hass(self): async def async_added_to_hass(self) -> None:
"""Register callbacks.""" """Register callbacks."""
if self._react_to_signal == SIGNAL_OUTPUTS_UPDATED: if self._react_to_signal == SIGNAL_OUTPUTS_UPDATED:
if self._device_number in self._satel.violated_outputs: if self._device_number in self._satel.violated_outputs:

View File

@ -2,6 +2,7 @@
from __future__ import annotations from __future__ import annotations
import logging import logging
from typing import Any
from homeassistant.components.switch import SwitchEntity from homeassistant.components.switch import SwitchEntity
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
@ -61,7 +62,7 @@ class SatelIntegraSwitch(SwitchEntity):
self._code = code self._code = code
self._satel = controller self._satel = controller
async def async_added_to_hass(self): async def async_added_to_hass(self) -> None:
"""Register callbacks.""" """Register callbacks."""
async_dispatcher_connect( async_dispatcher_connect(
self.hass, SIGNAL_OUTPUTS_UPDATED, self._devices_updated self.hass, SIGNAL_OUTPUTS_UPDATED, self._devices_updated
@ -78,13 +79,13 @@ class SatelIntegraSwitch(SwitchEntity):
self._state = new_state self._state = new_state
self.async_write_ha_state() self.async_write_ha_state()
async def async_turn_on(self, **kwargs): async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn the device on.""" """Turn the device on."""
_LOGGER.debug("Switch: %s status: %s, turning on", self._name, self._state) _LOGGER.debug("Switch: %s status: %s, turning on", self._name, self._state)
await self._satel.set_output(self._code, self._device_number, True) await self._satel.set_output(self._code, self._device_number, True)
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 device off.""" """Turn the device off."""
_LOGGER.debug( _LOGGER.debug(
"Switch name: %s status: %s, turning off", self._name, self._state "Switch name: %s status: %s, turning off", self._name, self._state

View File

@ -2,6 +2,7 @@
from __future__ import annotations from __future__ import annotations
import logging import logging
from typing import Any
from requests import RequestException from requests import RequestException
import voluptuous as vol import voluptuous as vol
@ -131,7 +132,7 @@ class SchluterThermostat(CoordinatorEntity, ClimateEntity):
async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None: async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
"""Mode is always heating, so do nothing.""" """Mode is always heating, so do nothing."""
def set_temperature(self, **kwargs): def set_temperature(self, **kwargs: Any) -> None:
"""Set new target temperature.""" """Set new target temperature."""
target_temp = None target_temp = None
target_temp = kwargs.get(ATTR_TEMPERATURE) target_temp = kwargs.get(ATTR_TEMPERATURE)

View File

@ -1,5 +1,6 @@
"""Support for a ScreenLogic heating device.""" """Support for a ScreenLogic heating device."""
import logging import logging
from typing import Any
from screenlogicpy.const import DATA as SL_DATA, EQUIPMENT, HEAT_MODE from screenlogicpy.const import DATA as SL_DATA, EQUIPMENT, HEAT_MODE
@ -130,7 +131,7 @@ class ScreenLogicClimate(ScreenlogicEntity, ClimateEntity, RestoreEntity):
HEAT_MODE.NAME_FOR_NUM[mode_num] for mode_num in self._configured_heat_modes HEAT_MODE.NAME_FOR_NUM[mode_num] for mode_num in self._configured_heat_modes
] ]
async def async_set_temperature(self, **kwargs) -> None: async def async_set_temperature(self, **kwargs: Any) -> None:
"""Change the setpoint of the heater.""" """Change the setpoint of the heater."""
if (temperature := kwargs.get(ATTR_TEMPERATURE)) is None: if (temperature := kwargs.get(ATTR_TEMPERATURE)) is None:
raise ValueError(f"Expected attribute {ATTR_TEMPERATURE}") raise ValueError(f"Expected attribute {ATTR_TEMPERATURE}")
@ -144,7 +145,7 @@ class ScreenLogicClimate(ScreenlogicEntity, ClimateEntity, RestoreEntity):
f"Failed to set_temperature {temperature} on body {self.body['body_type']['value']}" f"Failed to set_temperature {temperature} on body {self.body['body_type']['value']}"
) )
async def async_set_hvac_mode(self, hvac_mode) -> None: async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
"""Set the operation mode.""" """Set the operation mode."""
if hvac_mode == HVACMode.OFF: if hvac_mode == HVACMode.OFF:
mode = HEAT_MODE.OFF mode = HEAT_MODE.OFF
@ -172,7 +173,7 @@ class ScreenLogicClimate(ScreenlogicEntity, ClimateEntity, RestoreEntity):
f"Failed to set_preset_mode {mode} on body {self.body['body_type']['value']}" f"Failed to set_preset_mode {mode} on body {self.body['body_type']['value']}"
) )
async def async_added_to_hass(self): async def async_added_to_hass(self) -> None:
"""Run when entity is about to be added.""" """Run when entity is about to be added."""
await super().async_added_to_hass() await super().async_added_to_hass()

View File

@ -2,6 +2,7 @@
from __future__ import annotations from __future__ import annotations
import logging import logging
from typing import Any
from scsgate.messages import ScenarioTriggeredMessage, StateMessage from scsgate.messages import ScenarioTriggeredMessage, StateMessage
from scsgate.tasks import ToggleStatusTask from scsgate.tasks import ToggleStatusTask
@ -116,7 +117,7 @@ class SCSGateSwitch(SwitchEntity):
"""Return true if switch is on.""" """Return true if switch is on."""
return self._toggled return self._toggled
def turn_on(self, **kwargs): def turn_on(self, **kwargs: Any) -> None:
"""Turn the device on.""" """Turn the device on."""
self._scsgate.append_task(ToggleStatusTask(target=self._scs_id, toggled=True)) self._scsgate.append_task(ToggleStatusTask(target=self._scs_id, toggled=True))
@ -124,7 +125,7 @@ class SCSGateSwitch(SwitchEntity):
self._toggled = True self._toggled = True
self.schedule_update_ha_state() self.schedule_update_ha_state()
def turn_off(self, **kwargs): def turn_off(self, **kwargs: Any) -> None:
"""Turn the device off.""" """Turn the device off."""
self._scsgate.append_task(ToggleStatusTask(target=self._scs_id, toggled=False)) self._scsgate.append_task(ToggleStatusTask(target=self._scs_id, toggled=False))

View File

@ -126,7 +126,7 @@ class SenseDevice(BinarySensorEntity):
"""Return the device class of the binary sensor.""" """Return the device class of the binary sensor."""
return BinarySensorDeviceClass.POWER return BinarySensorDeviceClass.POWER
async def async_added_to_hass(self): async def async_added_to_hass(self) -> None:
"""Register callbacks.""" """Register callbacks."""
self.async_on_remove( self.async_on_remove(
async_dispatcher_connect( async_dispatcher_connect(

View File

@ -182,7 +182,7 @@ class SenseActiveSensor(SensorEntity):
self._variant_id = variant_id self._variant_id = variant_id
self._variant_name = variant_name self._variant_name = variant_name
async def async_added_to_hass(self): async def async_added_to_hass(self) -> None:
"""Register callbacks.""" """Register callbacks."""
self.async_on_remove( self.async_on_remove(
async_dispatcher_connect( async_dispatcher_connect(
@ -230,7 +230,7 @@ class SenseVoltageSensor(SensorEntity):
self._sense_monitor_id = sense_monitor_id self._sense_monitor_id = sense_monitor_id
self._voltage_index = index self._voltage_index = index
async def async_added_to_hass(self): async def async_added_to_hass(self) -> None:
"""Register callbacks.""" """Register callbacks."""
self.async_on_remove( self.async_on_remove(
async_dispatcher_connect( async_dispatcher_connect(
@ -323,7 +323,7 @@ class SenseEnergyDevice(SensorEntity):
self._attr_icon = sense_to_mdi(device["icon"]) self._attr_icon = sense_to_mdi(device["icon"])
self._sense_devices_data = sense_devices_data self._sense_devices_data = sense_devices_data
async def async_added_to_hass(self): async def async_added_to_hass(self) -> None:
"""Register callbacks.""" """Register callbacks."""
self.async_on_remove( self.async_on_remove(
async_dispatcher_connect( async_dispatcher_connect(

View File

@ -143,7 +143,7 @@ class SerialSensor(SensorEntity):
self._template = value_template self._template = value_template
self._attributes = None self._attributes = 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.""" """Handle when an entity is about to be added to Home Assistant."""
self._serial_loop_task = self.hass.loop.create_task( self._serial_loop_task = self.hass.loop.create_task(
self.serial_read( self.serial_read(

View File

@ -90,7 +90,7 @@ class ParticulateMatterSensor(SensorEntity):
"""Return the unit of measurement of this entity, if any.""" """Return the unit of measurement of this entity, if any."""
return CONCENTRATION_MICROGRAMS_PER_CUBIC_METER return CONCENTRATION_MICROGRAMS_PER_CUBIC_METER
def update(self): def update(self) -> None:
"""Read from sensor and update the state.""" """Read from sensor and update the state."""
_LOGGER.debug("Reading data from PM sensor") _LOGGER.debug("Reading data from PM sensor")
try: try:

View File

@ -134,7 +134,7 @@ class SeventeenTrackSummarySensor(SensorEntity):
"""Return the state.""" """Return the state."""
return self._state return self._state
async def async_update(self): async def async_update(self) -> None:
"""Update the sensor.""" """Update the sensor."""
await self._data.async_update() await self._data.async_update()
@ -189,7 +189,7 @@ class SeventeenTrackPackageSensor(SensorEntity):
) )
@property @property
def available(self): def available(self) -> bool:
"""Return whether the entity is available.""" """Return whether the entity is available."""
return self._data.packages.get(self._tracking_number) is not None return self._data.packages.get(self._tracking_number) is not None
@ -205,7 +205,7 @@ class SeventeenTrackPackageSensor(SensorEntity):
"""Return the state.""" """Return the state."""
return self._state return self._state
async def async_update(self): async def async_update(self) -> None:
"""Update the sensor.""" """Update the sensor."""
await self._data.async_update() await self._data.async_update()

View File

@ -149,7 +149,7 @@ class SigfoxDevice(SensorEntity):
"time": epoch_to_datetime(epoch_time), "time": epoch_to_datetime(epoch_time),
} }
def update(self): def update(self) -> None:
"""Fetch the latest device message.""" """Fetch the latest device message."""
self._message_data = self.get_last_message() self._message_data = self.get_last_message()
self._state = self._message_data["payload"] self._state = self._message_data["payload"]

View File

@ -121,7 +121,7 @@ class SimulatedSensor(SensorEntity):
noise = self._random.gauss(mu=0, sigma=fwhm) noise = self._random.gauss(mu=0, sigma=fwhm)
return round(mean + periodic + noise, 3) return round(mean + periodic + noise, 3)
async def async_update(self): async def async_update(self) -> None:
"""Update the sensor.""" """Update the sensor."""
self._state = self.signal_calc() self._state = self.signal_calc()

View File

@ -65,11 +65,11 @@ class SisyphusPlayer(MediaPlayerEntity):
self._host = host self._host = host
self._table = table self._table = table
async def async_added_to_hass(self): async def async_added_to_hass(self) -> None:
"""Add listeners after this object has been initialized.""" """Add listeners after this object has been initialized."""
self._table.add_listener(self.async_write_ha_state) self._table.add_listener(self.async_write_ha_state)
async def async_update(self): async def async_update(self) -> None:
"""Force update table state.""" """Force update table state."""
await self._table.refresh() await self._table.refresh()
@ -79,7 +79,7 @@ class SisyphusPlayer(MediaPlayerEntity):
return self._table.id return self._table.id
@property @property
def available(self): def available(self) -> bool:
"""Return true if the table is responding to heartbeats.""" """Return true if the table is responding to heartbeats."""
return self._table.is_connected return self._table.is_connected
@ -113,7 +113,7 @@ class SisyphusPlayer(MediaPlayerEntity):
"""Return True if the current playlist is in shuffle mode.""" """Return True if the current playlist is in shuffle mode."""
return self._table.is_shuffle return self._table.is_shuffle
async def async_set_shuffle(self, shuffle): async def async_set_shuffle(self, shuffle: bool) -> None:
"""Change the shuffle mode of the current playlist.""" """Change the shuffle mode of the current playlist."""
await self._table.set_shuffle(shuffle) await self._table.set_shuffle(shuffle)
@ -164,35 +164,35 @@ class SisyphusPlayer(MediaPlayerEntity):
return super().media_image_url return super().media_image_url
async def async_turn_on(self): async def async_turn_on(self) -> None:
"""Wake up a sleeping table.""" """Wake up a sleeping table."""
await self._table.wakeup() await self._table.wakeup()
async def async_turn_off(self): async def async_turn_off(self) -> None:
"""Put the table to sleep.""" """Put the table to sleep."""
await self._table.sleep() await self._table.sleep()
async def async_volume_down(self): async def async_volume_down(self) -> None:
"""Slow down playback.""" """Slow down playback."""
await self._table.set_speed(max(0, self._table.speed - 0.1)) await self._table.set_speed(max(0, self._table.speed - 0.1))
async def async_volume_up(self): async def async_volume_up(self) -> None:
"""Speed up playback.""" """Speed up playback."""
await self._table.set_speed(min(1.0, self._table.speed + 0.1)) await self._table.set_speed(min(1.0, self._table.speed + 0.1))
async def async_set_volume_level(self, volume): async def async_set_volume_level(self, volume: float) -> None:
"""Set playback speed (0..1).""" """Set playback speed (0..1)."""
await self._table.set_speed(volume) await self._table.set_speed(volume)
async def async_media_play(self): async def async_media_play(self) -> None:
"""Start playing.""" """Start playing."""
await self._table.play() await self._table.play()
async def async_media_pause(self): async def async_media_pause(self) -> None:
"""Pause.""" """Pause."""
await self._table.pause() await self._table.pause()
async def async_media_next_track(self): async def async_media_next_track(self) -> None:
"""Skip to next track.""" """Skip to next track."""
cur_track_index = self._get_current_track_index() cur_track_index = self._get_current_track_index()
@ -200,7 +200,7 @@ class SisyphusPlayer(MediaPlayerEntity):
self._table.active_playlist.tracks[cur_track_index + 1] self._table.active_playlist.tracks[cur_track_index + 1]
) )
async def async_media_previous_track(self): async def async_media_previous_track(self) -> None:
"""Skip to previous track.""" """Skip to previous track."""
cur_track_index = self._get_current_track_index() cur_track_index = self._get_current_track_index()

View File

@ -2,6 +2,7 @@
from __future__ import annotations from __future__ import annotations
import asyncio import asyncio
from typing import Any
from aioslimproto.client import PlayerState, SlimClient from aioslimproto.client import PlayerState, SlimClient
from aioslimproto.const import EventType, SlimEvent from aioslimproto.const import EventType, SlimEvent
@ -175,7 +176,9 @@ class SlimProtoPlayer(MediaPlayerEntity):
"""Turn off device.""" """Turn off device."""
await self.player.power(False) await self.player.power(False)
async def async_play_media(self, media_type: str, media_id: str, **kwargs) -> None: async def async_play_media(
self, media_type: str, media_id: str, **kwargs: Any
) -> None:
"""Send the play_media command to the media player.""" """Send the play_media command to the media player."""
to_send_media_type: str | None = media_type to_send_media_type: str | None = media_type
# Handle media_source # Handle media_source
@ -193,7 +196,7 @@ class SlimProtoPlayer(MediaPlayerEntity):
await self.player.play_url(media_id, mime_type=to_send_media_type) await self.player.play_url(media_id, mime_type=to_send_media_type)
async def async_browse_media( 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: ) -> BrowseMedia:
"""Implement the websocket media browsing helper.""" """Implement the websocket media browsing helper."""
return await media_source.async_browse_media( return await media_source.async_browse_media(

View File

@ -91,7 +91,7 @@ class SmappeePresence(BinarySensorEntity):
sw_version=self._service_location.firmware_version, sw_version=self._service_location.firmware_version,
) )
async def async_update(self): async def async_update(self) -> None:
"""Get the latest data from Smappee and update the state.""" """Get the latest data from Smappee and update the state."""
await self._smappee_base.async_update() await self._smappee_base.async_update()
@ -174,7 +174,7 @@ class SmappeeAppliance(BinarySensorEntity):
sw_version=self._service_location.firmware_version, sw_version=self._service_location.firmware_version,
) )
async def async_update(self): async def async_update(self) -> None:
"""Get the latest data from Smappee and update the state.""" """Get the latest data from Smappee and update the state."""
await self._smappee_base.async_update() await self._smappee_base.async_update()

View File

@ -388,7 +388,7 @@ class SmappeeSensor(SensorEntity):
sw_version=self._service_location.firmware_version, sw_version=self._service_location.firmware_version,
) )
async def async_update(self): async def async_update(self) -> None:
"""Get the latest data from Smappee and update the state.""" """Get the latest data from Smappee and update the state."""
await self._smappee_base.async_update() await self._smappee_base.async_update()

View File

@ -1,4 +1,6 @@
"""Support for interacting with Smappee Comport Plugs, Switches and Output Modules.""" """Support for interacting with Smappee Comport Plugs, Switches and Output Modules."""
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
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
@ -108,7 +110,7 @@ class SmappeeActuator(SwitchEntity):
"""Icon to use in the frontend.""" """Icon to use in the frontend."""
return ICON return ICON
def turn_on(self, **kwargs): def turn_on(self, **kwargs: Any) -> None:
"""Turn on Comport Plug.""" """Turn on Comport Plug."""
if self._actuator_type in ("SWITCH", "COMFORT_PLUG"): if self._actuator_type in ("SWITCH", "COMFORT_PLUG"):
self._service_location.set_actuator_state(self._actuator_id, state="ON_ON") self._service_location.set_actuator_state(self._actuator_id, state="ON_ON")
@ -117,7 +119,7 @@ class SmappeeActuator(SwitchEntity):
self._actuator_id, state=self._actuator_state_option self._actuator_id, state=self._actuator_state_option
) )
def turn_off(self, **kwargs): def turn_off(self, **kwargs: Any) -> None:
"""Turn off Comport Plug.""" """Turn off Comport Plug."""
if self._actuator_type in ("SWITCH", "COMFORT_PLUG"): if self._actuator_type in ("SWITCH", "COMFORT_PLUG"):
self._service_location.set_actuator_state( self._service_location.set_actuator_state(
@ -129,7 +131,7 @@ class SmappeeActuator(SwitchEntity):
) )
@property @property
def available(self): def available(self) -> bool:
"""Return True if entity is available. Unavailable for COMFORT_PLUGS.""" """Return True if entity is available. Unavailable for COMFORT_PLUGS."""
return ( return (
self._connection_state == "CONNECTED" self._connection_state == "CONNECTED"
@ -166,7 +168,7 @@ class SmappeeActuator(SwitchEntity):
sw_version=self._service_location.firmware_version, sw_version=self._service_location.firmware_version,
) )
async def async_update(self): async def async_update(self) -> None:
"""Get the latest data from Smappee and update the state.""" """Get the latest data from Smappee and update the state."""
await self._smappee_base.async_update() await self._smappee_base.async_update()

View File

@ -4,6 +4,7 @@ from __future__ import annotations
import asyncio import asyncio
from collections.abc import Iterable, Sequence from collections.abc import Iterable, Sequence
import logging import logging
from typing import Any
from pysmartthings import Attribute, Capability from pysmartthings import Attribute, Capability
@ -160,7 +161,7 @@ class SmartThingsThermostat(SmartThingsEntity, ClimateEntity):
flags |= ClimateEntityFeature.FAN_MODE flags |= ClimateEntityFeature.FAN_MODE
return flags return flags
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.""" """Set new target fan mode."""
await self._device.set_thermostat_fan_mode(fan_mode, set_status=True) await self._device.set_thermostat_fan_mode(fan_mode, set_status=True)
@ -177,7 +178,7 @@ class SmartThingsThermostat(SmartThingsEntity, ClimateEntity):
# the entity state ahead of receiving the confirming push updates # the entity state ahead of receiving the confirming push updates
self.async_schedule_update_ha_state(True) self.async_schedule_update_ha_state(True)
async def async_set_temperature(self, **kwargs): async def async_set_temperature(self, **kwargs: Any) -> None:
"""Set new operation mode and target temperatures.""" """Set new operation mode and target temperatures."""
# Operation state # Operation state
if operation_state := kwargs.get(ATTR_HVAC_MODE): if operation_state := kwargs.get(ATTR_HVAC_MODE):
@ -214,7 +215,7 @@ class SmartThingsThermostat(SmartThingsEntity, ClimateEntity):
# the entity state ahead of receiving the confirming push updates # the entity state ahead of receiving the confirming push updates
self.async_schedule_update_ha_state(True) self.async_schedule_update_ha_state(True)
async def async_update(self): async def async_update(self) -> None:
"""Update the attributes of the climate device.""" """Update the attributes of the climate device."""
thermostat_mode = self._device.status.thermostat_mode thermostat_mode = self._device.status.thermostat_mode
self._hvac_mode = MODE_TO_STATE.get(thermostat_mode) self._hvac_mode = MODE_TO_STATE.get(thermostat_mode)
@ -326,7 +327,7 @@ class SmartThingsAirConditioner(SmartThingsEntity, ClimateEntity):
super().__init__(device) super().__init__(device)
self._hvac_modes = None self._hvac_modes = None
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.""" """Set new target fan mode."""
await self._device.set_fan_mode(fan_mode, set_status=True) await self._device.set_fan_mode(fan_mode, set_status=True)
# State is set optimistically in the command above, therefore update # State is set optimistically in the command above, therefore update
@ -352,7 +353,7 @@ class SmartThingsAirConditioner(SmartThingsEntity, ClimateEntity):
# the entity state ahead of receiving the confirming push updates # the entity state ahead of receiving the confirming push updates
self.async_write_ha_state() 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.""" """Set new target temperature."""
tasks = [] tasks = []
# operation mode # operation mode
@ -372,21 +373,21 @@ class SmartThingsAirConditioner(SmartThingsEntity, ClimateEntity):
# the entity state ahead of receiving the confirming push updates # the entity state ahead of receiving the confirming push updates
self.async_write_ha_state() self.async_write_ha_state()
async def async_turn_on(self): async def async_turn_on(self) -> None:
"""Turn device on.""" """Turn device on."""
await self._device.switch_on(set_status=True) await self._device.switch_on(set_status=True)
# State is set optimistically in the command above, therefore update # State is set optimistically in the command above, therefore update
# the entity state ahead of receiving the confirming push updates # the entity state ahead of receiving the confirming push updates
self.async_write_ha_state() self.async_write_ha_state()
async def async_turn_off(self): async def async_turn_off(self) -> None:
"""Turn device off.""" """Turn device off."""
await self._device.switch_off(set_status=True) await self._device.switch_off(set_status=True)
# State is set optimistically in the command above, therefore update # State is set optimistically in the command above, therefore update
# the entity state ahead of receiving the confirming push updates # the entity state ahead of receiving the confirming push updates
self.async_write_ha_state() self.async_write_ha_state()
async def async_update(self): async def async_update(self) -> None:
"""Update the calculated fields of the AC.""" """Update the calculated fields of the AC."""
modes = {HVACMode.OFF} modes = {HVACMode.OFF}
for mode in self._device.status.supported_ac_modes: for mode in self._device.status.supported_ac_modes:

View File

@ -2,6 +2,7 @@
from __future__ import annotations from __future__ import annotations
from collections.abc import Sequence from collections.abc import Sequence
from typing import Any
from pysmartthings import Capability from pysmartthings import Capability
@ -41,14 +42,14 @@ def get_capabilities(capabilities: Sequence[str]) -> Sequence[str] | None:
class SmartThingsSwitch(SmartThingsEntity, SwitchEntity): class SmartThingsSwitch(SmartThingsEntity, SwitchEntity):
"""Define a SmartThings switch.""" """Define a SmartThings switch."""
async def async_turn_off(self, **kwargs) -> None: async def async_turn_off(self, **kwargs: Any) -> None:
"""Turn the switch off.""" """Turn the switch off."""
await self._device.switch_off(set_status=True) await self._device.switch_off(set_status=True)
# State is set optimistically in the command above, therefore update # State is set optimistically in the command above, therefore update
# the entity state ahead of receiving the confirming push updates # the entity state ahead of receiving the confirming push updates
self.async_write_ha_state() self.async_write_ha_state()
async def async_turn_on(self, **kwargs) -> None: async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn the switch on.""" """Turn the switch on."""
await self._device.switch_on(set_status=True) await self._device.switch_on(set_status=True)
# State is set optimistically in the command above, therefore update # State is set optimistically in the command above, therefore update

View File

@ -1,6 +1,8 @@
"""Platform for climate integration.""" """Platform for climate integration."""
from __future__ import annotations from __future__ import annotations
from typing import Any
from smarttub import Spa from smarttub import Spa
from homeassistant.components.climate import ClimateEntity from homeassistant.components.climate import ClimateEntity
@ -72,7 +74,7 @@ class SmartTubThermostat(SmartTubEntity, ClimateEntity):
"""Return the current running hvac operation.""" """Return the current running hvac operation."""
return HVAC_ACTIONS.get(self.spa_status.heater) return HVAC_ACTIONS.get(self.spa_status.heater)
async def async_set_hvac_mode(self, hvac_mode: HVACMode): async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
"""Set new target hvac mode. """Set new target hvac mode.
As with hvac_mode, we don't really have an option here. As with hvac_mode, we don't really have an option here.
@ -113,13 +115,13 @@ class SmartTubThermostat(SmartTubEntity, ClimateEntity):
"""Return the target water temperature.""" """Return the target water temperature."""
return self.spa_status.set_temperature return self.spa_status.set_temperature
async def async_set_temperature(self, **kwargs): async def async_set_temperature(self, **kwargs: Any) -> None:
"""Set new target temperature.""" """Set new target temperature."""
temperature = kwargs[ATTR_TEMPERATURE] temperature = kwargs[ATTR_TEMPERATURE]
await self.spa.set_temperature(temperature) await self.spa.set_temperature(temperature)
await self.coordinator.async_refresh() await self.coordinator.async_refresh()
async def async_set_preset_mode(self, preset_mode: str): async def async_set_preset_mode(self, preset_mode: str) -> None:
"""Activate the specified preset mode.""" """Activate the specified preset mode."""
heat_mode = HEAT_MODES[preset_mode] heat_mode = HEAT_MODES[preset_mode]
await self.spa.set_heat_mode(heat_mode) await self.spa.set_heat_mode(heat_mode)

View File

@ -1,4 +1,6 @@
"""Platform for switch integration.""" """Platform for switch integration."""
from typing import Any
import async_timeout import async_timeout
from smarttub import SpaPump from smarttub import SpaPump
@ -62,21 +64,21 @@ class SmartTubPump(SmartTubEntity, SwitchEntity):
"""Return True if the pump is on.""" """Return True if the pump is on."""
return self.pump.state != SpaPump.PumpState.OFF return self.pump.state != SpaPump.PumpState.OFF
async def async_turn_on(self, **kwargs) -> None: async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn the pump on.""" """Turn the pump on."""
# the API only supports toggling # the API only supports toggling
if not self.is_on: if not self.is_on:
await self.async_toggle() await self.async_toggle()
async def async_turn_off(self, **kwargs) -> None: async def async_turn_off(self, **kwargs: Any) -> None:
"""Turn the pump off.""" """Turn the pump off."""
# the API only supports toggling # the API only supports toggling
if self.is_on: if self.is_on:
await self.async_toggle() await self.async_toggle()
async def async_toggle(self, **kwargs) -> None: async def async_toggle(self, **kwargs: Any) -> None:
"""Toggle the pump on or off.""" """Toggle the pump on or off."""
async with async_timeout.timeout(API_TIMEOUT): async with async_timeout.timeout(API_TIMEOUT):
await self.pump.toggle() await self.pump.toggle()

View File

@ -181,19 +181,19 @@ class SnapcastGroupDevice(MediaPlayerEntity):
name = f"{self._group.friendly_name} {GROUP_SUFFIX}" name = f"{self._group.friendly_name} {GROUP_SUFFIX}"
return {"friendly_name": name} return {"friendly_name": name}
async def async_select_source(self, source): async def async_select_source(self, source: str) -> None:
"""Set input source.""" """Set input source."""
streams = self._group.streams_by_name() streams = self._group.streams_by_name()
if source in streams: if source in streams:
await self._group.set_stream(streams[source].identifier) await self._group.set_stream(streams[source].identifier)
self.async_write_ha_state() self.async_write_ha_state()
async def async_mute_volume(self, mute): async def async_mute_volume(self, mute: bool) -> None:
"""Send the mute command.""" """Send the mute command."""
await self._group.set_muted(mute) await self._group.set_muted(mute)
self.async_write_ha_state() self.async_write_ha_state()
async def async_set_volume_level(self, volume): async def async_set_volume_level(self, volume: float) -> None:
"""Set the volume level.""" """Set the volume level."""
await self._group.set_volume(round(volume * 100)) await self._group.set_volume(round(volume * 100))
self.async_write_ha_state() self.async_write_ha_state()
@ -292,19 +292,19 @@ class SnapcastClientDevice(MediaPlayerEntity):
"""Latency for Client.""" """Latency for Client."""
return self._client.latency return self._client.latency
async def async_select_source(self, source): async def async_select_source(self, source: str) -> None:
"""Set input source.""" """Set input source."""
streams = self._client.group.streams_by_name() streams = self._client.group.streams_by_name()
if source in streams: if source in streams:
await self._client.group.set_stream(streams[source].identifier) await self._client.group.set_stream(streams[source].identifier)
self.async_write_ha_state() self.async_write_ha_state()
async def async_mute_volume(self, mute): async def async_mute_volume(self, mute: bool) -> None:
"""Send the mute command.""" """Send the mute command."""
await self._client.set_muted(mute) await self._client.set_muted(mute)
self.async_write_ha_state() self.async_write_ha_state()
async def async_set_volume_level(self, volume): async def async_set_volume_level(self, volume: float) -> None:
"""Set the volume level.""" """Set the volume level."""
await self._client.set_volume(round(volume * 100)) await self._client.set_volume(round(volume * 100))
self.async_write_ha_state() self.async_write_ha_state()

View File

@ -166,7 +166,7 @@ class SnmpSensor(TemplateSensor):
"""Return the state of the sensor.""" """Return the state of the sensor."""
return self._state return self._state
async def async_update(self): async def async_update(self) -> None:
"""Get the latest data and updates the states.""" """Get the latest data and updates the states."""
await self.data.async_update() await self.data.async_update()

View File

@ -2,6 +2,7 @@
from __future__ import annotations from __future__ import annotations
import logging import logging
from typing import Any
import pysnmp.hlapi.asyncio as hlapi import pysnmp.hlapi.asyncio as hlapi
from pysnmp.hlapi.asyncio import ( from pysnmp.hlapi.asyncio import (
@ -235,12 +236,12 @@ class SnmpSwitch(SwitchEntity):
ContextData(), ContextData(),
] ]
async def async_turn_on(self, **kwargs): async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn on the switch.""" """Turn on the switch."""
# If vartype set, use it - http://snmplabs.com/pysnmp/docs/api-reference.html#pysnmp.smi.rfc1902.ObjectType # If vartype set, use it - http://snmplabs.com/pysnmp/docs/api-reference.html#pysnmp.smi.rfc1902.ObjectType
await self._execute_command(self._command_payload_on) await self._execute_command(self._command_payload_on)
async def async_turn_off(self, **kwargs): async def async_turn_off(self, **kwargs: Any) -> None:
"""Turn off the switch.""" """Turn off the switch."""
await self._execute_command(self._command_payload_off) await self._execute_command(self._command_payload_off)
@ -256,7 +257,7 @@ class SnmpSwitch(SwitchEntity):
else: else:
await self._set(MAP_SNMP_VARTYPES.get(self._vartype, Integer)(command)) await self._set(MAP_SNMP_VARTYPES.get(self._vartype, Integer)(command))
async def async_update(self): async def async_update(self) -> None:
"""Update the state.""" """Update the state."""
errindication, errstatus, errindex, restable = await getCmd( errindication, errstatus, errindex, restable = await getCmd(
*self._request_args, ObjectType(ObjectIdentity(self._baseoid)) *self._request_args, ObjectType(ObjectIdentity(self._baseoid))