mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
Improve entity type hints [u] (#77884)
This commit is contained in:
parent
3ec231c911
commit
3798d28bec
@ -115,7 +115,7 @@ class UERadioDevice(MediaPlayerEntity):
|
||||
self._session,
|
||||
)
|
||||
|
||||
def update(self):
|
||||
def update(self) -> None:
|
||||
"""Get the latest details from the device."""
|
||||
request = send_request(
|
||||
{
|
||||
@ -192,35 +192,35 @@ class UERadioDevice(MediaPlayerEntity):
|
||||
"""Title of current playing media."""
|
||||
return self._media_title
|
||||
|
||||
def turn_on(self):
|
||||
def turn_on(self) -> None:
|
||||
"""Turn on specified media player or all."""
|
||||
self.send_command(["power", 1])
|
||||
|
||||
def turn_off(self):
|
||||
def turn_off(self) -> None:
|
||||
"""Turn off specified media player or all."""
|
||||
self.send_command(["power", 0])
|
||||
|
||||
def media_play(self):
|
||||
def media_play(self) -> None:
|
||||
"""Send the media player the command for play/pause."""
|
||||
self.send_command(["play"])
|
||||
|
||||
def media_pause(self):
|
||||
def media_pause(self) -> None:
|
||||
"""Send the media player the command for pause."""
|
||||
self.send_command(["pause"])
|
||||
|
||||
def media_stop(self):
|
||||
def media_stop(self) -> None:
|
||||
"""Send the media player the stop command."""
|
||||
self.send_command(["stop"])
|
||||
|
||||
def media_previous_track(self):
|
||||
def media_previous_track(self) -> None:
|
||||
"""Send the media player the command for prev track."""
|
||||
self.send_command(["button", "rew"])
|
||||
|
||||
def media_next_track(self):
|
||||
def media_next_track(self) -> None:
|
||||
"""Send the media player the command for next track."""
|
||||
self.send_command(["button", "fwd"])
|
||||
|
||||
def mute_volume(self, mute):
|
||||
def mute_volume(self, mute: bool) -> None:
|
||||
"""Send mute command."""
|
||||
if mute:
|
||||
self._last_volume = self._volume
|
||||
@ -228,6 +228,6 @@ class UERadioDevice(MediaPlayerEntity):
|
||||
else:
|
||||
self.send_command(["mixer", "volume", self._last_volume * 100])
|
||||
|
||||
def set_volume_level(self, volume):
|
||||
def set_volume_level(self, volume: float) -> None:
|
||||
"""Set volume level, range 0..1."""
|
||||
self.send_command(["mixer", "volume", volume * 100])
|
||||
|
@ -232,7 +232,7 @@ class UniFiPOEClientSwitch(UniFiClient, SwitchEntity, RestoreEntity):
|
||||
if client.switch_port and self.port.poe_mode != "off":
|
||||
self.poe_mode = self.port.poe_mode
|
||||
|
||||
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()
|
||||
|
||||
@ -256,7 +256,7 @@ class UniFiPOEClientSwitch(UniFiClient, SwitchEntity, RestoreEntity):
|
||||
return self.port.poe_mode != "off"
|
||||
|
||||
@property
|
||||
def available(self):
|
||||
def available(self) -> bool:
|
||||
"""Return if switch is available.
|
||||
|
||||
Poe_mode None means its POE state is unknown.
|
||||
@ -270,11 +270,11 @@ class UniFiPOEClientSwitch(UniFiClient, SwitchEntity, RestoreEntity):
|
||||
and self.client.switch_mac in self.controller.api.devices
|
||||
)
|
||||
|
||||
async def async_turn_on(self, **kwargs):
|
||||
async def async_turn_on(self, **kwargs: Any) -> None:
|
||||
"""Enable POE for client."""
|
||||
await self.device.set_port_poe_mode(self.client.switch_port, self.poe_mode)
|
||||
|
||||
async def async_turn_off(self, **kwargs):
|
||||
async def async_turn_off(self, **kwargs: Any) -> None:
|
||||
"""Disable POE for client."""
|
||||
await self.device.set_port_poe_mode(self.client.switch_port, "off")
|
||||
|
||||
@ -335,16 +335,16 @@ class UniFiBlockClientSwitch(UniFiClient, SwitchEntity):
|
||||
"""Return true if client is allowed to connect."""
|
||||
return not self._is_blocked
|
||||
|
||||
async def async_turn_on(self, **kwargs):
|
||||
async def async_turn_on(self, **kwargs: Any) -> None:
|
||||
"""Turn on connectivity for client."""
|
||||
await self.controller.api.clients.unblock(self.client.mac)
|
||||
|
||||
async def async_turn_off(self, **kwargs):
|
||||
async def async_turn_off(self, **kwargs: Any) -> None:
|
||||
"""Turn off connectivity for client."""
|
||||
await self.controller.api.clients.block(self.client.mac)
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
def icon(self) -> str:
|
||||
"""Return the icon to use in the frontend."""
|
||||
if self._is_blocked:
|
||||
return "mdi:network-off"
|
||||
@ -445,7 +445,7 @@ class UniFiDPIRestrictionSwitch(UniFiBase, SwitchEntity):
|
||||
"""Return true if DPI group app restriction is enabled."""
|
||||
return self._is_enabled
|
||||
|
||||
async def async_turn_on(self, **kwargs):
|
||||
async def async_turn_on(self, **kwargs: Any) -> None:
|
||||
"""Restrict access of apps related to DPI group."""
|
||||
return await asyncio.gather(
|
||||
*[
|
||||
@ -454,7 +454,7 @@ class UniFiDPIRestrictionSwitch(UniFiBase, SwitchEntity):
|
||||
]
|
||||
)
|
||||
|
||||
async def async_turn_off(self, **kwargs):
|
||||
async def async_turn_off(self, **kwargs: Any) -> None:
|
||||
"""Remove restriction of apps related to DPI group."""
|
||||
return await asyncio.gather(
|
||||
*[
|
||||
@ -503,15 +503,15 @@ class UniFiOutletSwitch(UniFiBase, SwitchEntity):
|
||||
return self._item.outlets[self._outlet_index].relay_state
|
||||
|
||||
@property
|
||||
def available(self):
|
||||
def available(self) -> bool:
|
||||
"""Return if switch is available."""
|
||||
return not self._item.disabled and self.controller.available
|
||||
|
||||
async def async_turn_on(self, **kwargs):
|
||||
async def async_turn_on(self, **kwargs: Any) -> None:
|
||||
"""Enable outlet relay."""
|
||||
await self._item.set_outlet_relay_state(self._outlet_index, True)
|
||||
|
||||
async def async_turn_off(self, **kwargs):
|
||||
async def async_turn_off(self, **kwargs: Any) -> None:
|
||||
"""Disable outlet relay."""
|
||||
await self._item.set_outlet_relay_state(self._outlet_index, False)
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from copy import copy
|
||||
from typing import Any
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
@ -183,7 +184,7 @@ class UniversalMediaPlayer(MediaPlayerEntity):
|
||||
self._state_template = state_template
|
||||
self._device_class = device_class
|
||||
|
||||
async def async_added_to_hass(self):
|
||||
async def async_added_to_hass(self) -> None:
|
||||
"""Subscribe to children and template state changes."""
|
||||
|
||||
@callback
|
||||
@ -529,95 +530,97 @@ class UniversalMediaPlayer(MediaPlayerEntity):
|
||||
"""When was the position of the current playing media valid."""
|
||||
return self._child_attr(ATTR_MEDIA_POSITION_UPDATED_AT)
|
||||
|
||||
async def async_turn_on(self):
|
||||
async def async_turn_on(self) -> None:
|
||||
"""Turn the media player on."""
|
||||
await self._async_call_service(SERVICE_TURN_ON, allow_override=True)
|
||||
|
||||
async def async_turn_off(self):
|
||||
async def async_turn_off(self) -> None:
|
||||
"""Turn the media player off."""
|
||||
await self._async_call_service(SERVICE_TURN_OFF, allow_override=True)
|
||||
|
||||
async def async_mute_volume(self, mute):
|
||||
async def async_mute_volume(self, mute: bool) -> None:
|
||||
"""Mute the volume."""
|
||||
data = {ATTR_MEDIA_VOLUME_MUTED: mute}
|
||||
await self._async_call_service(SERVICE_VOLUME_MUTE, data, allow_override=True)
|
||||
|
||||
async def async_set_volume_level(self, volume):
|
||||
async def async_set_volume_level(self, volume: float) -> None:
|
||||
"""Set volume level, range 0..1."""
|
||||
data = {ATTR_MEDIA_VOLUME_LEVEL: volume}
|
||||
await self._async_call_service(SERVICE_VOLUME_SET, data, allow_override=True)
|
||||
|
||||
async def async_media_play(self):
|
||||
async def async_media_play(self) -> None:
|
||||
"""Send play command."""
|
||||
await self._async_call_service(SERVICE_MEDIA_PLAY, allow_override=True)
|
||||
|
||||
async def async_media_pause(self):
|
||||
async def async_media_pause(self) -> None:
|
||||
"""Send pause command."""
|
||||
await self._async_call_service(SERVICE_MEDIA_PAUSE, allow_override=True)
|
||||
|
||||
async def async_media_stop(self):
|
||||
async def async_media_stop(self) -> None:
|
||||
"""Send stop command."""
|
||||
await self._async_call_service(SERVICE_MEDIA_STOP, allow_override=True)
|
||||
|
||||
async def async_media_previous_track(self):
|
||||
async def async_media_previous_track(self) -> None:
|
||||
"""Send previous track command."""
|
||||
await self._async_call_service(
|
||||
SERVICE_MEDIA_PREVIOUS_TRACK, allow_override=True
|
||||
)
|
||||
|
||||
async def async_media_next_track(self):
|
||||
async def async_media_next_track(self) -> None:
|
||||
"""Send next track command."""
|
||||
await self._async_call_service(SERVICE_MEDIA_NEXT_TRACK, allow_override=True)
|
||||
|
||||
async def async_media_seek(self, position):
|
||||
async def async_media_seek(self, position: float) -> None:
|
||||
"""Send seek command."""
|
||||
data = {ATTR_MEDIA_SEEK_POSITION: position}
|
||||
await self._async_call_service(SERVICE_MEDIA_SEEK, data)
|
||||
|
||||
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 a piece of media."""
|
||||
data = {ATTR_MEDIA_CONTENT_TYPE: media_type, ATTR_MEDIA_CONTENT_ID: media_id}
|
||||
await self._async_call_service(SERVICE_PLAY_MEDIA, data, allow_override=True)
|
||||
|
||||
async def async_volume_up(self):
|
||||
async def async_volume_up(self) -> None:
|
||||
"""Turn volume up for media player."""
|
||||
await self._async_call_service(SERVICE_VOLUME_UP, allow_override=True)
|
||||
|
||||
async def async_volume_down(self):
|
||||
async def async_volume_down(self) -> None:
|
||||
"""Turn volume down for media player."""
|
||||
await self._async_call_service(SERVICE_VOLUME_DOWN, allow_override=True)
|
||||
|
||||
async def async_media_play_pause(self):
|
||||
async def async_media_play_pause(self) -> None:
|
||||
"""Play or pause the media player."""
|
||||
await self._async_call_service(SERVICE_MEDIA_PLAY_PAUSE, allow_override=True)
|
||||
|
||||
async def async_select_sound_mode(self, sound_mode):
|
||||
async def async_select_sound_mode(self, sound_mode: str) -> None:
|
||||
"""Select sound mode."""
|
||||
data = {ATTR_SOUND_MODE: sound_mode}
|
||||
await self._async_call_service(
|
||||
SERVICE_SELECT_SOUND_MODE, data, allow_override=True
|
||||
)
|
||||
|
||||
async def async_select_source(self, source):
|
||||
async def async_select_source(self, source: str) -> None:
|
||||
"""Set the input source."""
|
||||
data = {ATTR_INPUT_SOURCE: source}
|
||||
await self._async_call_service(SERVICE_SELECT_SOURCE, data, allow_override=True)
|
||||
|
||||
async def async_clear_playlist(self):
|
||||
async def async_clear_playlist(self) -> None:
|
||||
"""Clear players playlist."""
|
||||
await self._async_call_service(SERVICE_CLEAR_PLAYLIST, allow_override=True)
|
||||
|
||||
async def async_set_shuffle(self, shuffle):
|
||||
async def async_set_shuffle(self, shuffle: bool) -> None:
|
||||
"""Enable/disable shuffling."""
|
||||
data = {ATTR_MEDIA_SHUFFLE: shuffle}
|
||||
await self._async_call_service(SERVICE_SHUFFLE_SET, data, allow_override=True)
|
||||
|
||||
async def async_set_repeat(self, repeat):
|
||||
async def async_set_repeat(self, repeat: str) -> None:
|
||||
"""Set repeat mode."""
|
||||
data = {ATTR_MEDIA_REPEAT: repeat}
|
||||
await self._async_call_service(SERVICE_REPEAT_SET, data, allow_override=True)
|
||||
|
||||
async def async_toggle(self):
|
||||
async def async_toggle(self) -> None:
|
||||
"""Toggle the power on the media player."""
|
||||
if SERVICE_TOGGLE in self._cmds:
|
||||
await self._async_call_service(SERVICE_TOGGLE, allow_override=True)
|
||||
@ -625,7 +628,7 @@ class UniversalMediaPlayer(MediaPlayerEntity):
|
||||
# Delegate to turn_on or turn_off by default
|
||||
await super().async_toggle()
|
||||
|
||||
async def async_update(self):
|
||||
async def async_update(self) -> None:
|
||||
"""Update state in HA."""
|
||||
self._child_state = None
|
||||
for child_name in self._children:
|
||||
|
@ -107,7 +107,7 @@ class UnifiVideoCamera(Camera):
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def supported_features(self):
|
||||
def supported_features(self) -> int:
|
||||
"""Return supported features."""
|
||||
channels = self._caminfo["channels"]
|
||||
for channel in channels:
|
||||
@ -127,7 +127,7 @@ class UnifiVideoCamera(Camera):
|
||||
return attr
|
||||
|
||||
@property
|
||||
def is_recording(self):
|
||||
def is_recording(self) -> bool:
|
||||
"""Return true if the camera is recording."""
|
||||
recording_state = "DISABLED"
|
||||
if "recordingIndicator" in self._caminfo:
|
||||
@ -138,7 +138,7 @@ class UnifiVideoCamera(Camera):
|
||||
] or recording_state in ("MOTION_INPROGRESS", "MOTION_FINISHED")
|
||||
|
||||
@property
|
||||
def motion_detection_enabled(self):
|
||||
def motion_detection_enabled(self) -> bool:
|
||||
"""Camera Motion Detection Status."""
|
||||
return self._caminfo["recordingSettings"]["motionRecordEnabled"]
|
||||
|
||||
@ -230,11 +230,11 @@ class UnifiVideoCamera(Camera):
|
||||
_LOGGER.error("Unable to set recordmode to %s", set_mode)
|
||||
_LOGGER.debug(err)
|
||||
|
||||
def enable_motion_detection(self):
|
||||
def enable_motion_detection(self) -> None:
|
||||
"""Enable motion detection in camera."""
|
||||
self.set_motion_detection(True)
|
||||
|
||||
def disable_motion_detection(self):
|
||||
def disable_motion_detection(self) -> None:
|
||||
"""Disable motion detection in camera."""
|
||||
self.set_motion_detection(False)
|
||||
|
||||
@ -255,7 +255,7 @@ class UnifiVideoCamera(Camera):
|
||||
|
||||
return None
|
||||
|
||||
def update(self):
|
||||
def update(self) -> None:
|
||||
"""Update the info."""
|
||||
self._caminfo = self._nvr.get_camera(self._uuid)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user