2017-05-02 18:18:47 +02:00
|
|
|
"""Typing Helpers for Home Assistant."""
|
2022-01-12 07:56:35 +01:00
|
|
|
from collections.abc import Mapping
|
2020-12-19 13:46:27 +02:00
|
|
|
from enum import Enum
|
2023-07-23 21:51:54 +02:00
|
|
|
from typing import Any, Generic, TypeVar
|
2016-07-31 22:56:57 +02:00
|
|
|
|
2016-08-30 18:22:52 +02:00
|
|
|
import homeassistant.core
|
2016-08-07 18:26:35 -05:00
|
|
|
|
2023-07-23 21:51:54 +02:00
|
|
|
_DataT = TypeVar("_DataT")
|
|
|
|
|
2022-01-11 21:26:03 +01:00
|
|
|
GPSType = tuple[float, float]
|
|
|
|
ConfigType = dict[str, Any]
|
2019-06-15 01:48:21 +03:00
|
|
|
ContextType = homeassistant.core.Context
|
2022-01-11 21:26:03 +01:00
|
|
|
DiscoveryInfoType = dict[str, Any]
|
|
|
|
ServiceDataType = dict[str, Any]
|
2023-01-23 09:10:05 +01:00
|
|
|
StateType = str | int | float | None
|
|
|
|
TemplateVarsType = Mapping[str, Any] | None
|
2016-07-31 22:56:57 +02:00
|
|
|
|
2016-08-30 18:22:52 +02:00
|
|
|
# Custom type for recorder Queries
|
|
|
|
QueryType = Any
|
2020-12-19 13:46:27 +02:00
|
|
|
|
|
|
|
|
|
|
|
class UndefinedType(Enum):
|
|
|
|
"""Singleton type for use with not set sentinel values."""
|
|
|
|
|
|
|
|
_singleton = 0
|
|
|
|
|
|
|
|
|
|
|
|
UNDEFINED = UndefinedType._singleton # pylint: disable=protected-access
|
2021-05-02 00:15:27 +02:00
|
|
|
|
2022-09-22 07:18:00 +02:00
|
|
|
|
2021-05-02 00:15:27 +02:00
|
|
|
# The following types should not used and
|
|
|
|
# are not present in the core code base.
|
|
|
|
# They are kept in order not to break custom integrations
|
|
|
|
# that may rely on them.
|
|
|
|
# In due time they will be removed.
|
|
|
|
HomeAssistantType = homeassistant.core.HomeAssistant
|
|
|
|
ServiceCallType = homeassistant.core.ServiceCall
|
2023-07-23 21:51:54 +02:00
|
|
|
|
|
|
|
|
|
|
|
class EventType(homeassistant.core.Event, Generic[_DataT]):
|
|
|
|
"""Generic Event class to better type data."""
|
|
|
|
|
|
|
|
data: _DataT # type: ignore[assignment]
|