Minor Hyperion mypy cleanups (#45765)

This commit is contained in:
Dermot Duffy 2021-03-01 09:10:28 -08:00 committed by GitHub
parent adad4a7785
commit 61f509bdd8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 7 deletions

View file

@ -286,6 +286,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
]
)
assert hyperion_client
if hyperion_client.instances is not None:
await async_instances_to_clients_raw(hyperion_client.instances)
hass.data[DOMAIN][config_entry.entry_id][CONF_ON_UNLOAD].append(
config_entry.add_update_listener(_async_entry_updated)

View file

@ -4,7 +4,7 @@ from __future__ import annotations
import functools
import logging
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
@ -147,7 +147,7 @@ class HyperionBaseLight(LightEntity):
self._static_effect_list += list(const.KEY_COMPONENTID_EXTERNAL_SOURCES)
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_COMPONENTS}-{const.KEY_UPDATE}": self._update_components,
f"{const.KEY_EFFECTS}-{const.KEY_UPDATE}": self._update_effect_list,
@ -236,7 +236,7 @@ class HyperionBaseLight(LightEntity):
# == Set brightness ==
if ATTR_BRIGHTNESS in kwargs:
brightness = kwargs[ATTR_BRIGHTNESS]
for item in self._client.adjustment:
for item in self._client.adjustment or []:
if const.KEY_ID in item:
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]]:
"""Get the relevant Hyperion priority entry to consider."""
# 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
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(
CONF_PRIORITY
) 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
@classmethod

View file

@ -157,7 +157,7 @@ class HyperionComponentSwitch(SwitchEntity):
@property
def is_on(self) -> bool:
"""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:
return bool(component.setdefault(KEY_ENABLED, False))
return False