Add alias to DOMAIN import (part 4)

This commit is contained in:
epenet
2024-09-09 08:00:54 +00:00
parent 4bcde36a97
commit 2785fbefc7
11 changed files with 68 additions and 36 deletions

View File

@@ -5,8 +5,8 @@ from __future__ import annotations
from typing import Any
import uuid
from homeassistant.components.automation import DOMAIN as AUTOMATION_DOMAIN
from homeassistant.components.automation.config import (
DOMAIN,
PLATFORM_SCHEMA,
async_validate_config_item,
)
@@ -27,13 +27,15 @@ def async_setup(hass: HomeAssistant) -> bool:
"""post_write_hook for Config View that reloads automations."""
if action != ACTION_DELETE:
await hass.services.async_call(
DOMAIN, SERVICE_RELOAD, {CONF_ID: config_key}
AUTOMATION_DOMAIN, SERVICE_RELOAD, {CONF_ID: config_key}
)
return
ent_reg = er.async_get(hass)
entity_id = ent_reg.async_get_entity_id(DOMAIN, DOMAIN, config_key)
entity_id = ent_reg.async_get_entity_id(
AUTOMATION_DOMAIN, AUTOMATION_DOMAIN, config_key
)
if entity_id is None:
return
@@ -42,7 +44,7 @@ def async_setup(hass: HomeAssistant) -> bool:
hass.http.register_view(
EditAutomationConfigView(
DOMAIN,
AUTOMATION_DOMAIN,
"config",
AUTOMATION_CONFIG_PATH,
cv.string,

View File

@@ -10,7 +10,7 @@ from pydeconz.models.sensor.ancillary_control import (
)
from homeassistant.components.alarm_control_panel import (
DOMAIN,
DOMAIN as ALARM_CONTROL_PANEL_DOMAIN,
AlarmControlPanelEntity,
AlarmControlPanelEntityFeature,
CodeFormat,
@@ -60,7 +60,7 @@ async def async_setup_entry(
) -> None:
"""Set up the deCONZ alarm control panel devices."""
hub = DeconzHub.get_hub(hass, config_entry)
hub.entities[DOMAIN] = set()
hub.entities[ALARM_CONTROL_PANEL_DOMAIN] = set()
@callback
def async_add_sensor(_: EventType, sensor_id: str) -> None:
@@ -79,7 +79,7 @@ class DeconzAlarmControlPanel(DeconzDevice[AncillaryControl], AlarmControlPanelE
"""Representation of a deCONZ alarm control panel."""
_update_key = "panel"
TYPE = DOMAIN
TYPE = ALARM_CONTROL_PANEL_DOMAIN
_attr_code_format = CodeFormat.NUMBER
_attr_supported_features = (

View File

@@ -18,7 +18,7 @@ from pydeconz.models.sensor.vibration import Vibration
from pydeconz.models.sensor.water import Water
from homeassistant.components.binary_sensor import (
DOMAIN,
DOMAIN as BINARY_SENSOR_DOMAIN,
BinarySensorDeviceClass,
BinarySensorEntity,
BinarySensorEntityDescription,
@@ -165,7 +165,7 @@ async def async_setup_entry(
) -> None:
"""Set up the deCONZ binary sensor."""
hub = DeconzHub.get_hub(hass, config_entry)
hub.entities[DOMAIN] = set()
hub.entities[BINARY_SENSOR_DOMAIN] = set()
@callback
def async_add_sensor(_: EventType, sensor_id: str) -> None:
@@ -189,7 +189,7 @@ async def async_setup_entry(
class DeconzBinarySensor(DeconzDevice[SensorResources], BinarySensorEntity):
"""Representation of a deCONZ binary sensor."""
TYPE = DOMAIN
TYPE = BINARY_SENSOR_DOMAIN
entity_description: DeconzBinarySensorDescription
def __init__(

View File

@@ -12,7 +12,7 @@ from pydeconz.models.light.cover import Cover
from homeassistant.components.cover import (
ATTR_POSITION,
ATTR_TILT_POSITION,
DOMAIN,
DOMAIN as COVER_DOMAIN,
CoverDeviceClass,
CoverEntity,
CoverEntityFeature,
@@ -38,7 +38,7 @@ async def async_setup_entry(
) -> None:
"""Set up covers for deCONZ component."""
hub = DeconzHub.get_hub(hass, config_entry)
hub.entities[DOMAIN] = set()
hub.entities[COVER_DOMAIN] = set()
@callback
def async_add_cover(_: EventType, cover_id: str) -> None:
@@ -54,7 +54,7 @@ async def async_setup_entry(
class DeconzCover(DeconzDevice[Cover], CoverEntity):
"""Representation of a deCONZ cover."""
TYPE = DOMAIN
TYPE = COVER_DOMAIN
def __init__(self, cover_id: str, hub: DeconzHub) -> None:
"""Set up cover device."""

View File

@@ -11,7 +11,7 @@ from homeassistant.components.cover import (
ATTR_CURRENT_TILT_POSITION,
ATTR_POSITION,
ATTR_TILT_POSITION,
DOMAIN,
DOMAIN as COVER_DOMAIN,
PLATFORM_SCHEMA as COVER_PLATFORM_SCHEMA,
CoverEntity,
CoverEntityFeature,
@@ -57,7 +57,7 @@ PARALLEL_UPDATES = 0
PLATFORM_SCHEMA = COVER_PLATFORM_SCHEMA.extend(
{
vol.Required(CONF_ENTITIES): cv.entities_domain(DOMAIN),
vol.Required(CONF_ENTITIES): cv.entities_domain(COVER_DOMAIN),
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
vol.Optional(CONF_UNIQUE_ID): cv.string,
}
@@ -181,21 +181,25 @@ class CoverGroup(GroupEntity, CoverEntity):
"""Move the covers up."""
data = {ATTR_ENTITY_ID: self._covers[KEY_OPEN_CLOSE]}
await self.hass.services.async_call(
DOMAIN, SERVICE_OPEN_COVER, data, blocking=True, context=self._context
COVER_DOMAIN, SERVICE_OPEN_COVER, data, blocking=True, context=self._context
)
async def async_close_cover(self, **kwargs: Any) -> None:
"""Move the covers down."""
data = {ATTR_ENTITY_ID: self._covers[KEY_OPEN_CLOSE]}
await self.hass.services.async_call(
DOMAIN, SERVICE_CLOSE_COVER, data, blocking=True, context=self._context
COVER_DOMAIN,
SERVICE_CLOSE_COVER,
data,
blocking=True,
context=self._context,
)
async def async_stop_cover(self, **kwargs: Any) -> None:
"""Fire the stop action."""
data = {ATTR_ENTITY_ID: self._covers[KEY_STOP]}
await self.hass.services.async_call(
DOMAIN, SERVICE_STOP_COVER, data, blocking=True, context=self._context
COVER_DOMAIN, SERVICE_STOP_COVER, data, blocking=True, context=self._context
)
async def async_set_cover_position(self, **kwargs: Any) -> None:
@@ -205,7 +209,7 @@ class CoverGroup(GroupEntity, CoverEntity):
ATTR_POSITION: kwargs[ATTR_POSITION],
}
await self.hass.services.async_call(
DOMAIN,
COVER_DOMAIN,
SERVICE_SET_COVER_POSITION,
data,
blocking=True,
@@ -216,21 +220,33 @@ class CoverGroup(GroupEntity, CoverEntity):
"""Tilt covers open."""
data = {ATTR_ENTITY_ID: self._tilts[KEY_OPEN_CLOSE]}
await self.hass.services.async_call(
DOMAIN, SERVICE_OPEN_COVER_TILT, data, blocking=True, context=self._context
COVER_DOMAIN,
SERVICE_OPEN_COVER_TILT,
data,
blocking=True,
context=self._context,
)
async def async_close_cover_tilt(self, **kwargs: Any) -> None:
"""Tilt covers closed."""
data = {ATTR_ENTITY_ID: self._tilts[KEY_OPEN_CLOSE]}
await self.hass.services.async_call(
DOMAIN, SERVICE_CLOSE_COVER_TILT, data, blocking=True, context=self._context
COVER_DOMAIN,
SERVICE_CLOSE_COVER_TILT,
data,
blocking=True,
context=self._context,
)
async def async_stop_cover_tilt(self, **kwargs: Any) -> None:
"""Stop cover tilt."""
data = {ATTR_ENTITY_ID: self._tilts[KEY_STOP]}
await self.hass.services.async_call(
DOMAIN, SERVICE_STOP_COVER_TILT, data, blocking=True, context=self._context
COVER_DOMAIN,
SERVICE_STOP_COVER_TILT,
data,
blocking=True,
context=self._context,
)
async def async_set_cover_tilt_position(self, **kwargs: Any) -> None:
@@ -240,7 +256,7 @@ class CoverGroup(GroupEntity, CoverEntity):
ATTR_TILT_POSITION: kwargs[ATTR_TILT_POSITION],
}
await self.hass.services.async_call(
DOMAIN,
COVER_DOMAIN,
SERVICE_SET_COVER_TILT_POSITION,
data,
blocking=True,

View File

@@ -5,7 +5,7 @@ from __future__ import annotations
from iaqualink.device import AqualinkBinarySensor
from homeassistant.components.binary_sensor import (
DOMAIN,
DOMAIN as BINARY_SENSOR_DOMAIN,
BinarySensorDeviceClass,
BinarySensorEntity,
)
@@ -26,7 +26,10 @@ async def async_setup_entry(
) -> None:
"""Set up discovered binary sensors."""
async_add_entities(
(HassAqualinkBinarySensor(dev) for dev in hass.data[AQUALINK_DOMAIN][DOMAIN]),
(
HassAqualinkBinarySensor(dev)
for dev in hass.data[AQUALINK_DOMAIN][BINARY_SENSOR_DOMAIN]
),
True,
)

View File

@@ -5,7 +5,7 @@ from typing import Any
from homeassistant.components.cover import (
ATTR_POSITION,
ATTR_TILT_POSITION,
DOMAIN,
DOMAIN as COVER_DOMAIN,
CoverDeviceClass,
CoverEntity,
CoverEntityFeature,
@@ -122,7 +122,7 @@ async def async_setup_entry(
"""
data = config_entry.runtime_data
bridge = data.bridge
cover_devices = bridge.get_devices_by_domain(DOMAIN)
cover_devices = bridge.get_devices_by_domain(COVER_DOMAIN)
async_add_entities(
# default to standard LutronCasetaCover type if the pylutron type is not yet mapped
PYLUTRON_TYPE_TO_CLASSES.get(cover_device["type"], LutronCasetaShade)(

View File

@@ -5,7 +5,10 @@ from __future__ import annotations
from http import HTTPStatus
import logging
from homeassistant.components.binary_sensor import DOMAIN, BinarySensorEntity
from homeassistant.components.binary_sensor import (
DOMAIN as BINARY_SENSOR_DOMAIN,
BinarySensorEntity,
)
from homeassistant.components.http import KEY_HASS, HomeAssistantView
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity_platform import AddEntitiesCallback
@@ -55,7 +58,7 @@ class MyStromView(HomeAssistantView):
)
button_id = data[button_action]
entity_id = f"{DOMAIN}.{button_id}_{button_action}"
entity_id = f"{BINARY_SENSOR_DOMAIN}.{button_id}_{button_action}"
if entity_id not in self.buttons:
_LOGGER.info(
"New myStrom button/action detected: %s/%s", button_id, button_action

View File

@@ -6,7 +6,7 @@ from collections.abc import Callable
import logging
from homeassistant.components.alarm_control_panel import (
DOMAIN,
DOMAIN as ALARM_CONTROL_PANEL_DOMAIN,
AlarmControlPanelEntity,
AlarmControlPanelEntityFeature,
)
@@ -47,7 +47,9 @@ async def async_setup_entry(
async_add_entities([MinutPointAlarmControl(client, home_id)], True)
async_dispatcher_connect(
hass, POINT_DISCOVERY_NEW.format(DOMAIN, POINT_DOMAIN), async_discover_home
hass,
POINT_DISCOVERY_NEW.format(ALARM_CONTROL_PANEL_DOMAIN, POINT_DOMAIN),
async_discover_home,
)

View File

@@ -7,7 +7,7 @@ import logging
from pypoint import EVENTS
from homeassistant.components.binary_sensor import (
DOMAIN,
DOMAIN as BINARY_SENSOR_DOMAIN,
BinarySensorDeviceClass,
BinarySensorEntity,
)
@@ -60,7 +60,9 @@ async def async_setup_entry(
)
async_dispatcher_connect(
hass, POINT_DISCOVERY_NEW.format(DOMAIN, POINT_DOMAIN), async_discover_sensor
hass,
POINT_DISCOVERY_NEW.format(BINARY_SENSOR_DOMAIN, POINT_DOMAIN),
async_discover_sensor,
)

View File

@@ -9,7 +9,7 @@ from screenlogicpy.const.msg import CODE
from screenlogicpy.device_const.system import EQUIPMENT_FLAG
from homeassistant.components.binary_sensor import (
DOMAIN,
DOMAIN as BINARY_SENSOR_DOMAIN,
BinarySensorDeviceClass,
BinarySensorEntity,
BinarySensorEntityDescription,
@@ -202,7 +202,9 @@ async def async_setup_entry(
chem_sensor_description.key,
)
if EQUIPMENT_FLAG.INTELLICHEM not in gateway.equipment_flags:
cleanup_excluded_entity(coordinator, DOMAIN, chem_sensor_data_path)
cleanup_excluded_entity(
coordinator, BINARY_SENSOR_DOMAIN, chem_sensor_data_path
)
continue
if gateway.get_data(*chem_sensor_data_path):
entities.append(
@@ -216,7 +218,9 @@ async def async_setup_entry(
scg_sensor_description.key,
)
if EQUIPMENT_FLAG.CHLORINATOR not in gateway.equipment_flags:
cleanup_excluded_entity(coordinator, DOMAIN, scg_sensor_data_path)
cleanup_excluded_entity(
coordinator, BINARY_SENSOR_DOMAIN, scg_sensor_data_path
)
continue
if gateway.get_data(*scg_sensor_data_path):
entities.append(