mirror of
https://github.com/home-assistant/core.git
synced 2025-07-09 14:27:07 +00:00
Improve type hints in geo-location (#78352)
This commit is contained in:
parent
0ab19fe6f6
commit
49ab5cfc9c
@ -1,10 +1,20 @@
|
|||||||
"""Offer geolocation automation rules."""
|
"""Offer geolocation automation rules."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
from typing import Final
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.const import CONF_EVENT, CONF_PLATFORM, CONF_SOURCE, CONF_ZONE
|
from homeassistant.const import CONF_EVENT, CONF_PLATFORM, CONF_SOURCE, CONF_ZONE
|
||||||
from homeassistant.core import CALLBACK_TYPE, HassJob, HomeAssistant, callback
|
from homeassistant.core import (
|
||||||
|
CALLBACK_TYPE,
|
||||||
|
Event,
|
||||||
|
HassJob,
|
||||||
|
HomeAssistant,
|
||||||
|
State,
|
||||||
|
callback,
|
||||||
|
)
|
||||||
from homeassistant.helpers import condition, config_validation as cv
|
from homeassistant.helpers import condition, config_validation as cv
|
||||||
from homeassistant.helpers.config_validation import entity_domain
|
from homeassistant.helpers.config_validation import entity_domain
|
||||||
from homeassistant.helpers.event import TrackStates, async_track_state_change_filtered
|
from homeassistant.helpers.event import TrackStates, async_track_state_change_filtered
|
||||||
@ -13,13 +23,11 @@ from homeassistant.helpers.typing import ConfigType
|
|||||||
|
|
||||||
from . import DOMAIN
|
from . import DOMAIN
|
||||||
|
|
||||||
# mypy: allow-untyped-defs, no-check-untyped-defs
|
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
EVENT_ENTER = "enter"
|
EVENT_ENTER: Final = "enter"
|
||||||
EVENT_LEAVE = "leave"
|
EVENT_LEAVE: Final = "leave"
|
||||||
DEFAULT_EVENT = EVENT_ENTER
|
DEFAULT_EVENT: Final = EVENT_ENTER
|
||||||
|
|
||||||
TRIGGER_SCHEMA = cv.TRIGGER_BASE_SCHEMA.extend(
|
TRIGGER_SCHEMA = cv.TRIGGER_BASE_SCHEMA.extend(
|
||||||
{
|
{
|
||||||
@ -33,9 +41,9 @@ TRIGGER_SCHEMA = cv.TRIGGER_BASE_SCHEMA.extend(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def source_match(state, source):
|
def source_match(state: State | None, source: str) -> bool:
|
||||||
"""Check if the state matches the provided source."""
|
"""Check if the state matches the provided source."""
|
||||||
return state and state.attributes.get("source") == source
|
return state is not None and state.attributes.get("source") == source
|
||||||
|
|
||||||
|
|
||||||
async def async_attach_trigger(
|
async def async_attach_trigger(
|
||||||
@ -47,12 +55,12 @@ async def async_attach_trigger(
|
|||||||
"""Listen for state changes based on configuration."""
|
"""Listen for state changes based on configuration."""
|
||||||
trigger_data = trigger_info["trigger_data"]
|
trigger_data = trigger_info["trigger_data"]
|
||||||
source: str = config[CONF_SOURCE].lower()
|
source: str = config[CONF_SOURCE].lower()
|
||||||
zone_entity_id = config.get(CONF_ZONE)
|
zone_entity_id: str = config[CONF_ZONE]
|
||||||
trigger_event = config.get(CONF_EVENT)
|
trigger_event: str = config[CONF_EVENT]
|
||||||
job = HassJob(action)
|
job = HassJob(action)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def state_change_listener(event):
|
def state_change_listener(event: Event) -> None:
|
||||||
"""Handle specific state changes."""
|
"""Handle specific state changes."""
|
||||||
# Skip if the event's source does not match the trigger's source.
|
# Skip if the event's source does not match the trigger's source.
|
||||||
from_state = event.data.get("old_state")
|
from_state = event.data.get("old_state")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user