mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 19:27:45 +00:00
Minor Hyperion mypy cleanups (#45765)
This commit is contained in:
parent
adad4a7785
commit
61f509bdd8
@ -286,6 +286,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
assert hyperion_client
|
assert hyperion_client
|
||||||
|
if hyperion_client.instances is not None:
|
||||||
await async_instances_to_clients_raw(hyperion_client.instances)
|
await async_instances_to_clients_raw(hyperion_client.instances)
|
||||||
hass.data[DOMAIN][config_entry.entry_id][CONF_ON_UNLOAD].append(
|
hass.data[DOMAIN][config_entry.entry_id][CONF_ON_UNLOAD].append(
|
||||||
config_entry.add_update_listener(_async_entry_updated)
|
config_entry.add_update_listener(_async_entry_updated)
|
||||||
|
@ -4,7 +4,7 @@ from __future__ import annotations
|
|||||||
import functools
|
import functools
|
||||||
import logging
|
import logging
|
||||||
from types import MappingProxyType
|
from types import MappingProxyType
|
||||||
from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple
|
from typing import Any, Callable, Dict, List, Mapping, Optional, Sequence, Tuple
|
||||||
|
|
||||||
from hyperion import client, const
|
from hyperion import client, const
|
||||||
|
|
||||||
@ -147,7 +147,7 @@ class HyperionBaseLight(LightEntity):
|
|||||||
self._static_effect_list += list(const.KEY_COMPONENTID_EXTERNAL_SOURCES)
|
self._static_effect_list += list(const.KEY_COMPONENTID_EXTERNAL_SOURCES)
|
||||||
self._effect_list: List[str] = self._static_effect_list[:]
|
self._effect_list: List[str] = self._static_effect_list[:]
|
||||||
|
|
||||||
self._client_callbacks = {
|
self._client_callbacks: Mapping[str, Callable[[Dict[str, Any]], None]] = {
|
||||||
f"{const.KEY_ADJUSTMENT}-{const.KEY_UPDATE}": self._update_adjustment,
|
f"{const.KEY_ADJUSTMENT}-{const.KEY_UPDATE}": self._update_adjustment,
|
||||||
f"{const.KEY_COMPONENTS}-{const.KEY_UPDATE}": self._update_components,
|
f"{const.KEY_COMPONENTS}-{const.KEY_UPDATE}": self._update_components,
|
||||||
f"{const.KEY_EFFECTS}-{const.KEY_UPDATE}": self._update_effect_list,
|
f"{const.KEY_EFFECTS}-{const.KEY_UPDATE}": self._update_effect_list,
|
||||||
@ -236,7 +236,7 @@ class HyperionBaseLight(LightEntity):
|
|||||||
# == Set brightness ==
|
# == Set brightness ==
|
||||||
if ATTR_BRIGHTNESS in kwargs:
|
if ATTR_BRIGHTNESS in kwargs:
|
||||||
brightness = kwargs[ATTR_BRIGHTNESS]
|
brightness = kwargs[ATTR_BRIGHTNESS]
|
||||||
for item in self._client.adjustment:
|
for item in self._client.adjustment or []:
|
||||||
if const.KEY_ID in item:
|
if const.KEY_ID in item:
|
||||||
if not await self._client.async_send_set_adjustment(
|
if not await self._client.async_send_set_adjustment(
|
||||||
**{
|
**{
|
||||||
@ -423,7 +423,12 @@ class HyperionBaseLight(LightEntity):
|
|||||||
def _get_priority_entry_that_dictates_state(self) -> Optional[Dict[str, Any]]:
|
def _get_priority_entry_that_dictates_state(self) -> Optional[Dict[str, Any]]:
|
||||||
"""Get the relevant Hyperion priority entry to consider."""
|
"""Get the relevant Hyperion priority entry to consider."""
|
||||||
# Return the visible priority (whether or not it is the HA priority).
|
# Return the visible priority (whether or not it is the HA priority).
|
||||||
return self._client.visible_priority # type: ignore[no-any-return]
|
|
||||||
|
# Explicit type specifier to ensure this works when the underlying (typed)
|
||||||
|
# library is installed along with the tests. Casts would trigger a
|
||||||
|
# redundant-cast warning in this case.
|
||||||
|
priority: Optional[Dict[str, Any]] = self._client.visible_priority
|
||||||
|
return priority
|
||||||
|
|
||||||
# pylint: disable=no-self-use
|
# pylint: disable=no-self-use
|
||||||
def _allow_priority_update(self, priority: Optional[Dict[str, Any]] = None) -> bool:
|
def _allow_priority_update(self, priority: Optional[Dict[str, Any]] = None) -> bool:
|
||||||
@ -530,7 +535,11 @@ class HyperionPriorityLight(HyperionBaseLight):
|
|||||||
if candidate[const.KEY_PRIORITY] == self._get_option(
|
if candidate[const.KEY_PRIORITY] == self._get_option(
|
||||||
CONF_PRIORITY
|
CONF_PRIORITY
|
||||||
) and candidate.get(const.KEY_ACTIVE, False):
|
) and candidate.get(const.KEY_ACTIVE, False):
|
||||||
return candidate # type: ignore[no-any-return]
|
# Explicit type specifier to ensure this works when the underlying
|
||||||
|
# (typed) library is installed along with the tests. Casts would trigger
|
||||||
|
# a redundant-cast warning in this case.
|
||||||
|
output: Dict[str, Any] = candidate
|
||||||
|
return output
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -157,7 +157,7 @@ class HyperionComponentSwitch(SwitchEntity):
|
|||||||
@property
|
@property
|
||||||
def is_on(self) -> bool:
|
def is_on(self) -> bool:
|
||||||
"""Return true if the switch is on."""
|
"""Return true if the switch is on."""
|
||||||
for component in self._client.components:
|
for component in self._client.components or []:
|
||||||
if component[KEY_NAME] == self._component_name:
|
if component[KEY_NAME] == self._component_name:
|
||||||
return bool(component.setdefault(KEY_ENABLED, False))
|
return bool(component.setdefault(KEY_ENABLED, False))
|
||||||
return False
|
return False
|
||||||
|
Loading…
x
Reference in New Issue
Block a user