diff --git a/homeassistant/components/homeassistant/scene.py b/homeassistant/components/homeassistant/scene.py index 13a4ef66383..9ae271baa72 100644 --- a/homeassistant/components/homeassistant/scene.py +++ b/homeassistant/components/homeassistant/scene.py @@ -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), diff --git a/homeassistant/components/homeassistant/triggers/numeric_state.py b/homeassistant/components/homeassistant/triggers/numeric_state.py index 366f937a192..f315addb272 100644 --- a/homeassistant/components/homeassistant/triggers/numeric_state.py +++ b/homeassistant/components/homeassistant/triggers/numeric_state.py @@ -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 {} diff --git a/homeassistant/components/homeassistant/triggers/state.py b/homeassistant/components/homeassistant/triggers/state.py index 2c96b6be944..12c42a95978 100644 --- a/homeassistant/components/homeassistant/triggers/state.py +++ b/homeassistant/components/homeassistant/triggers/state.py @@ -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: diff --git a/homeassistant/components/homeassistant/triggers/time.py b/homeassistant/components/homeassistant/triggers/time.py index ff78e4c43c8..f661ae21a5b 100644 --- a/homeassistant/components/homeassistant/triggers/time.py +++ b/homeassistant/components/homeassistant/triggers/time.py @@ -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'", ) diff --git a/homeassistant/helpers/event.py b/homeassistant/helpers/event.py index 85eebf05298..1fe542c096c 100644 --- a/homeassistant/helpers/event.py +++ b/homeassistant/helpers/event.py @@ -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 diff --git a/mypy.ini b/mypy.ini index c3dd71d8229..f6079c74e13 100644 --- a/mypy.ini +++ b/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 diff --git a/script/hassfest/mypy_config.py b/script/hassfest/mypy_config.py index dbde9516f8c..d234f96589a 100644 --- a/script/hassfest/mypy_config.py +++ b/script/hassfest/mypy_config.py @@ -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.*",