Use HassKey in core components (d-z) (#126324)
* Use HassKey in core components (d-s) * Add * Undo light * Undo device_tracker * Undo notify * Undo sensor * Undo stt * Improve
This commit is contained in:
parent
52d349d776
commit
94df0bd5ab
22 changed files with 116 additions and 119 deletions
|
@ -16,11 +16,13 @@ from homeassistant.helpers import config_validation as cv
|
|||
from homeassistant.helpers.entity import Entity, EntityDescription
|
||||
from homeassistant.helpers.entity_component import EntityComponent
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.util.hass_dict import HassKey
|
||||
|
||||
from .const import DOMAIN, SERVICE_SET_VALUE
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
DOMAIN_DATA: HassKey[EntityComponent[DateEntity]] = HassKey(DOMAIN)
|
||||
ENTITY_ID_FORMAT = DOMAIN + ".{}"
|
||||
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA
|
||||
PLATFORM_SCHEMA_BASE = cv.PLATFORM_SCHEMA_BASE
|
||||
|
@ -37,7 +39,7 @@ async def _async_set_value(entity: DateEntity, service_call: ServiceCall) -> Non
|
|||
|
||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
"""Set up Date entities."""
|
||||
component = hass.data[DOMAIN] = EntityComponent[DateEntity](
|
||||
component = hass.data[DOMAIN_DATA] = EntityComponent[DateEntity](
|
||||
_LOGGER, DOMAIN, hass, SCAN_INTERVAL
|
||||
)
|
||||
await component.async_setup(config)
|
||||
|
@ -51,14 +53,12 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Set up a config entry."""
|
||||
component: EntityComponent[DateEntity] = hass.data[DOMAIN]
|
||||
return await component.async_setup_entry(entry)
|
||||
return await hass.data[DOMAIN_DATA].async_setup_entry(entry)
|
||||
|
||||
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Unload a config entry."""
|
||||
component: EntityComponent[DateEntity] = hass.data[DOMAIN]
|
||||
return await component.async_unload_entry(entry)
|
||||
return await hass.data[DOMAIN_DATA].async_unload_entry(entry)
|
||||
|
||||
|
||||
class DateEntityDescription(EntityDescription, frozen_or_thawed=True):
|
||||
|
|
|
@ -16,11 +16,13 @@ from homeassistant.helpers.entity import Entity, EntityDescription
|
|||
from homeassistant.helpers.entity_component import EntityComponent
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.util import dt as dt_util
|
||||
from homeassistant.util.hass_dict import HassKey
|
||||
|
||||
from .const import ATTR_DATETIME, DOMAIN, SERVICE_SET_VALUE
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
DOMAIN_DATA: HassKey[EntityComponent[DateTimeEntity]] = HassKey(DOMAIN)
|
||||
ENTITY_ID_FORMAT = DOMAIN + ".{}"
|
||||
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA
|
||||
PLATFORM_SCHEMA_BASE = cv.PLATFORM_SCHEMA_BASE
|
||||
|
@ -40,7 +42,7 @@ async def _async_set_value(entity: DateTimeEntity, service_call: ServiceCall) ->
|
|||
|
||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
"""Set up Date/Time entities."""
|
||||
component = hass.data[DOMAIN] = EntityComponent[DateTimeEntity](
|
||||
component = hass.data[DOMAIN_DATA] = EntityComponent[DateTimeEntity](
|
||||
_LOGGER, DOMAIN, hass, SCAN_INTERVAL
|
||||
)
|
||||
await component.async_setup(config)
|
||||
|
@ -58,14 +60,12 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Set up a config entry."""
|
||||
component: EntityComponent[DateTimeEntity] = hass.data[DOMAIN]
|
||||
return await component.async_setup_entry(entry)
|
||||
return await hass.data[DOMAIN_DATA].async_setup_entry(entry)
|
||||
|
||||
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Unload a config entry."""
|
||||
component: EntityComponent[DateTimeEntity] = hass.data[DOMAIN]
|
||||
return await component.async_unload_entry(entry)
|
||||
return await hass.data[DOMAIN_DATA].async_unload_entry(entry)
|
||||
|
||||
|
||||
class DateTimeEntityDescription(EntityDescription, frozen_or_thawed=True):
|
||||
|
|
|
@ -17,10 +17,12 @@ from homeassistant.helpers.entity_component import EntityComponent
|
|||
from homeassistant.helpers.restore_state import ExtraStoredData, RestoreEntity
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.util import dt as dt_util
|
||||
from homeassistant.util.hass_dict import HassKey
|
||||
|
||||
from .const import ATTR_EVENT_TYPE, ATTR_EVENT_TYPES, DOMAIN
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
DOMAIN_DATA: HassKey[EntityComponent[EventEntity]] = HassKey(DOMAIN)
|
||||
ENTITY_ID_FORMAT = DOMAIN + ".{}"
|
||||
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA
|
||||
PLATFORM_SCHEMA_BASE = cv.PLATFORM_SCHEMA_BASE
|
||||
|
@ -51,7 +53,7 @@ __all__ = [
|
|||
|
||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
"""Set up Event entities."""
|
||||
component = hass.data[DOMAIN] = EntityComponent[EventEntity](
|
||||
component = hass.data[DOMAIN_DATA] = EntityComponent[EventEntity](
|
||||
_LOGGER, DOMAIN, hass, SCAN_INTERVAL
|
||||
)
|
||||
await component.async_setup(config)
|
||||
|
@ -60,14 +62,12 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Set up a config entry."""
|
||||
component: EntityComponent[EventEntity] = hass.data[DOMAIN]
|
||||
return await component.async_setup_entry(entry)
|
||||
return await hass.data[DOMAIN_DATA].async_setup_entry(entry)
|
||||
|
||||
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Unload a config entry."""
|
||||
component: EntityComponent[EventEntity] = hass.data[DOMAIN]
|
||||
return await component.async_unload_entry(entry)
|
||||
return await hass.data[DOMAIN_DATA].async_unload_entry(entry)
|
||||
|
||||
|
||||
class EventEntityDescription(EntityDescription, frozen_or_thawed=True):
|
||||
|
|
|
@ -34,6 +34,7 @@ from homeassistant.helpers.entity_component import EntityComponent
|
|||
from homeassistant.helpers.entity_platform import EntityPlatform
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.loader import bind_hass
|
||||
from homeassistant.util.hass_dict import HassKey
|
||||
from homeassistant.util.percentage import (
|
||||
percentage_to_ranged_value,
|
||||
ranged_value_to_percentage,
|
||||
|
@ -42,6 +43,7 @@ from homeassistant.util.percentage import (
|
|||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
DOMAIN = "fan"
|
||||
DOMAIN_DATA: HassKey[EntityComponent[FanEntity]] = HassKey(DOMAIN)
|
||||
ENTITY_ID_FORMAT = DOMAIN + ".{}"
|
||||
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA
|
||||
PLATFORM_SCHEMA_BASE = cv.PLATFORM_SCHEMA_BASE
|
||||
|
@ -119,7 +121,7 @@ def is_on(hass: HomeAssistant, entity_id: str) -> bool:
|
|||
|
||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
"""Expose fan control via statemachine and services."""
|
||||
component = hass.data[DOMAIN] = EntityComponent[FanEntity](
|
||||
component = hass.data[DOMAIN_DATA] = EntityComponent[FanEntity](
|
||||
_LOGGER, DOMAIN, hass, SCAN_INTERVAL
|
||||
)
|
||||
|
||||
|
@ -201,14 +203,12 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Set up a config entry."""
|
||||
component: EntityComponent[FanEntity] = hass.data[DOMAIN]
|
||||
return await component.async_setup_entry(entry)
|
||||
return await hass.data[DOMAIN_DATA].async_setup_entry(entry)
|
||||
|
||||
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Unload a config entry."""
|
||||
component: EntityComponent[FanEntity] = hass.data[DOMAIN]
|
||||
return await component.async_unload_entry(entry)
|
||||
return await hass.data[DOMAIN_DATA].async_unload_entry(entry)
|
||||
|
||||
|
||||
class FanEntityDescription(ToggleEntityDescription, frozen_or_thawed=True):
|
||||
|
|
|
@ -14,10 +14,12 @@ from homeassistant.helpers import config_validation as cv
|
|||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.helpers.entity_component import EntityComponent
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.util.hass_dict import HassKey
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
DOMAIN = "geo_location"
|
||||
DOMAIN_DATA: HassKey[EntityComponent[GeolocationEvent]] = HassKey(DOMAIN)
|
||||
ENTITY_ID_FORMAT = DOMAIN + ".{}"
|
||||
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA
|
||||
PLATFORM_SCHEMA_BASE = cv.PLATFORM_SCHEMA_BASE
|
||||
|
@ -32,7 +34,7 @@ ATTR_SOURCE = "source"
|
|||
|
||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
"""Set up the Geolocation component."""
|
||||
component = hass.data[DOMAIN] = EntityComponent[GeolocationEvent](
|
||||
component = hass.data[DOMAIN_DATA] = EntityComponent[GeolocationEvent](
|
||||
_LOGGER, DOMAIN, hass, SCAN_INTERVAL
|
||||
)
|
||||
await component.async_setup(config)
|
||||
|
@ -41,14 +43,12 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Set up a config entry."""
|
||||
component: EntityComponent[GeolocationEvent] = hass.data[DOMAIN]
|
||||
return await component.async_setup_entry(entry)
|
||||
return await hass.data[DOMAIN_DATA].async_setup_entry(entry)
|
||||
|
||||
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Unload a config entry."""
|
||||
component: EntityComponent[GeolocationEvent] = hass.data[DOMAIN]
|
||||
return await component.async_unload_entry(entry)
|
||||
return await hass.data[DOMAIN_DATA].async_unload_entry(entry)
|
||||
|
||||
|
||||
CACHED_PROPERTIES_WITH_ATTR_ = {
|
||||
|
|
|
@ -30,6 +30,7 @@ from homeassistant.helpers.entity import ToggleEntity, ToggleEntityDescription
|
|||
from homeassistant.helpers.entity_component import EntityComponent
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.loader import bind_hass
|
||||
from homeassistant.util.hass_dict import HassKey
|
||||
|
||||
from .const import ( # noqa: F401
|
||||
_DEPRECATED_DEVICE_CLASS_DEHUMIDIFIER,
|
||||
|
@ -61,6 +62,7 @@ from .const import ( # noqa: F401
|
|||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
DOMAIN_DATA: HassKey[EntityComponent[HumidifierEntity]] = HassKey(DOMAIN)
|
||||
ENTITY_ID_FORMAT = DOMAIN + ".{}"
|
||||
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA
|
||||
PLATFORM_SCHEMA_BASE = cv.PLATFORM_SCHEMA_BASE
|
||||
|
@ -94,7 +96,7 @@ def is_on(hass: HomeAssistant, entity_id: str) -> bool:
|
|||
|
||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
"""Set up humidifier devices."""
|
||||
component = hass.data[DOMAIN] = EntityComponent[HumidifierEntity](
|
||||
component = hass.data[DOMAIN_DATA] = EntityComponent[HumidifierEntity](
|
||||
_LOGGER, DOMAIN, hass, SCAN_INTERVAL
|
||||
)
|
||||
await component.async_setup(config)
|
||||
|
@ -123,14 +125,12 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Set up a config entry."""
|
||||
component: EntityComponent[HumidifierEntity] = hass.data[DOMAIN]
|
||||
return await component.async_setup_entry(entry)
|
||||
return await hass.data[DOMAIN_DATA].async_setup_entry(entry)
|
||||
|
||||
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Unload a config entry."""
|
||||
component: EntityComponent[HumidifierEntity] = hass.data[DOMAIN]
|
||||
return await component.async_unload_entry(entry)
|
||||
return await hass.data[DOMAIN_DATA].async_unload_entry(entry)
|
||||
|
||||
|
||||
class HumidifierEntityDescription(ToggleEntityDescription, frozen_or_thawed=True):
|
||||
|
|
|
@ -13,6 +13,7 @@ from homeassistant.helpers import config_validation as cv
|
|||
from homeassistant.helpers.entity import Entity, EntityDescription
|
||||
from homeassistant.helpers.entity_component import EntityComponent
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.util.hass_dict import HassKey
|
||||
|
||||
from .const import (
|
||||
DOMAIN,
|
||||
|
@ -25,6 +26,7 @@ from .const import (
|
|||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
DOMAIN_DATA: HassKey[EntityComponent[LawnMowerEntity]] = HassKey(DOMAIN)
|
||||
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA
|
||||
PLATFORM_SCHEMA_BASE = cv.PLATFORM_SCHEMA_BASE
|
||||
SCAN_INTERVAL = timedelta(seconds=60)
|
||||
|
@ -32,7 +34,7 @@ SCAN_INTERVAL = timedelta(seconds=60)
|
|||
|
||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
"""Set up the lawn_mower component."""
|
||||
component = hass.data[DOMAIN] = EntityComponent[LawnMowerEntity](
|
||||
component = hass.data[DOMAIN_DATA] = EntityComponent[LawnMowerEntity](
|
||||
_LOGGER, DOMAIN, hass, SCAN_INTERVAL
|
||||
)
|
||||
await component.async_setup(config)
|
||||
|
@ -55,14 +57,12 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Set up lawn mower devices."""
|
||||
component: EntityComponent[LawnMowerEntity] = hass.data[DOMAIN]
|
||||
return await component.async_setup_entry(entry)
|
||||
return await hass.data[DOMAIN_DATA].async_setup_entry(entry)
|
||||
|
||||
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Unload a config entry."""
|
||||
component: EntityComponent[LawnMowerEntity] = hass.data[DOMAIN]
|
||||
return await component.async_unload_entry(entry)
|
||||
return await hass.data[DOMAIN_DATA].async_unload_entry(entry)
|
||||
|
||||
|
||||
class LawnMowerEntityEntityDescription(EntityDescription, frozen_or_thawed=True):
|
||||
|
|
|
@ -39,11 +39,13 @@ from homeassistant.helpers.deprecation import (
|
|||
from homeassistant.helpers.entity import Entity, EntityDescription
|
||||
from homeassistant.helpers.entity_component import EntityComponent
|
||||
from homeassistant.helpers.typing import ConfigType, StateType
|
||||
from homeassistant.util.hass_dict import HassKey
|
||||
|
||||
from .const import DOMAIN
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
DOMAIN_DATA: HassKey[EntityComponent[LockEntity]] = HassKey(DOMAIN)
|
||||
ENTITY_ID_FORMAT = DOMAIN + ".{}"
|
||||
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA
|
||||
PLATFORM_SCHEMA_BASE = cv.PLATFORM_SCHEMA_BASE
|
||||
|
@ -76,7 +78,7 @@ PROP_TO_ATTR = {"changed_by": ATTR_CHANGED_BY, "code_format": ATTR_CODE_FORMAT}
|
|||
|
||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
"""Track states and offer events for locks."""
|
||||
component = hass.data[DOMAIN] = EntityComponent[LockEntity](
|
||||
component = hass.data[DOMAIN_DATA] = EntityComponent[LockEntity](
|
||||
_LOGGER, DOMAIN, hass, SCAN_INTERVAL
|
||||
)
|
||||
|
||||
|
@ -100,14 +102,12 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Set up a config entry."""
|
||||
component: EntityComponent[LockEntity] = hass.data[DOMAIN]
|
||||
return await component.async_setup_entry(entry)
|
||||
return await hass.data[DOMAIN_DATA].async_setup_entry(entry)
|
||||
|
||||
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Unload a config entry."""
|
||||
component: EntityComponent[LockEntity] = hass.data[DOMAIN]
|
||||
return await component.async_unload_entry(entry)
|
||||
return await hass.data[DOMAIN_DATA].async_unload_entry(entry)
|
||||
|
||||
|
||||
class LockEntityDescription(EntityDescription, frozen_or_thawed=True):
|
||||
|
|
|
@ -59,6 +59,7 @@ from homeassistant.helpers.entity_component import EntityComponent
|
|||
from homeassistant.helpers.network import get_url
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.loader import bind_hass
|
||||
from homeassistant.util.hass_dict import HassKey
|
||||
|
||||
from .browse_media import BrowseMedia, async_process_play_media_url # noqa: F401
|
||||
from .const import ( # noqa: F401
|
||||
|
@ -132,6 +133,7 @@ from .errors import BrowseError
|
|||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
DOMAIN_DATA: HassKey[EntityComponent[MediaPlayerEntity]] = HassKey(DOMAIN)
|
||||
ENTITY_ID_FORMAT = DOMAIN + ".{}"
|
||||
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA
|
||||
PLATFORM_SCHEMA_BASE = cv.PLATFORM_SCHEMA_BASE
|
||||
|
@ -264,7 +266,7 @@ def _rename_keys(**keys: Any) -> Callable[[dict[str, Any]], dict[str, Any]]:
|
|||
|
||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
"""Track states and offer events for media_players."""
|
||||
component = hass.data[DOMAIN] = EntityComponent[MediaPlayerEntity](
|
||||
component = hass.data[DOMAIN_DATA] = EntityComponent[MediaPlayerEntity](
|
||||
logging.getLogger(__name__), DOMAIN, hass, SCAN_INTERVAL
|
||||
)
|
||||
|
||||
|
@ -438,14 +440,12 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Set up a config entry."""
|
||||
component: EntityComponent[MediaPlayerEntity] = hass.data[DOMAIN]
|
||||
return await component.async_setup_entry(entry)
|
||||
return await hass.data[DOMAIN_DATA].async_setup_entry(entry)
|
||||
|
||||
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Unload a config entry."""
|
||||
component: EntityComponent[MediaPlayerEntity] = hass.data[DOMAIN]
|
||||
return await component.async_unload_entry(entry)
|
||||
return await hass.data[DOMAIN_DATA].async_unload_entry(entry)
|
||||
|
||||
|
||||
class MediaPlayerEntityDescription(EntityDescription, frozen_or_thawed=True):
|
||||
|
@ -1282,8 +1282,7 @@ async def websocket_browse_media(
|
|||
To use, media_player integrations can implement
|
||||
MediaPlayerEntity.async_browse_media()
|
||||
"""
|
||||
component: EntityComponent[MediaPlayerEntity] = hass.data[DOMAIN]
|
||||
player = component.get_entity(msg["entity_id"])
|
||||
player = hass.data[DOMAIN_DATA].get_entity(msg["entity_id"])
|
||||
|
||||
if player is None:
|
||||
connection.send_error(msg["id"], "entity_not_found", "Entity not found")
|
||||
|
|
|
@ -28,6 +28,7 @@ from homeassistant.helpers.entity_component import EntityComponent
|
|||
from homeassistant.helpers.restore_state import ExtraStoredData, RestoreEntity
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.loader import async_suggest_report_issue
|
||||
from homeassistant.util.hass_dict import HassKey
|
||||
|
||||
from .const import ( # noqa: F401
|
||||
ATTR_MAX,
|
||||
|
@ -49,6 +50,7 @@ from .websocket_api import async_setup as async_setup_ws_api
|
|||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
DOMAIN_DATA: HassKey[EntityComponent[NumberEntity]] = HassKey(DOMAIN)
|
||||
ENTITY_ID_FORMAT = DOMAIN + ".{}"
|
||||
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA
|
||||
PLATFORM_SCHEMA_BASE = cv.PLATFORM_SCHEMA_BASE
|
||||
|
@ -81,7 +83,7 @@ __all__ = [
|
|||
|
||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
"""Set up Number entities."""
|
||||
component = hass.data[DOMAIN] = EntityComponent[NumberEntity](
|
||||
component = hass.data[DOMAIN_DATA] = EntityComponent[NumberEntity](
|
||||
_LOGGER, DOMAIN, hass, SCAN_INTERVAL
|
||||
)
|
||||
async_setup_ws_api(hass)
|
||||
|
@ -124,14 +126,12 @@ async def async_set_value(entity: NumberEntity, service_call: ServiceCall) -> No
|
|||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Set up a config entry."""
|
||||
component: EntityComponent[NumberEntity] = hass.data[DOMAIN]
|
||||
return await component.async_setup_entry(entry)
|
||||
return await hass.data[DOMAIN_DATA].async_setup_entry(entry)
|
||||
|
||||
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Unload a config entry."""
|
||||
component: EntityComponent[NumberEntity] = hass.data[DOMAIN]
|
||||
return await component.async_unload_entry(entry)
|
||||
return await hass.data[DOMAIN_DATA].async_unload_entry(entry)
|
||||
|
||||
|
||||
class NumberEntityDescription(EntityDescription, frozen_or_thawed=True):
|
||||
|
|
|
@ -32,10 +32,12 @@ from homeassistant.helpers.entity import ToggleEntity, ToggleEntityDescription
|
|||
from homeassistant.helpers.entity_component import EntityComponent
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.loader import bind_hass
|
||||
from homeassistant.util.hass_dict import HassKey
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
DOMAIN = "remote"
|
||||
DOMAIN_DATA: HassKey[EntityComponent[RemoteEntity]] = HassKey(DOMAIN)
|
||||
ENTITY_ID_FORMAT = DOMAIN + ".{}"
|
||||
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA
|
||||
PLATFORM_SCHEMA_BASE = cv.PLATFORM_SCHEMA_BASE
|
||||
|
@ -98,7 +100,7 @@ def is_on(hass: HomeAssistant, entity_id: str) -> bool:
|
|||
|
||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
"""Track states and offer events for remotes."""
|
||||
component = hass.data[DOMAIN] = EntityComponent[RemoteEntity](
|
||||
component = hass.data[DOMAIN_DATA] = EntityComponent[RemoteEntity](
|
||||
_LOGGER, DOMAIN, hass, SCAN_INTERVAL
|
||||
)
|
||||
await component.async_setup(config)
|
||||
|
@ -155,14 +157,12 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Set up a config entry."""
|
||||
component: EntityComponent[RemoteEntity] = hass.data[DOMAIN]
|
||||
return await component.async_setup_entry(entry)
|
||||
return await hass.data[DOMAIN_DATA].async_setup_entry(entry)
|
||||
|
||||
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Unload a config entry."""
|
||||
component: EntityComponent[RemoteEntity] = hass.data[DOMAIN]
|
||||
return await component.async_unload_entry(entry)
|
||||
return await hass.data[DOMAIN_DATA].async_unload_entry(entry)
|
||||
|
||||
|
||||
class RemoteEntityDescription(ToggleEntityDescription, frozen_or_thawed=True):
|
||||
|
|
|
@ -17,8 +17,10 @@ from homeassistant.helpers.entity_component import EntityComponent
|
|||
from homeassistant.helpers.restore_state import RestoreEntity
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.util import dt as dt_util
|
||||
from homeassistant.util.hass_dict import HassKey
|
||||
|
||||
DOMAIN: Final = "scene"
|
||||
DOMAIN_DATA: HassKey[EntityComponent[Scene]] = HassKey(DOMAIN)
|
||||
STATES: Final = "states"
|
||||
|
||||
|
||||
|
@ -60,7 +62,7 @@ PLATFORM_SCHEMA = vol.Schema(
|
|||
|
||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
"""Set up the scenes."""
|
||||
component = hass.data[DOMAIN] = EntityComponent[Scene](
|
||||
component = hass.data[DOMAIN_DATA] = EntityComponent[Scene](
|
||||
logging.getLogger(__name__), DOMAIN, hass
|
||||
)
|
||||
|
||||
|
@ -83,14 +85,12 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Set up a config entry."""
|
||||
component: EntityComponent[Scene] = hass.data[DOMAIN]
|
||||
return await component.async_setup_entry(entry)
|
||||
return await hass.data[DOMAIN_DATA].async_setup_entry(entry)
|
||||
|
||||
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Unload a config entry."""
|
||||
component: EntityComponent[Scene] = hass.data[DOMAIN]
|
||||
return await component.async_unload_entry(entry)
|
||||
return await hass.data[DOMAIN_DATA].async_unload_entry(entry)
|
||||
|
||||
|
||||
class Scene(RestoreEntity):
|
||||
|
|
|
@ -16,6 +16,7 @@ from homeassistant.helpers import config_validation as cv
|
|||
from homeassistant.helpers.entity import Entity, EntityDescription
|
||||
from homeassistant.helpers.entity_component import EntityComponent
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.util.hass_dict import HassKey
|
||||
|
||||
from .const import (
|
||||
ATTR_CYCLE,
|
||||
|
@ -31,6 +32,7 @@ from .const import (
|
|||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
DOMAIN_DATA: HassKey[EntityComponent[SelectEntity]] = HassKey(DOMAIN)
|
||||
ENTITY_ID_FORMAT = DOMAIN + ".{}"
|
||||
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA
|
||||
PLATFORM_SCHEMA_BASE = cv.PLATFORM_SCHEMA_BASE
|
||||
|
@ -59,7 +61,7 @@ __all__ = [
|
|||
|
||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
"""Set up Select entities."""
|
||||
component = hass.data[DOMAIN] = EntityComponent[SelectEntity](
|
||||
component = hass.data[DOMAIN_DATA] = EntityComponent[SelectEntity](
|
||||
_LOGGER, DOMAIN, hass, SCAN_INTERVAL
|
||||
)
|
||||
await component.async_setup(config)
|
||||
|
@ -99,14 +101,12 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Set up a config entry."""
|
||||
component: EntityComponent[SelectEntity] = hass.data[DOMAIN]
|
||||
return await component.async_setup_entry(entry)
|
||||
return await hass.data[DOMAIN_DATA].async_setup_entry(entry)
|
||||
|
||||
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Unload a config entry."""
|
||||
component: EntityComponent[SelectEntity] = hass.data[DOMAIN]
|
||||
return await component.async_unload_entry(entry)
|
||||
return await hass.data[DOMAIN_DATA].async_unload_entry(entry)
|
||||
|
||||
|
||||
class SelectEntityDescription(EntityDescription, frozen_or_thawed=True):
|
||||
|
|
|
@ -21,6 +21,7 @@ from homeassistant.helpers.deprecation import (
|
|||
from homeassistant.helpers.entity import ToggleEntity, ToggleEntityDescription
|
||||
from homeassistant.helpers.entity_component import EntityComponent
|
||||
from homeassistant.helpers.typing import ConfigType, VolDictType
|
||||
from homeassistant.util.hass_dict import HassKey
|
||||
|
||||
from .const import ( # noqa: F401
|
||||
_DEPRECATED_SUPPORT_DURATION,
|
||||
|
@ -38,6 +39,7 @@ from .const import ( # noqa: F401
|
|||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
DOMAIN_DATA: HassKey[EntityComponent[SirenEntity]] = HassKey(DOMAIN)
|
||||
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA
|
||||
PLATFORM_SCHEMA_BASE = cv.PLATFORM_SCHEMA_BASE
|
||||
SCAN_INTERVAL = timedelta(seconds=60)
|
||||
|
@ -104,7 +106,7 @@ def process_turn_on_params(
|
|||
|
||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
"""Set up siren devices."""
|
||||
component = hass.data[DOMAIN] = EntityComponent[SirenEntity](
|
||||
component = hass.data[DOMAIN_DATA] = EntityComponent[SirenEntity](
|
||||
_LOGGER, DOMAIN, hass, SCAN_INTERVAL
|
||||
)
|
||||
await component.async_setup(config)
|
||||
|
@ -143,14 +145,12 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Set up a config entry."""
|
||||
component: EntityComponent[SirenEntity] = hass.data[DOMAIN]
|
||||
return await component.async_setup_entry(entry)
|
||||
return await hass.data[DOMAIN_DATA].async_setup_entry(entry)
|
||||
|
||||
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Unload a config entry."""
|
||||
component: EntityComponent[SirenEntity] = hass.data[DOMAIN]
|
||||
return await component.async_unload_entry(entry)
|
||||
return await hass.data[DOMAIN_DATA].async_unload_entry(entry)
|
||||
|
||||
|
||||
class SirenEntityDescription(ToggleEntityDescription, frozen_or_thawed=True):
|
||||
|
|
|
@ -28,11 +28,13 @@ from homeassistant.helpers.entity import ToggleEntity, ToggleEntityDescription
|
|||
from homeassistant.helpers.entity_component import EntityComponent
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.loader import bind_hass
|
||||
from homeassistant.util.hass_dict import HassKey
|
||||
|
||||
from .const import DOMAIN
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
DOMAIN_DATA: HassKey[EntityComponent[SwitchEntity]] = HassKey(DOMAIN)
|
||||
ENTITY_ID_FORMAT = DOMAIN + ".{}"
|
||||
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA
|
||||
PLATFORM_SCHEMA_BASE = cv.PLATFORM_SCHEMA_BASE
|
||||
|
@ -74,7 +76,7 @@ def is_on(hass: HomeAssistant, entity_id: str) -> bool:
|
|||
|
||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
"""Track states and offer events for switches."""
|
||||
component = hass.data[DOMAIN] = EntityComponent[SwitchEntity](
|
||||
component = hass.data[DOMAIN_DATA] = EntityComponent[SwitchEntity](
|
||||
_LOGGER, DOMAIN, hass, SCAN_INTERVAL
|
||||
)
|
||||
await component.async_setup(config)
|
||||
|
@ -88,14 +90,12 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Set up a config entry."""
|
||||
component: EntityComponent[SwitchEntity] = hass.data[DOMAIN]
|
||||
return await component.async_setup_entry(entry)
|
||||
return await hass.data[DOMAIN_DATA].async_setup_entry(entry)
|
||||
|
||||
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Unload a config entry."""
|
||||
component: EntityComponent[SwitchEntity] = hass.data[DOMAIN]
|
||||
return await component.async_unload_entry(entry)
|
||||
return await hass.data[DOMAIN_DATA].async_unload_entry(entry)
|
||||
|
||||
|
||||
class SwitchEntityDescription(ToggleEntityDescription, frozen_or_thawed=True):
|
||||
|
|
|
@ -20,6 +20,7 @@ from homeassistant.helpers.entity import Entity, EntityDescription
|
|||
from homeassistant.helpers.entity_component import EntityComponent
|
||||
from homeassistant.helpers.restore_state import ExtraStoredData, RestoreEntity
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.util.hass_dict import HassKey
|
||||
|
||||
from .const import (
|
||||
ATTR_MAX,
|
||||
|
@ -33,6 +34,7 @@ from .const import (
|
|||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
DOMAIN_DATA: HassKey[EntityComponent[TextEntity]] = HassKey(DOMAIN)
|
||||
ENTITY_ID_FORMAT = DOMAIN + ".{}"
|
||||
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA
|
||||
PLATFORM_SCHEMA_BASE = cv.PLATFORM_SCHEMA_BASE
|
||||
|
@ -46,7 +48,7 @@ __all__ = ["DOMAIN", "TextEntity", "TextEntityDescription", "TextMode"]
|
|||
|
||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
"""Set up Text entities."""
|
||||
component = hass.data[DOMAIN] = EntityComponent[TextEntity](
|
||||
component = hass.data[DOMAIN_DATA] = EntityComponent[TextEntity](
|
||||
_LOGGER, DOMAIN, hass, SCAN_INTERVAL
|
||||
)
|
||||
await component.async_setup(config)
|
||||
|
@ -81,14 +83,12 @@ async def _async_set_value(entity: TextEntity, service_call: ServiceCall) -> Non
|
|||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Set up a config entry."""
|
||||
component: EntityComponent[TextEntity] = hass.data[DOMAIN]
|
||||
return await component.async_setup_entry(entry)
|
||||
return await hass.data[DOMAIN_DATA].async_setup_entry(entry)
|
||||
|
||||
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Unload a config entry."""
|
||||
component: EntityComponent[TextEntity] = hass.data[DOMAIN]
|
||||
return await component.async_unload_entry(entry)
|
||||
return await hass.data[DOMAIN_DATA].async_unload_entry(entry)
|
||||
|
||||
|
||||
class TextMode(StrEnum):
|
||||
|
|
|
@ -16,11 +16,13 @@ from homeassistant.helpers import config_validation as cv
|
|||
from homeassistant.helpers.entity import Entity, EntityDescription
|
||||
from homeassistant.helpers.entity_component import EntityComponent
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.util.hass_dict import HassKey
|
||||
|
||||
from .const import DOMAIN, SERVICE_SET_VALUE
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
DOMAIN_DATA: HassKey[EntityComponent[TimeEntity]] = HassKey(DOMAIN)
|
||||
ENTITY_ID_FORMAT = DOMAIN + ".{}"
|
||||
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA
|
||||
PLATFORM_SCHEMA_BASE = cv.PLATFORM_SCHEMA_BASE
|
||||
|
@ -37,7 +39,7 @@ async def _async_set_value(entity: TimeEntity, service_call: ServiceCall) -> Non
|
|||
|
||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
"""Set up Time entities."""
|
||||
component = hass.data[DOMAIN] = EntityComponent[TimeEntity](
|
||||
component = hass.data[DOMAIN_DATA] = EntityComponent[TimeEntity](
|
||||
_LOGGER, DOMAIN, hass, SCAN_INTERVAL
|
||||
)
|
||||
await component.async_setup(config)
|
||||
|
@ -51,14 +53,12 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Set up a config entry."""
|
||||
component: EntityComponent[TimeEntity] = hass.data[DOMAIN]
|
||||
return await component.async_setup_entry(entry)
|
||||
return await hass.data[DOMAIN_DATA].async_setup_entry(entry)
|
||||
|
||||
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Unload a config entry."""
|
||||
component: EntityComponent[TimeEntity] = hass.data[DOMAIN]
|
||||
return await component.async_unload_entry(entry)
|
||||
return await hass.data[DOMAIN_DATA].async_unload_entry(entry)
|
||||
|
||||
|
||||
class TimeEntityDescription(EntityDescription, frozen_or_thawed=True):
|
||||
|
|
|
@ -21,6 +21,7 @@ from homeassistant.helpers.entity import ABCCachedProperties, EntityDescription
|
|||
from homeassistant.helpers.entity_component import EntityComponent
|
||||
from homeassistant.helpers.restore_state import RestoreEntity
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.util.hass_dict import HassKey
|
||||
|
||||
from .const import (
|
||||
ATTR_AUTO_UPDATE,
|
||||
|
@ -41,6 +42,7 @@ from .const import (
|
|||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
DOMAIN_DATA: HassKey[EntityComponent[UpdateEntity]] = HassKey(DOMAIN)
|
||||
ENTITY_ID_FORMAT: Final = DOMAIN + ".{}"
|
||||
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA
|
||||
PLATFORM_SCHEMA_BASE = cv.PLATFORM_SCHEMA_BASE
|
||||
|
@ -78,7 +80,7 @@ __all__ = [
|
|||
|
||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
"""Set up Select entities."""
|
||||
component = hass.data[DOMAIN] = EntityComponent[UpdateEntity](
|
||||
component = hass.data[DOMAIN_DATA] = EntityComponent[UpdateEntity](
|
||||
_LOGGER, DOMAIN, hass, SCAN_INTERVAL
|
||||
)
|
||||
await component.async_setup(config)
|
||||
|
@ -111,14 +113,12 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Set up a config entry."""
|
||||
component: EntityComponent[UpdateEntity] = hass.data[DOMAIN]
|
||||
return await component.async_setup_entry(entry)
|
||||
return await hass.data[DOMAIN_DATA].async_setup_entry(entry)
|
||||
|
||||
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Unload a config entry."""
|
||||
component: EntityComponent[UpdateEntity] = hass.data[DOMAIN]
|
||||
return await component.async_unload_entry(entry)
|
||||
return await hass.data[DOMAIN_DATA].async_unload_entry(entry)
|
||||
|
||||
|
||||
async def async_install(entity: UpdateEntity, service_call: ServiceCall) -> None:
|
||||
|
@ -492,8 +492,7 @@ async def websocket_release_notes(
|
|||
msg: dict[str, Any],
|
||||
) -> None:
|
||||
"""Get the full release notes for a entity."""
|
||||
component: EntityComponent[UpdateEntity] = hass.data[DOMAIN]
|
||||
entity = component.get_entity(msg["entity_id"])
|
||||
entity = hass.data[DOMAIN_DATA].get_entity(msg["entity_id"])
|
||||
|
||||
if entity is None:
|
||||
connection.send_error(
|
||||
|
|
|
@ -28,11 +28,13 @@ from homeassistant.helpers.entity_component import EntityComponent
|
|||
from homeassistant.helpers.icon import icon_for_battery_level
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.loader import bind_hass
|
||||
from homeassistant.util.hass_dict import HassKey
|
||||
|
||||
from .const import DOMAIN, STATE_CLEANING, STATE_DOCKED, STATE_ERROR, STATE_RETURNING
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
DOMAIN_DATA: HassKey[EntityComponent[StateVacuumEntity]] = HassKey(DOMAIN)
|
||||
ENTITY_ID_FORMAT = DOMAIN + ".{}"
|
||||
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA
|
||||
PLATFORM_SCHEMA_BASE = cv.PLATFORM_SCHEMA_BASE
|
||||
|
@ -108,7 +110,7 @@ def is_on(hass: HomeAssistant, entity_id: str) -> bool:
|
|||
|
||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
"""Set up the vacuum component."""
|
||||
component = hass.data[DOMAIN] = EntityComponent[StateVacuumEntity](
|
||||
component = hass.data[DOMAIN_DATA] = EntityComponent[StateVacuumEntity](
|
||||
_LOGGER, DOMAIN, hass, SCAN_INTERVAL
|
||||
)
|
||||
|
||||
|
@ -171,14 +173,12 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Set up a config entry."""
|
||||
component: EntityComponent[StateVacuumEntity] = hass.data[DOMAIN]
|
||||
return await component.async_setup_entry(entry)
|
||||
return await hass.data[DOMAIN_DATA].async_setup_entry(entry)
|
||||
|
||||
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Unload a config entry."""
|
||||
component: EntityComponent[StateVacuumEntity] = hass.data[DOMAIN]
|
||||
return await component.async_unload_entry(entry)
|
||||
return await hass.data[DOMAIN_DATA].async_unload_entry(entry)
|
||||
|
||||
|
||||
class StateVacuumEntityDescription(EntityDescription, frozen_or_thawed=True):
|
||||
|
|
|
@ -27,10 +27,12 @@ from homeassistant.helpers import config_validation as cv
|
|||
from homeassistant.helpers.entity import Entity, EntityDescription
|
||||
from homeassistant.helpers.entity_component import EntityComponent
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.util.hass_dict import HassKey
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
DOMAIN = "valve"
|
||||
DOMAIN_DATA: HassKey[EntityComponent[ValveEntity]] = HassKey(DOMAIN)
|
||||
ENTITY_ID_FORMAT = DOMAIN + ".{}"
|
||||
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA
|
||||
PLATFORM_SCHEMA_BASE = cv.PLATFORM_SCHEMA_BASE
|
||||
|
@ -64,7 +66,7 @@ ATTR_POSITION = "position"
|
|||
|
||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
"""Track states and offer events for valves."""
|
||||
component = hass.data[DOMAIN] = EntityComponent[ValveEntity](
|
||||
component = hass.data[DOMAIN_DATA] = EntityComponent[ValveEntity](
|
||||
_LOGGER, DOMAIN, hass, SCAN_INTERVAL
|
||||
)
|
||||
|
||||
|
@ -108,14 +110,12 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Set up a config entry."""
|
||||
component: EntityComponent[ValveEntity] = hass.data[DOMAIN]
|
||||
return await component.async_setup_entry(entry)
|
||||
return await hass.data[DOMAIN_DATA].async_setup_entry(entry)
|
||||
|
||||
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Unload a config entry."""
|
||||
component: EntityComponent[ValveEntity] = hass.data[DOMAIN]
|
||||
return await component.async_unload_entry(entry)
|
||||
return await hass.data[DOMAIN_DATA].async_unload_entry(entry)
|
||||
|
||||
|
||||
@dataclass(frozen=True, kw_only=True)
|
||||
|
|
|
@ -19,6 +19,7 @@ from homeassistant.helpers.entity_component import EntityComponent
|
|||
from homeassistant.helpers.restore_state import RestoreEntity
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.util import dt as dt_util
|
||||
from homeassistant.util.hass_dict import HassKey
|
||||
|
||||
from .const import DOMAIN
|
||||
from .models import DetectionResult, WakeWord
|
||||
|
@ -35,6 +36,7 @@ __all__ = [
|
|||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
CONFIG_SCHEMA = cv.empty_config_schema(DOMAIN)
|
||||
DOMAIN_DATA: HassKey[EntityComponent[WakeWordDetectionEntity]] = HassKey(DOMAIN)
|
||||
|
||||
TIMEOUT_FETCH_WAKE_WORDS = 10
|
||||
|
||||
|
@ -50,16 +52,16 @@ def async_get_wake_word_detection_entity(
|
|||
hass: HomeAssistant, entity_id: str
|
||||
) -> WakeWordDetectionEntity | None:
|
||||
"""Return wake word entity."""
|
||||
component: EntityComponent[WakeWordDetectionEntity] = hass.data[DOMAIN]
|
||||
|
||||
return component.get_entity(entity_id)
|
||||
return hass.data[DOMAIN_DATA].get_entity(entity_id)
|
||||
|
||||
|
||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
"""Set up wake word."""
|
||||
websocket_api.async_register_command(hass, websocket_entity_info)
|
||||
|
||||
component = hass.data[DOMAIN] = EntityComponent(_LOGGER, DOMAIN, hass)
|
||||
component = hass.data[DOMAIN_DATA] = EntityComponent[WakeWordDetectionEntity](
|
||||
_LOGGER, DOMAIN, hass
|
||||
)
|
||||
component.register_shutdown()
|
||||
|
||||
return True
|
||||
|
@ -67,14 +69,12 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Set up a config entry."""
|
||||
component: EntityComponent = hass.data[DOMAIN]
|
||||
return await component.async_setup_entry(entry)
|
||||
return await hass.data[DOMAIN_DATA].async_setup_entry(entry)
|
||||
|
||||
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Unload a config entry."""
|
||||
component: EntityComponent = hass.data[DOMAIN]
|
||||
return await component.async_unload_entry(entry)
|
||||
return await hass.data[DOMAIN_DATA].async_unload_entry(entry)
|
||||
|
||||
|
||||
class WakeWordDetectionEntity(RestoreEntity):
|
||||
|
@ -142,8 +142,7 @@ async def websocket_entity_info(
|
|||
hass: HomeAssistant, connection: websocket_api.ActiveConnection, msg: dict
|
||||
) -> None:
|
||||
"""Get info about wake word entity."""
|
||||
component: EntityComponent[WakeWordDetectionEntity] = hass.data[DOMAIN]
|
||||
entity = component.get_entity(msg["entity_id"])
|
||||
entity = hass.data[DOMAIN_DATA].get_entity(msg["entity_id"])
|
||||
|
||||
if entity is None:
|
||||
connection.send_error(
|
||||
|
|
|
@ -35,10 +35,12 @@ from homeassistant.helpers.entity import Entity, EntityDescription
|
|||
from homeassistant.helpers.entity_component import EntityComponent
|
||||
from homeassistant.helpers.temperature import display_temp as show_temp
|
||||
from homeassistant.helpers.typing import ConfigType, VolDictType
|
||||
from homeassistant.util.hass_dict import HassKey
|
||||
from homeassistant.util.unit_conversion import TemperatureConverter
|
||||
|
||||
from .const import DOMAIN
|
||||
|
||||
DOMAIN_DATA: HassKey[EntityComponent[WaterHeaterEntity]] = HassKey(DOMAIN)
|
||||
ENTITY_ID_FORMAT = DOMAIN + ".{}"
|
||||
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA
|
||||
PLATFORM_SCHEMA_BASE = cv.PLATFORM_SCHEMA_BASE
|
||||
|
@ -109,7 +111,7 @@ SET_OPERATION_MODE_SCHEMA: VolDictType = {
|
|||
|
||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
"""Set up water_heater devices."""
|
||||
component = hass.data[DOMAIN] = EntityComponent[WaterHeaterEntity](
|
||||
component = hass.data[DOMAIN_DATA] = EntityComponent[WaterHeaterEntity](
|
||||
_LOGGER, DOMAIN, hass, SCAN_INTERVAL
|
||||
)
|
||||
await component.async_setup(config)
|
||||
|
@ -137,14 +139,12 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Set up a config entry."""
|
||||
component: EntityComponent[WaterHeaterEntity] = hass.data[DOMAIN]
|
||||
return await component.async_setup_entry(entry)
|
||||
return await hass.data[DOMAIN_DATA].async_setup_entry(entry)
|
||||
|
||||
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Unload a config entry."""
|
||||
component: EntityComponent[WaterHeaterEntity] = hass.data[DOMAIN]
|
||||
return await component.async_unload_entry(entry)
|
||||
return await hass.data[DOMAIN_DATA].async_unload_entry(entry)
|
||||
|
||||
|
||||
class WaterHeaterEntityEntityDescription(EntityDescription, frozen_or_thawed=True):
|
||||
|
|
Loading…
Add table
Reference in a new issue