Enable basic type checking for the homeassistant component (#52464)
* Enable basic type checking for the homeassistant component * Tweakpull/52541/head
parent
600bea2459
commit
1cc8280959
|
@ -1,9 +1,8 @@
|
|||
"""Allow users to set and activate scenes."""
|
||||
from __future__ import annotations
|
||||
|
||||
from collections import namedtuple
|
||||
import logging
|
||||
from typing import Any
|
||||
from typing import Any, NamedTuple
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
|
@ -115,10 +114,19 @@ CREATE_SCENE_SCHEMA = vol.All(
|
|||
|
||||
SERVICE_APPLY = "apply"
|
||||
SERVICE_CREATE = "create"
|
||||
SCENECONFIG = namedtuple("SceneConfig", [CONF_ID, CONF_NAME, CONF_ICON, STATES])
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class SceneConfig(NamedTuple):
|
||||
"""Object for storing scene config."""
|
||||
|
||||
id: str
|
||||
name: str
|
||||
icon: str
|
||||
states: dict
|
||||
|
||||
|
||||
@callback
|
||||
def scenes_with_entity(hass: HomeAssistant, entity_id: str) -> list[str]:
|
||||
"""Return all scenes that reference the entity."""
|
||||
|
@ -238,7 +246,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
|||
_LOGGER.warning("Empty scenes are not allowed")
|
||||
return
|
||||
|
||||
scene_config = SCENECONFIG(None, call.data[CONF_SCENE_ID], None, entities)
|
||||
scene_config = SceneConfig(None, call.data[CONF_SCENE_ID], None, entities)
|
||||
entity_id = f"{SCENE_DOMAIN}.{scene_config.name}"
|
||||
old = platform.entities.get(entity_id)
|
||||
if old is not None:
|
||||
|
@ -264,7 +272,7 @@ def _process_scenes_config(hass, async_add_entities, config):
|
|||
async_add_entities(
|
||||
HomeAssistantScene(
|
||||
hass,
|
||||
SCENECONFIG(
|
||||
SceneConfig(
|
||||
scene.get(CONF_ID),
|
||||
scene[CONF_NAME],
|
||||
scene.get(CONF_ICON),
|
||||
|
|
|
@ -79,7 +79,7 @@ async def async_attach_trigger(
|
|||
job = HassJob(action)
|
||||
|
||||
trigger_data = automation_info.get("trigger_data", {}) if automation_info else {}
|
||||
_variables = {}
|
||||
_variables: dict = {}
|
||||
if automation_info:
|
||||
_variables = automation_info.get("variables") or {}
|
||||
|
||||
|
|
|
@ -88,7 +88,7 @@ async def async_attach_trigger(
|
|||
job = HassJob(action)
|
||||
|
||||
trigger_data = automation_info.get("trigger_data", {}) if automation_info else {}
|
||||
_variables = {}
|
||||
_variables: dict = {}
|
||||
if automation_info:
|
||||
_variables = automation_info.get("variables") or {}
|
||||
|
||||
|
@ -171,10 +171,11 @@ async def async_attach_trigger(
|
|||
)
|
||||
return
|
||||
|
||||
def _check_same_state(_, _2, new_st: State):
|
||||
def _check_same_state(_, _2, new_st: State | None) -> bool:
|
||||
if new_st is None:
|
||||
return False
|
||||
|
||||
cur_value: str | None
|
||||
if attribute is None:
|
||||
cur_value = new_st.state
|
||||
else:
|
||||
|
|
|
@ -25,7 +25,7 @@ import homeassistant.util.dt as dt_util
|
|||
|
||||
_TIME_TRIGGER_SCHEMA = vol.Any(
|
||||
cv.time,
|
||||
vol.All(str, cv.entity_domain(("input_datetime", "sensor"))),
|
||||
vol.All(str, cv.entity_domain(["input_datetime", "sensor"])),
|
||||
msg="Expected HH:MM, HH:MM:SS or Entity ID with domain 'input_datetime' or 'sensor'",
|
||||
)
|
||||
|
||||
|
|
|
@ -1440,7 +1440,9 @@ def async_track_time_change(
|
|||
track_time_change = threaded_listener_factory(async_track_time_change)
|
||||
|
||||
|
||||
def process_state_match(parameter: None | str | Iterable[str]) -> Callable[[str], bool]:
|
||||
def process_state_match(
|
||||
parameter: None | str | Iterable[str],
|
||||
) -> Callable[[str | None], bool]:
|
||||
"""Convert parameter to function that matches input against parameter."""
|
||||
if parameter is None or parameter == MATCH_ALL:
|
||||
return lambda _: True
|
||||
|
|
18
mypy.ini
18
mypy.ini
|
@ -1210,24 +1210,6 @@ ignore_errors = true
|
|||
[mypy-homeassistant.components.home_plus_control.*]
|
||||
ignore_errors = true
|
||||
|
||||
[mypy-homeassistant.components.homeassistant.triggers.homeassistant]
|
||||
ignore_errors = true
|
||||
|
||||
[mypy-homeassistant.components.homeassistant.triggers.numeric_state]
|
||||
ignore_errors = true
|
||||
|
||||
[mypy-homeassistant.components.homeassistant.triggers.time_pattern]
|
||||
ignore_errors = true
|
||||
|
||||
[mypy-homeassistant.components.homeassistant.triggers.time]
|
||||
ignore_errors = true
|
||||
|
||||
[mypy-homeassistant.components.homeassistant.triggers.state]
|
||||
ignore_errors = true
|
||||
|
||||
[mypy-homeassistant.components.homeassistant.scene]
|
||||
ignore_errors = true
|
||||
|
||||
[mypy-homeassistant.components.homekit.*]
|
||||
ignore_errors = true
|
||||
|
||||
|
|
|
@ -80,12 +80,6 @@ IGNORED_MODULES: Final[list[str]] = [
|
|||
"homeassistant.components.hisense_aehw4a1.*",
|
||||
"homeassistant.components.home_connect.*",
|
||||
"homeassistant.components.home_plus_control.*",
|
||||
"homeassistant.components.homeassistant.triggers.homeassistant",
|
||||
"homeassistant.components.homeassistant.triggers.numeric_state",
|
||||
"homeassistant.components.homeassistant.triggers.time_pattern",
|
||||
"homeassistant.components.homeassistant.triggers.time",
|
||||
"homeassistant.components.homeassistant.triggers.state",
|
||||
"homeassistant.components.homeassistant.scene",
|
||||
"homeassistant.components.homekit.*",
|
||||
"homeassistant.components.homekit_controller.*",
|
||||
"homeassistant.components.homematicip_cloud.*",
|
||||
|
|
Loading…
Reference in New Issue