diff --git a/homeassistant/components/zha/alarm_control_panel.py b/homeassistant/components/zha/alarm_control_panel.py index 1ba5f1b73f8..c76e26baaf6 100644 --- a/homeassistant/components/zha/alarm_control_panel.py +++ b/homeassistant/components/zha/alarm_control_panel.py @@ -4,7 +4,6 @@ import functools from zigpy.zcl.clusters.security import IasAce from homeassistant.components.alarm_control_panel import ( - DOMAIN, FORMAT_TEXT, SUPPORT_ALARM_ARM_AWAY, SUPPORT_ALARM_ARM_HOME, @@ -19,6 +18,7 @@ from homeassistant.const import ( STATE_ALARM_ARMED_NIGHT, STATE_ALARM_DISARMED, STATE_ALARM_TRIGGERED, + Platform, ) from homeassistant.core import callback from homeassistant.helpers.dispatcher import async_dispatcher_connect @@ -43,7 +43,9 @@ from .core.helpers import async_get_zha_config_value from .core.registries import ZHA_ENTITIES from .entity import ZhaEntity -STRICT_MATCH = functools.partial(ZHA_ENTITIES.strict_match, DOMAIN) +STRICT_MATCH = functools.partial( + ZHA_ENTITIES.strict_match, Platform.ALARM_CONTROL_PANEL +) IAS_ACE_STATE_MAP = { IasAce.PanelStatus.Panel_Disarmed: STATE_ALARM_DISARMED, @@ -56,7 +58,7 @@ IAS_ACE_STATE_MAP = { async def async_setup_entry(hass, config_entry, async_add_entities): """Set up the Zigbee Home Automation alarm control panel from config entry.""" - entities_to_create = hass.data[DATA_ZHA][DOMAIN] + entities_to_create = hass.data[DATA_ZHA][Platform.ALARM_CONTROL_PANEL] unsub = async_dispatcher_connect( hass, diff --git a/homeassistant/components/zha/binary_sensor.py b/homeassistant/components/zha/binary_sensor.py index e6f03a8a848..7e083a07d72 100644 --- a/homeassistant/components/zha/binary_sensor.py +++ b/homeassistant/components/zha/binary_sensor.py @@ -10,10 +10,9 @@ from homeassistant.components.binary_sensor import ( DEVICE_CLASS_OPENING, DEVICE_CLASS_SMOKE, DEVICE_CLASS_VIBRATION, - DOMAIN, BinarySensorEntity, ) -from homeassistant.const import STATE_ON +from homeassistant.const import STATE_ON, Platform from homeassistant.core import callback from homeassistant.helpers.dispatcher import async_dispatcher_connect @@ -42,12 +41,12 @@ CLASS_MAPPING = { 0x002D: DEVICE_CLASS_VIBRATION, } -STRICT_MATCH = functools.partial(ZHA_ENTITIES.strict_match, DOMAIN) +STRICT_MATCH = functools.partial(ZHA_ENTITIES.strict_match, Platform.BINARY_SENSOR) async def async_setup_entry(hass, config_entry, async_add_entities): """Set up the Zigbee Home Automation binary sensor from config entry.""" - entities_to_create = hass.data[DATA_ZHA][DOMAIN] + entities_to_create = hass.data[DATA_ZHA][Platform.BINARY_SENSOR] unsub = async_dispatcher_connect( hass, diff --git a/homeassistant/components/zha/climate.py b/homeassistant/components/zha/climate.py index f7a1d1815db..7cb2c0f16e4 100644 --- a/homeassistant/components/zha/climate.py +++ b/homeassistant/components/zha/climate.py @@ -21,7 +21,6 @@ from homeassistant.components.climate.const import ( CURRENT_HVAC_HEAT, CURRENT_HVAC_IDLE, CURRENT_HVAC_OFF, - DOMAIN, FAN_AUTO, FAN_ON, HVAC_MODE_COOL, @@ -40,7 +39,12 @@ from homeassistant.components.climate.const import ( SUPPORT_TARGET_TEMPERATURE, SUPPORT_TARGET_TEMPERATURE_RANGE, ) -from homeassistant.const import ATTR_TEMPERATURE, PRECISION_TENTHS, TEMP_CELSIUS +from homeassistant.const import ( + ATTR_TEMPERATURE, + PRECISION_TENTHS, + TEMP_CELSIUS, + Platform, +) from homeassistant.core import callback from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.event import async_track_time_interval @@ -73,8 +77,8 @@ ATTR_UNOCCP_HEAT_SETPT = "unoccupied_heating_setpoint" ATTR_UNOCCP_COOL_SETPT = "unoccupied_cooling_setpoint" -STRICT_MATCH = functools.partial(ZHA_ENTITIES.strict_match, DOMAIN) -MULTI_MATCH = functools.partial(ZHA_ENTITIES.multipass_match, DOMAIN) +STRICT_MATCH = functools.partial(ZHA_ENTITIES.strict_match, Platform.CLIMATE) +MULTI_MATCH = functools.partial(ZHA_ENTITIES.multipass_match, Platform.CLIMATE) RUNNING_MODE = {0x00: HVAC_MODE_OFF, 0x03: HVAC_MODE_COOL, 0x04: HVAC_MODE_HEAT} @@ -152,7 +156,7 @@ ZCL_TEMP = 100 async def async_setup_entry(hass, config_entry, async_add_entities): """Set up the Zigbee Home Automation sensor from config entry.""" - entities_to_create = hass.data[DATA_ZHA][DOMAIN] + entities_to_create = hass.data[DATA_ZHA][Platform.CLIMATE] unsub = async_dispatcher_connect( hass, SIGNAL_ADD_ENTITIES, diff --git a/homeassistant/components/zha/core/const.py b/homeassistant/components/zha/core/const.py index 813f268bbe5..876d4c4e9f5 100644 --- a/homeassistant/components/zha/core/const.py +++ b/homeassistant/components/zha/core/const.py @@ -12,18 +12,7 @@ import zigpy_xbee.zigbee.application import zigpy_zigate.zigbee.application import zigpy_znp.zigbee.application -from homeassistant.components.alarm_control_panel import DOMAIN as ALARM -from homeassistant.components.binary_sensor import DOMAIN as BINARY_SENSOR -from homeassistant.components.climate import DOMAIN as CLIMATE -from homeassistant.components.cover import DOMAIN as COVER -from homeassistant.components.device_tracker import DOMAIN as DEVICE_TRACKER -from homeassistant.components.fan import DOMAIN as FAN -from homeassistant.components.light import DOMAIN as LIGHT -from homeassistant.components.lock import DOMAIN as LOCK -from homeassistant.components.number import DOMAIN as NUMBER -from homeassistant.components.sensor import DOMAIN as SENSOR -from homeassistant.components.siren import DOMAIN as SIREN -from homeassistant.components.switch import DOMAIN as SWITCH +from homeassistant.const import Platform import homeassistant.helpers.config_validation as cv from .typing import CALLABLE_T @@ -111,18 +100,18 @@ CLUSTER_TYPE_IN = "in" CLUSTER_TYPE_OUT = "out" PLATFORMS = ( - ALARM, - BINARY_SENSOR, - CLIMATE, - COVER, - DEVICE_TRACKER, - FAN, - LIGHT, - LOCK, - NUMBER, - SENSOR, - SIREN, - SWITCH, + Platform.ALARM_CONTROL_PANEL, + Platform.BINARY_SENSOR, + Platform.CLIMATE, + Platform.COVER, + Platform.DEVICE_TRACKER, + Platform.FAN, + Platform.LIGHT, + Platform.LOCK, + Platform.NUMBER, + Platform.SENSOR, + Platform.SIREN, + Platform.SWITCH, ) CONF_ALARM_MASTER_CODE = "alarm_master_code" diff --git a/homeassistant/components/zha/core/registries.py b/homeassistant/components/zha/core/registries.py index f624ef9289d..36a77b841b6 100644 --- a/homeassistant/components/zha/core/registries.py +++ b/homeassistant/components/zha/core/registries.py @@ -11,25 +11,14 @@ from zigpy import zcl import zigpy.profiles.zha import zigpy.profiles.zll -from homeassistant.components.alarm_control_panel import DOMAIN as ALARM -from homeassistant.components.binary_sensor import DOMAIN as BINARY_SENSOR -from homeassistant.components.climate import DOMAIN as CLIMATE -from homeassistant.components.cover import DOMAIN as COVER -from homeassistant.components.device_tracker import DOMAIN as DEVICE_TRACKER -from homeassistant.components.fan import DOMAIN as FAN -from homeassistant.components.light import DOMAIN as LIGHT -from homeassistant.components.lock import DOMAIN as LOCK -from homeassistant.components.number import DOMAIN as NUMBER -from homeassistant.components.sensor import DOMAIN as SENSOR -from homeassistant.components.siren import DOMAIN as SIREN -from homeassistant.components.switch import DOMAIN as SWITCH +from homeassistant.const import Platform # importing channels updates registries from . import channels as zha_channels # noqa: F401 pylint: disable=unused-import from .decorators import CALLABLE_T, DictRegistry, SetRegistry from .typing import ChannelType -GROUP_ENTITY_DOMAINS = [LIGHT, SWITCH, FAN] +GROUP_ENTITY_DOMAINS = [Platform.LIGHT, Platform.SWITCH, Platform.FAN] PHILLIPS_REMOTE_CLUSTER = 0xFC00 SMARTTHINGS_ACCELERATION_CLUSTER = 0xFC02 @@ -64,34 +53,34 @@ REMOTE_DEVICE_TYPES = collections.defaultdict(list, REMOTE_DEVICE_TYPES) SINGLE_INPUT_CLUSTER_DEVICE_CLASS = { # this works for now but if we hit conflicts we can break it out to # a different dict that is keyed by manufacturer - SMARTTHINGS_ACCELERATION_CLUSTER: BINARY_SENSOR, - SMARTTHINGS_HUMIDITY_CLUSTER: SENSOR, - VOC_LEVEL_CLUSTER: SENSOR, - zcl.clusters.closures.DoorLock.cluster_id: LOCK, - zcl.clusters.closures.WindowCovering.cluster_id: COVER, - zcl.clusters.general.BinaryInput.cluster_id: BINARY_SENSOR, - zcl.clusters.general.AnalogInput.cluster_id: SENSOR, - zcl.clusters.general.AnalogOutput.cluster_id: NUMBER, - zcl.clusters.general.MultistateInput.cluster_id: SENSOR, - zcl.clusters.general.OnOff.cluster_id: SWITCH, - zcl.clusters.general.PowerConfiguration.cluster_id: SENSOR, - zcl.clusters.hvac.Fan.cluster_id: FAN, - zcl.clusters.measurement.CarbonDioxideConcentration.cluster_id: SENSOR, - zcl.clusters.measurement.CarbonMonoxideConcentration.cluster_id: SENSOR, - zcl.clusters.measurement.FormaldehydeConcentration.cluster_id: SENSOR, - zcl.clusters.measurement.IlluminanceMeasurement.cluster_id: SENSOR, - zcl.clusters.measurement.OccupancySensing.cluster_id: BINARY_SENSOR, - zcl.clusters.measurement.PressureMeasurement.cluster_id: SENSOR, - zcl.clusters.measurement.RelativeHumidity.cluster_id: SENSOR, - zcl.clusters.measurement.SoilMoisture.cluster_id: SENSOR, - zcl.clusters.measurement.LeafWetness.cluster_id: SENSOR, - zcl.clusters.measurement.TemperatureMeasurement.cluster_id: SENSOR, - zcl.clusters.security.IasZone.cluster_id: BINARY_SENSOR, + SMARTTHINGS_ACCELERATION_CLUSTER: Platform.BINARY_SENSOR, + SMARTTHINGS_HUMIDITY_CLUSTER: Platform.SENSOR, + VOC_LEVEL_CLUSTER: Platform.SENSOR, + zcl.clusters.closures.DoorLock.cluster_id: Platform.LOCK, + zcl.clusters.closures.WindowCovering.cluster_id: Platform.COVER, + zcl.clusters.general.BinaryInput.cluster_id: Platform.BINARY_SENSOR, + zcl.clusters.general.AnalogInput.cluster_id: Platform.SENSOR, + zcl.clusters.general.AnalogOutput.cluster_id: Platform.NUMBER, + zcl.clusters.general.MultistateInput.cluster_id: Platform.SENSOR, + zcl.clusters.general.OnOff.cluster_id: Platform.SWITCH, + zcl.clusters.general.PowerConfiguration.cluster_id: Platform.SENSOR, + zcl.clusters.hvac.Fan.cluster_id: Platform.FAN, + zcl.clusters.measurement.CarbonDioxideConcentration.cluster_id: Platform.SENSOR, + zcl.clusters.measurement.CarbonMonoxideConcentration.cluster_id: Platform.SENSOR, + zcl.clusters.measurement.FormaldehydeConcentration.cluster_id: Platform.SENSOR, + zcl.clusters.measurement.IlluminanceMeasurement.cluster_id: Platform.SENSOR, + zcl.clusters.measurement.OccupancySensing.cluster_id: Platform.BINARY_SENSOR, + zcl.clusters.measurement.PressureMeasurement.cluster_id: Platform.SENSOR, + zcl.clusters.measurement.RelativeHumidity.cluster_id: Platform.SENSOR, + zcl.clusters.measurement.SoilMoisture.cluster_id: Platform.SENSOR, + zcl.clusters.measurement.LeafWetness.cluster_id: Platform.SENSOR, + zcl.clusters.measurement.TemperatureMeasurement.cluster_id: Platform.SENSOR, + zcl.clusters.security.IasZone.cluster_id: Platform.BINARY_SENSOR, } SINGLE_OUTPUT_CLUSTER_DEVICE_CLASS = { - zcl.clusters.general.OnOff.cluster_id: BINARY_SENSOR, - zcl.clusters.security.IasAce.cluster_id: ALARM, + zcl.clusters.general.OnOff.cluster_id: Platform.BINARY_SENSOR, + zcl.clusters.security.IasAce.cluster_id: Platform.ALARM_CONTROL_PANEL, } BINDABLE_CLUSTERS = SetRegistry() @@ -99,31 +88,31 @@ CHANNEL_ONLY_CLUSTERS = SetRegistry() DEVICE_CLASS = { zigpy.profiles.zha.PROFILE_ID: { - SMARTTHINGS_ARRIVAL_SENSOR_DEVICE_TYPE: DEVICE_TRACKER, - zigpy.profiles.zha.DeviceType.THERMOSTAT: CLIMATE, - zigpy.profiles.zha.DeviceType.COLOR_DIMMABLE_LIGHT: LIGHT, - zigpy.profiles.zha.DeviceType.COLOR_TEMPERATURE_LIGHT: LIGHT, - zigpy.profiles.zha.DeviceType.DIMMABLE_BALLAST: LIGHT, - zigpy.profiles.zha.DeviceType.DIMMABLE_LIGHT: LIGHT, - zigpy.profiles.zha.DeviceType.DIMMABLE_PLUG_IN_UNIT: LIGHT, - zigpy.profiles.zha.DeviceType.EXTENDED_COLOR_LIGHT: LIGHT, - zigpy.profiles.zha.DeviceType.LEVEL_CONTROLLABLE_OUTPUT: COVER, - zigpy.profiles.zha.DeviceType.ON_OFF_BALLAST: SWITCH, - zigpy.profiles.zha.DeviceType.ON_OFF_LIGHT: LIGHT, - zigpy.profiles.zha.DeviceType.ON_OFF_PLUG_IN_UNIT: SWITCH, - zigpy.profiles.zha.DeviceType.SHADE: COVER, - zigpy.profiles.zha.DeviceType.SMART_PLUG: SWITCH, - zigpy.profiles.zha.DeviceType.IAS_ANCILLARY_CONTROL: ALARM, - zigpy.profiles.zha.DeviceType.IAS_WARNING_DEVICE: SIREN, + SMARTTHINGS_ARRIVAL_SENSOR_DEVICE_TYPE: Platform.DEVICE_TRACKER, + zigpy.profiles.zha.DeviceType.THERMOSTAT: Platform.CLIMATE, + zigpy.profiles.zha.DeviceType.COLOR_DIMMABLE_LIGHT: Platform.LIGHT, + zigpy.profiles.zha.DeviceType.COLOR_TEMPERATURE_LIGHT: Platform.LIGHT, + zigpy.profiles.zha.DeviceType.DIMMABLE_BALLAST: Platform.LIGHT, + zigpy.profiles.zha.DeviceType.DIMMABLE_LIGHT: Platform.LIGHT, + zigpy.profiles.zha.DeviceType.DIMMABLE_PLUG_IN_UNIT: Platform.LIGHT, + zigpy.profiles.zha.DeviceType.EXTENDED_COLOR_LIGHT: Platform.LIGHT, + zigpy.profiles.zha.DeviceType.LEVEL_CONTROLLABLE_OUTPUT: Platform.COVER, + zigpy.profiles.zha.DeviceType.ON_OFF_BALLAST: Platform.SWITCH, + zigpy.profiles.zha.DeviceType.ON_OFF_LIGHT: Platform.LIGHT, + zigpy.profiles.zha.DeviceType.ON_OFF_PLUG_IN_UNIT: Platform.SWITCH, + zigpy.profiles.zha.DeviceType.SHADE: Platform.COVER, + zigpy.profiles.zha.DeviceType.SMART_PLUG: Platform.SWITCH, + zigpy.profiles.zha.DeviceType.IAS_ANCILLARY_CONTROL: Platform.ALARM_CONTROL_PANEL, + zigpy.profiles.zha.DeviceType.IAS_WARNING_DEVICE: Platform.SIREN, }, zigpy.profiles.zll.PROFILE_ID: { - zigpy.profiles.zll.DeviceType.COLOR_LIGHT: LIGHT, - zigpy.profiles.zll.DeviceType.COLOR_TEMPERATURE_LIGHT: LIGHT, - zigpy.profiles.zll.DeviceType.DIMMABLE_LIGHT: LIGHT, - zigpy.profiles.zll.DeviceType.DIMMABLE_PLUGIN_UNIT: LIGHT, - zigpy.profiles.zll.DeviceType.EXTENDED_COLOR_LIGHT: LIGHT, - zigpy.profiles.zll.DeviceType.ON_OFF_LIGHT: LIGHT, - zigpy.profiles.zll.DeviceType.ON_OFF_PLUGIN_UNIT: SWITCH, + zigpy.profiles.zll.DeviceType.COLOR_LIGHT: Platform.LIGHT, + zigpy.profiles.zll.DeviceType.COLOR_TEMPERATURE_LIGHT: Platform.LIGHT, + zigpy.profiles.zll.DeviceType.DIMMABLE_LIGHT: Platform.LIGHT, + zigpy.profiles.zll.DeviceType.DIMMABLE_PLUGIN_UNIT: Platform.LIGHT, + zigpy.profiles.zll.DeviceType.EXTENDED_COLOR_LIGHT: Platform.LIGHT, + zigpy.profiles.zll.DeviceType.ON_OFF_LIGHT: Platform.LIGHT, + zigpy.profiles.zll.DeviceType.ON_OFF_PLUGIN_UNIT: Platform.SWITCH, }, } DEVICE_CLASS = collections.defaultdict(dict, DEVICE_CLASS) diff --git a/homeassistant/components/zha/cover.py b/homeassistant/components/zha/cover.py index 71c5dcca908..2febc209755 100644 --- a/homeassistant/components/zha/cover.py +++ b/homeassistant/components/zha/cover.py @@ -12,10 +12,15 @@ from homeassistant.components.cover import ( ATTR_POSITION, DEVICE_CLASS_DAMPER, DEVICE_CLASS_SHADE, - DOMAIN, CoverEntity, ) -from homeassistant.const import STATE_CLOSED, STATE_CLOSING, STATE_OPEN, STATE_OPENING +from homeassistant.const import ( + STATE_CLOSED, + STATE_CLOSING, + STATE_OPEN, + STATE_OPENING, + Platform, +) from homeassistant.core import callback from homeassistant.helpers.dispatcher import async_dispatcher_connect @@ -37,12 +42,12 @@ from .entity import ZhaEntity _LOGGER = logging.getLogger(__name__) -STRICT_MATCH = functools.partial(ZHA_ENTITIES.strict_match, DOMAIN) +STRICT_MATCH = functools.partial(ZHA_ENTITIES.strict_match, Platform.COVER) async def async_setup_entry(hass, config_entry, async_add_entities): """Set up the Zigbee Home Automation cover from config entry.""" - entities_to_create = hass.data[DATA_ZHA][DOMAIN] + entities_to_create = hass.data[DATA_ZHA][Platform.COVER] unsub = async_dispatcher_connect( hass, diff --git a/homeassistant/components/zha/device_tracker.py b/homeassistant/components/zha/device_tracker.py index ffb37e33b0f..c203462d44d 100644 --- a/homeassistant/components/zha/device_tracker.py +++ b/homeassistant/components/zha/device_tracker.py @@ -2,8 +2,9 @@ import functools import time -from homeassistant.components.device_tracker import DOMAIN, SOURCE_TYPE_ROUTER +from homeassistant.components.device_tracker import SOURCE_TYPE_ROUTER from homeassistant.components.device_tracker.config_entry import ScannerEntity +from homeassistant.const import Platform from homeassistant.core import callback from homeassistant.helpers.dispatcher import async_dispatcher_connect @@ -19,12 +20,12 @@ from .core.registries import ZHA_ENTITIES from .entity import ZhaEntity from .sensor import Battery -STRICT_MATCH = functools.partial(ZHA_ENTITIES.strict_match, DOMAIN) +STRICT_MATCH = functools.partial(ZHA_ENTITIES.strict_match, Platform.DEVICE_TRACKER) async def async_setup_entry(hass, config_entry, async_add_entities): """Set up the Zigbee Home Automation device tracker from config entry.""" - entities_to_create = hass.data[DATA_ZHA][DOMAIN] + entities_to_create = hass.data[DATA_ZHA][Platform.DEVICE_TRACKER] unsub = async_dispatcher_connect( hass, diff --git a/homeassistant/components/zha/fan.py b/homeassistant/components/zha/fan.py index 0176cf1ea3b..0402e93ff8c 100644 --- a/homeassistant/components/zha/fan.py +++ b/homeassistant/components/zha/fan.py @@ -11,12 +11,11 @@ from zigpy.zcl.clusters import hvac from homeassistant.components.fan import ( ATTR_PERCENTAGE, ATTR_PRESET_MODE, - DOMAIN, SUPPORT_SET_SPEED, FanEntity, NotValidPresetModeError, ) -from homeassistant.const import STATE_UNAVAILABLE +from homeassistant.const import STATE_UNAVAILABLE, Platform from homeassistant.core import State, callback from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.util.percentage import ( @@ -53,13 +52,13 @@ PRESET_MODES = list(NAME_TO_PRESET_MODE) DEFAULT_ON_PERCENTAGE = 50 -STRICT_MATCH = functools.partial(ZHA_ENTITIES.strict_match, DOMAIN) -GROUP_MATCH = functools.partial(ZHA_ENTITIES.group_match, DOMAIN) +STRICT_MATCH = functools.partial(ZHA_ENTITIES.strict_match, Platform.FAN) +GROUP_MATCH = functools.partial(ZHA_ENTITIES.group_match, Platform.FAN) async def async_setup_entry(hass, config_entry, async_add_entities): """Set up the Zigbee Home Automation fan from config entry.""" - entities_to_create = hass.data[DATA_ZHA][DOMAIN] + entities_to_create = hass.data[DATA_ZHA][Platform.FAN] unsub = async_dispatcher_connect( hass, diff --git a/homeassistant/components/zha/light.py b/homeassistant/components/zha/light.py index 9398d0fde17..476bb733cc9 100644 --- a/homeassistant/components/zha/light.py +++ b/homeassistant/components/zha/light.py @@ -30,7 +30,12 @@ from homeassistant.components.light import ( SUPPORT_FLASH, SUPPORT_TRANSITION, ) -from homeassistant.const import ATTR_SUPPORTED_FEATURES, STATE_ON, STATE_UNAVAILABLE +from homeassistant.const import ( + ATTR_SUPPORTED_FEATURES, + STATE_ON, + STATE_UNAVAILABLE, + Platform, +) from homeassistant.core import State, callback from homeassistant.helpers.debounce import Debouncer from homeassistant.helpers.dispatcher import ( @@ -77,8 +82,8 @@ UPDATE_COLORLOOP_HUE = 0x8 FLASH_EFFECTS = {light.FLASH_SHORT: EFFECT_BLINK, light.FLASH_LONG: EFFECT_BREATHE} UNSUPPORTED_ATTRIBUTE = 0x86 -STRICT_MATCH = functools.partial(ZHA_ENTITIES.strict_match, light.DOMAIN) -GROUP_MATCH = functools.partial(ZHA_ENTITIES.group_match, light.DOMAIN) +STRICT_MATCH = functools.partial(ZHA_ENTITIES.strict_match, Platform.LIGHT) +GROUP_MATCH = functools.partial(ZHA_ENTITIES.group_match, Platform.LIGHT) PARALLEL_UPDATES = 0 SIGNAL_LIGHT_GROUP_STATE_CHANGED = "zha_light_group_state_changed" @@ -102,7 +107,7 @@ class LightColorMode(enum.IntEnum): async def async_setup_entry(hass, config_entry, async_add_entities): """Set up the Zigbee Home Automation light from config entry.""" - entities_to_create = hass.data[DATA_ZHA][light.DOMAIN] + entities_to_create = hass.data[DATA_ZHA][Platform.LIGHT] unsub = async_dispatcher_connect( hass, diff --git a/homeassistant/components/zha/lock.py b/homeassistant/components/zha/lock.py index 99f6230de0b..0c8ca756785 100644 --- a/homeassistant/components/zha/lock.py +++ b/homeassistant/components/zha/lock.py @@ -4,12 +4,8 @@ import functools import voluptuous as vol from zigpy.zcl.foundation import Status -from homeassistant.components.lock import ( - DOMAIN, - STATE_LOCKED, - STATE_UNLOCKED, - LockEntity, -) +from homeassistant.components.lock import STATE_LOCKED, STATE_UNLOCKED, LockEntity +from homeassistant.const import Platform from homeassistant.core import callback from homeassistant.helpers import config_validation as cv, entity_platform from homeassistant.helpers.dispatcher import async_dispatcher_connect @@ -27,7 +23,7 @@ from .entity import ZhaEntity # The first state is Zigbee 'Not fully locked' STATE_LIST = [STATE_UNLOCKED, STATE_LOCKED, STATE_UNLOCKED] -STRICT_MATCH = functools.partial(ZHA_ENTITIES.strict_match, DOMAIN) +STRICT_MATCH = functools.partial(ZHA_ENTITIES.strict_match, Platform.LOCK) VALUE_TO_STATE = dict(enumerate(STATE_LIST)) @@ -39,7 +35,7 @@ SERVICE_CLEAR_LOCK_USER_CODE = "clear_lock_user_code" async def async_setup_entry(hass, config_entry, async_add_entities): """Set up the Zigbee Home Automation Door Lock from config entry.""" - entities_to_create = hass.data[DATA_ZHA][DOMAIN] + entities_to_create = hass.data[DATA_ZHA][Platform.LOCK] unsub = async_dispatcher_connect( hass, diff --git a/homeassistant/components/zha/number.py b/homeassistant/components/zha/number.py index b4772e51742..0acda49c375 100644 --- a/homeassistant/components/zha/number.py +++ b/homeassistant/components/zha/number.py @@ -2,7 +2,8 @@ import functools import logging -from homeassistant.components.number import DOMAIN, NumberEntity +from homeassistant.components.number import NumberEntity +from homeassistant.const import Platform from homeassistant.core import callback from homeassistant.helpers.dispatcher import async_dispatcher_connect @@ -19,7 +20,7 @@ from .entity import ZhaEntity _LOGGER = logging.getLogger(__name__) -STRICT_MATCH = functools.partial(ZHA_ENTITIES.strict_match, DOMAIN) +STRICT_MATCH = functools.partial(ZHA_ENTITIES.strict_match, Platform.NUMBER) UNITS = { @@ -235,7 +236,7 @@ ICONS = { async def async_setup_entry(hass, config_entry, async_add_entities): """Set up the Zigbee Home Automation Analog Output from config entry.""" - entities_to_create = hass.data[DATA_ZHA][DOMAIN] + entities_to_create = hass.data[DATA_ZHA][Platform.NUMBER] unsub = async_dispatcher_connect( hass, diff --git a/homeassistant/components/zha/sensor.py b/homeassistant/components/zha/sensor.py index 567d2a6065e..d4c508a8378 100644 --- a/homeassistant/components/zha/sensor.py +++ b/homeassistant/components/zha/sensor.py @@ -22,7 +22,6 @@ from homeassistant.components.sensor import ( DEVICE_CLASS_POWER, DEVICE_CLASS_PRESSURE, DEVICE_CLASS_TEMPERATURE, - DOMAIN, STATE_CLASS_MEASUREMENT, STATE_CLASS_TOTAL_INCREASING, SensorEntity, @@ -51,6 +50,7 @@ from homeassistant.const import ( VOLUME_FLOW_RATE_CUBIC_METERS_PER_HOUR, VOLUME_GALLONS, VOLUME_LITERS, + Platform, ) from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.dispatcher import async_dispatcher_connect @@ -99,8 +99,8 @@ BATTERY_SIZES = { } CHANNEL_ST_HUMIDITY_CLUSTER = f"channel_0x{SMARTTHINGS_HUMIDITY_CLUSTER:04x}" -STRICT_MATCH = functools.partial(ZHA_ENTITIES.strict_match, DOMAIN) -MULTI_MATCH = functools.partial(ZHA_ENTITIES.multipass_match, DOMAIN) +STRICT_MATCH = functools.partial(ZHA_ENTITIES.strict_match, Platform.SENSOR) +MULTI_MATCH = functools.partial(ZHA_ENTITIES.multipass_match, Platform.SENSOR) async def async_setup_entry( @@ -109,7 +109,7 @@ async def async_setup_entry( async_add_entities: AddEntitiesCallback, ) -> None: """Set up the Zigbee Home Automation sensor from config entry.""" - entities_to_create = hass.data[DATA_ZHA][DOMAIN] + entities_to_create = hass.data[DATA_ZHA][Platform.SENSOR] unsub = async_dispatcher_connect( hass, diff --git a/homeassistant/components/zha/siren.py b/homeassistant/components/zha/siren.py index 75f527cfcf1..ce558e8f1a5 100644 --- a/homeassistant/components/zha/siren.py +++ b/homeassistant/components/zha/siren.py @@ -7,7 +7,6 @@ from typing import Any from homeassistant.components.siren import ( ATTR_DURATION, - DOMAIN, SUPPORT_DURATION, SUPPORT_TURN_OFF, SUPPORT_TURN_ON, @@ -20,6 +19,7 @@ from homeassistant.components.siren.const import ( SUPPORT_VOLUME_SET, ) from homeassistant.config_entries import ConfigEntry +from homeassistant.const import Platform from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -45,7 +45,7 @@ from .core.registries import ZHA_ENTITIES from .core.typing import ChannelType, ZhaDeviceType from .entity import ZhaEntity -STRICT_MATCH = functools.partial(ZHA_ENTITIES.strict_match, DOMAIN) +STRICT_MATCH = functools.partial(ZHA_ENTITIES.strict_match, Platform.SIREN) DEFAULT_DURATION = 5 # seconds @@ -55,7 +55,7 @@ async def async_setup_entry( async_add_entities: AddEntitiesCallback, ) -> None: """Set up the Zigbee Home Automation siren from config entry.""" - entities_to_create = hass.data[DATA_ZHA][DOMAIN] + entities_to_create = hass.data[DATA_ZHA][Platform.SIREN] unsub = async_dispatcher_connect( hass, diff --git a/homeassistant/components/zha/switch.py b/homeassistant/components/zha/switch.py index 75254f631b9..da5e843c59f 100644 --- a/homeassistant/components/zha/switch.py +++ b/homeassistant/components/zha/switch.py @@ -7,8 +7,8 @@ from typing import Any from zigpy.zcl.clusters.general import OnOff from zigpy.zcl.foundation import Status -from homeassistant.components.switch import DOMAIN, SwitchEntity -from homeassistant.const import STATE_ON, STATE_UNAVAILABLE +from homeassistant.components.switch import SwitchEntity +from homeassistant.const import STATE_ON, STATE_UNAVAILABLE, Platform from homeassistant.core import State, callback from homeassistant.helpers.dispatcher import async_dispatcher_connect @@ -23,13 +23,13 @@ from .core.const import ( from .core.registries import ZHA_ENTITIES from .entity import ZhaEntity, ZhaGroupEntity -STRICT_MATCH = functools.partial(ZHA_ENTITIES.strict_match, DOMAIN) -GROUP_MATCH = functools.partial(ZHA_ENTITIES.group_match, DOMAIN) +STRICT_MATCH = functools.partial(ZHA_ENTITIES.strict_match, Platform.SWITCH) +GROUP_MATCH = functools.partial(ZHA_ENTITIES.group_match, Platform.SWITCH) async def async_setup_entry(hass, config_entry, async_add_entities): """Set up the Zigbee Home Automation switch from config entry.""" - entities_to_create = hass.data[DATA_ZHA][DOMAIN] + entities_to_create = hass.data[DATA_ZHA][Platform.SWITCH] unsub = async_dispatcher_connect( hass, diff --git a/tests/components/zha/test_alarm_control_panel.py b/tests/components/zha/test_alarm_control_panel.py index 39063225e50..84e66f0833a 100644 --- a/tests/components/zha/test_alarm_control_panel.py +++ b/tests/components/zha/test_alarm_control_panel.py @@ -6,7 +6,6 @@ import zigpy.profiles.zha as zha import zigpy.zcl.clusters.security as security import zigpy.zcl.foundation as zcl_f -from homeassistant.components.alarm_control_panel import DOMAIN as ALARM_DOMAIN from homeassistant.const import ( ATTR_ENTITY_ID, STATE_ALARM_ARMED_AWAY, @@ -15,6 +14,7 @@ from homeassistant.const import ( STATE_ALARM_DISARMED, STATE_ALARM_TRIGGERED, STATE_UNAVAILABLE, + Platform, ) from .common import async_enable_traffic, find_entity_id @@ -46,7 +46,7 @@ async def test_alarm_control_panel(hass, zha_device_joined_restored, zigpy_devic zha_device = await zha_device_joined_restored(zigpy_device) cluster = zigpy_device.endpoints.get(1).ias_ace - entity_id = await find_entity_id(ALARM_DOMAIN, zha_device, hass) + entity_id = await find_entity_id(Platform.ALARM_CONTROL_PANEL, zha_device, hass) assert entity_id is not None assert hass.states.get(entity_id).state == STATE_ALARM_DISARMED await async_enable_traffic(hass, [zha_device], enabled=False) @@ -62,7 +62,10 @@ async def test_alarm_control_panel(hass, zha_device_joined_restored, zigpy_devic # arm_away from HA cluster.client_command.reset_mock() await hass.services.async_call( - ALARM_DOMAIN, "alarm_arm_away", {ATTR_ENTITY_ID: entity_id}, blocking=True + Platform.ALARM_CONTROL_PANEL, + "alarm_arm_away", + {ATTR_ENTITY_ID: entity_id}, + blocking=True, ) await hass.async_block_till_done() assert hass.states.get(entity_id).state == STATE_ALARM_ARMED_AWAY @@ -82,19 +85,22 @@ async def test_alarm_control_panel(hass, zha_device_joined_restored, zigpy_devic # trip alarm from faulty code entry cluster.client_command.reset_mock() await hass.services.async_call( - ALARM_DOMAIN, "alarm_arm_away", {ATTR_ENTITY_ID: entity_id}, blocking=True + Platform.ALARM_CONTROL_PANEL, + "alarm_arm_away", + {ATTR_ENTITY_ID: entity_id}, + blocking=True, ) await hass.async_block_till_done() assert hass.states.get(entity_id).state == STATE_ALARM_ARMED_AWAY cluster.client_command.reset_mock() await hass.services.async_call( - ALARM_DOMAIN, + Platform.ALARM_CONTROL_PANEL, "alarm_disarm", {ATTR_ENTITY_ID: entity_id, "code": "1111"}, blocking=True, ) await hass.services.async_call( - ALARM_DOMAIN, + Platform.ALARM_CONTROL_PANEL, "alarm_disarm", {ATTR_ENTITY_ID: entity_id, "code": "1111"}, blocking=True, @@ -117,7 +123,10 @@ async def test_alarm_control_panel(hass, zha_device_joined_restored, zigpy_devic # arm_home from HA cluster.client_command.reset_mock() await hass.services.async_call( - ALARM_DOMAIN, "alarm_arm_home", {ATTR_ENTITY_ID: entity_id}, blocking=True + Platform.ALARM_CONTROL_PANEL, + "alarm_arm_home", + {ATTR_ENTITY_ID: entity_id}, + blocking=True, ) await hass.async_block_till_done() assert hass.states.get(entity_id).state == STATE_ALARM_ARMED_HOME @@ -134,7 +143,10 @@ async def test_alarm_control_panel(hass, zha_device_joined_restored, zigpy_devic # arm_night from HA cluster.client_command.reset_mock() await hass.services.async_call( - ALARM_DOMAIN, "alarm_arm_night", {ATTR_ENTITY_ID: entity_id}, blocking=True + Platform.ALARM_CONTROL_PANEL, + "alarm_arm_night", + {ATTR_ENTITY_ID: entity_id}, + blocking=True, ) await hass.async_block_till_done() assert hass.states.get(entity_id).state == STATE_ALARM_ARMED_NIGHT @@ -228,7 +240,7 @@ async def reset_alarm_panel(hass, cluster, entity_id): """Reset the state of the alarm panel.""" cluster.client_command.reset_mock() await hass.services.async_call( - ALARM_DOMAIN, + Platform.ALARM_CONTROL_PANEL, "alarm_disarm", {ATTR_ENTITY_ID: entity_id, "code": "4321"}, blocking=True, diff --git a/tests/components/zha/test_binary_sensor.py b/tests/components/zha/test_binary_sensor.py index 1ab638d0b26..bfe2a3ce4f5 100644 --- a/tests/components/zha/test_binary_sensor.py +++ b/tests/components/zha/test_binary_sensor.py @@ -4,8 +4,7 @@ import zigpy.profiles.zha import zigpy.zcl.clusters.measurement as measurement import zigpy.zcl.clusters.security as security -from homeassistant.components.binary_sensor import DOMAIN -from homeassistant.const import STATE_OFF, STATE_ON, STATE_UNAVAILABLE +from homeassistant.const import STATE_OFF, STATE_ON, STATE_UNAVAILABLE, Platform from .common import ( async_enable_traffic, @@ -78,7 +77,7 @@ async def test_binary_sensor( """Test ZHA binary_sensor platform.""" zigpy_device = zigpy_device_mock(device) zha_device = await zha_device_joined_restored(zigpy_device) - entity_id = await find_entity_id(DOMAIN, zha_device, hass) + entity_id = await find_entity_id(Platform.BINARY_SENSOR, zha_device, hass) assert entity_id is not None assert hass.states.get(entity_id).state == STATE_OFF diff --git a/tests/components/zha/test_climate.py b/tests/components/zha/test_climate.py index 09da644bd29..58d5240aad7 100644 --- a/tests/components/zha/test_climate.py +++ b/tests/components/zha/test_climate.py @@ -45,14 +45,14 @@ from homeassistant.components.climate.const import ( SERVICE_SET_PRESET_MODE, SERVICE_SET_TEMPERATURE, ) -from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN -from homeassistant.components.zha.climate import ( - DOMAIN, - HVAC_MODE_2_SYSTEM, - SEQ_OF_OPERATION, -) +from homeassistant.components.zha.climate import HVAC_MODE_2_SYSTEM, SEQ_OF_OPERATION from homeassistant.components.zha.core.const import PRESET_COMPLEX, PRESET_SCHEDULE -from homeassistant.const import ATTR_ENTITY_ID, ATTR_TEMPERATURE, STATE_UNKNOWN +from homeassistant.const import ( + ATTR_ENTITY_ID, + ATTR_TEMPERATURE, + STATE_UNKNOWN, + Platform, +) from .common import async_enable_traffic, find_entity_id, send_attributes_report from .conftest import SIG_EP_INPUT, SIG_EP_OUTPUT, SIG_EP_PROFILE, SIG_EP_TYPE @@ -244,7 +244,7 @@ async def test_climate_local_temp(hass, device_climate): """Test local temperature.""" thrm_cluster = device_climate.device.endpoints[1].thermostat - entity_id = await find_entity_id(DOMAIN, device_climate, hass) + entity_id = await find_entity_id(Platform.CLIMATE, device_climate, hass) state = hass.states.get(entity_id) assert state.attributes[ATTR_CURRENT_TEMPERATURE] is None @@ -258,8 +258,8 @@ async def test_climate_hvac_action_running_state(hass, device_climate): """Test hvac action via running state.""" thrm_cluster = device_climate.device.endpoints[1].thermostat - entity_id = await find_entity_id(DOMAIN, device_climate, hass) - sensor_entity_id = await find_entity_id(SENSOR_DOMAIN, device_climate, hass) + entity_id = await find_entity_id(Platform.CLIMATE, device_climate, hass) + sensor_entity_id = await find_entity_id(Platform.SENSOR, device_climate, hass) state = hass.states.get(entity_id) assert state.attributes[ATTR_HVAC_ACTION] == CURRENT_HVAC_OFF @@ -319,8 +319,8 @@ async def test_climate_hvac_action_running_state_zen(hass, device_climate_zen): """Test Zen hvac action via running state.""" thrm_cluster = device_climate_zen.device.endpoints[1].thermostat - entity_id = await find_entity_id(DOMAIN, device_climate_zen, hass) - sensor_entity_id = await find_entity_id(SENSOR_DOMAIN, device_climate_zen, hass) + entity_id = await find_entity_id(Platform.CLIMATE, device_climate_zen, hass) + sensor_entity_id = await find_entity_id(Platform.SENSOR, device_climate_zen, hass) state = hass.states.get(entity_id) assert ATTR_HVAC_ACTION not in state.attributes @@ -404,7 +404,7 @@ async def test_climate_hvac_action_pi_demand(hass, device_climate): """Test hvac action based on pi_heating/cooling_demand attrs.""" thrm_cluster = device_climate.device.endpoints[1].thermostat - entity_id = await find_entity_id(DOMAIN, device_climate, hass) + entity_id = await find_entity_id(Platform.CLIMATE, device_climate, hass) state = hass.states.get(entity_id) assert state.attributes[ATTR_HVAC_ACTION] == CURRENT_HVAC_OFF @@ -451,7 +451,7 @@ async def test_hvac_mode(hass, device_climate, sys_mode, hvac_mode): """Test HVAC modee.""" thrm_cluster = device_climate.device.endpoints[1].thermostat - entity_id = await find_entity_id(DOMAIN, device_climate, hass) + entity_id = await find_entity_id(Platform.CLIMATE, device_climate, hass) state = hass.states.get(entity_id) assert state.state == HVAC_MODE_OFF @@ -489,7 +489,7 @@ async def test_hvac_modes(hass, device_climate_mock, seq_of_op, modes): device_climate = await device_climate_mock( CLIMATE, {"ctrl_seqe_of_oper": seq_of_op} ) - entity_id = await find_entity_id(DOMAIN, device_climate, hass) + entity_id = await find_entity_id(Platform.CLIMATE, device_climate, hass) state = hass.states.get(entity_id) assert set(state.attributes[ATTR_HVAC_MODES]) == modes @@ -520,10 +520,10 @@ async def test_target_temperature( manuf=MANUF_SINOPE, quirk=zhaquirks.sinope.thermostat.SinopeTechnologiesThermostat, ) - entity_id = await find_entity_id(DOMAIN, device_climate, hass) + entity_id = await find_entity_id(Platform.CLIMATE, device_climate, hass) if preset: await hass.services.async_call( - DOMAIN, + Platform.CLIMATE, SERVICE_SET_PRESET_MODE, {ATTR_ENTITY_ID: entity_id, ATTR_PRESET_MODE: preset}, blocking=True, @@ -556,10 +556,10 @@ async def test_target_temperature_high( manuf=MANUF_SINOPE, quirk=zhaquirks.sinope.thermostat.SinopeTechnologiesThermostat, ) - entity_id = await find_entity_id(DOMAIN, device_climate, hass) + entity_id = await find_entity_id(Platform.CLIMATE, device_climate, hass) if preset: await hass.services.async_call( - DOMAIN, + Platform.CLIMATE, SERVICE_SET_PRESET_MODE, {ATTR_ENTITY_ID: entity_id, ATTR_PRESET_MODE: preset}, blocking=True, @@ -592,10 +592,10 @@ async def test_target_temperature_low( manuf=MANUF_SINOPE, quirk=zhaquirks.sinope.thermostat.SinopeTechnologiesThermostat, ) - entity_id = await find_entity_id(DOMAIN, device_climate, hass) + entity_id = await find_entity_id(Platform.CLIMATE, device_climate, hass) if preset: await hass.services.async_call( - DOMAIN, + Platform.CLIMATE, SERVICE_SET_PRESET_MODE, {ATTR_ENTITY_ID: entity_id, ATTR_PRESET_MODE: preset}, blocking=True, @@ -620,13 +620,13 @@ async def test_set_hvac_mode(hass, device_climate, hvac_mode, sys_mode): """Test setting hvac mode.""" thrm_cluster = device_climate.device.endpoints[1].thermostat - entity_id = await find_entity_id(DOMAIN, device_climate, hass) + entity_id = await find_entity_id(Platform.CLIMATE, device_climate, hass) state = hass.states.get(entity_id) assert state.state == HVAC_MODE_OFF await hass.services.async_call( - DOMAIN, + Platform.CLIMATE, SERVICE_SET_HVAC_MODE, {ATTR_ENTITY_ID: entity_id, ATTR_HVAC_MODE: hvac_mode}, blocking=True, @@ -645,7 +645,7 @@ async def test_set_hvac_mode(hass, device_climate, hvac_mode, sys_mode): # turn off thrm_cluster.write_attributes.reset_mock() await hass.services.async_call( - DOMAIN, + Platform.CLIMATE, SERVICE_SET_HVAC_MODE, {ATTR_ENTITY_ID: entity_id, ATTR_HVAC_MODE: HVAC_MODE_OFF}, blocking=True, @@ -661,7 +661,7 @@ async def test_set_hvac_mode(hass, device_climate, hvac_mode, sys_mode): async def test_preset_setting(hass, device_climate_sinope): """Test preset setting.""" - entity_id = await find_entity_id(DOMAIN, device_climate_sinope, hass) + entity_id = await find_entity_id(Platform.CLIMATE, device_climate_sinope, hass) thrm_cluster = device_climate_sinope.device.endpoints[1].thermostat state = hass.states.get(entity_id) @@ -673,7 +673,7 @@ async def test_preset_setting(hass, device_climate_sinope): ] await hass.services.async_call( - DOMAIN, + Platform.CLIMATE, SERVICE_SET_PRESET_MODE, {ATTR_ENTITY_ID: entity_id, ATTR_PRESET_MODE: PRESET_AWAY}, blocking=True, @@ -690,7 +690,7 @@ async def test_preset_setting(hass, device_climate_sinope): zcl_f.WriteAttributesResponse.deserialize(b"\x00")[0] ] await hass.services.async_call( - DOMAIN, + Platform.CLIMATE, SERVICE_SET_PRESET_MODE, {ATTR_ENTITY_ID: entity_id, ATTR_PRESET_MODE: PRESET_AWAY}, blocking=True, @@ -707,7 +707,7 @@ async def test_preset_setting(hass, device_climate_sinope): zcl_f.WriteAttributesResponse.deserialize(b"\x01\x01\x01")[0] ] await hass.services.async_call( - DOMAIN, + Platform.CLIMATE, SERVICE_SET_PRESET_MODE, {ATTR_ENTITY_ID: entity_id, ATTR_PRESET_MODE: PRESET_NONE}, blocking=True, @@ -724,7 +724,7 @@ async def test_preset_setting(hass, device_climate_sinope): zcl_f.WriteAttributesResponse.deserialize(b"\x00")[0] ] await hass.services.async_call( - DOMAIN, + Platform.CLIMATE, SERVICE_SET_PRESET_MODE, {ATTR_ENTITY_ID: entity_id, ATTR_PRESET_MODE: PRESET_NONE}, blocking=True, @@ -739,14 +739,14 @@ async def test_preset_setting(hass, device_climate_sinope): async def test_preset_setting_invalid(hass, device_climate_sinope): """Test invalid preset setting.""" - entity_id = await find_entity_id(DOMAIN, device_climate_sinope, hass) + entity_id = await find_entity_id(Platform.CLIMATE, device_climate_sinope, hass) thrm_cluster = device_climate_sinope.device.endpoints[1].thermostat state = hass.states.get(entity_id) assert state.attributes[ATTR_PRESET_MODE] == PRESET_NONE await hass.services.async_call( - DOMAIN, + Platform.CLIMATE, SERVICE_SET_PRESET_MODE, {ATTR_ENTITY_ID: entity_id, ATTR_PRESET_MODE: "invalid_preset"}, blocking=True, @@ -760,14 +760,14 @@ async def test_preset_setting_invalid(hass, device_climate_sinope): async def test_set_temperature_hvac_mode(hass, device_climate): """Test setting HVAC mode in temperature service call.""" - entity_id = await find_entity_id(DOMAIN, device_climate, hass) + entity_id = await find_entity_id(Platform.CLIMATE, device_climate, hass) thrm_cluster = device_climate.device.endpoints[1].thermostat state = hass.states.get(entity_id) assert state.state == HVAC_MODE_OFF await hass.services.async_call( - DOMAIN, + Platform.CLIMATE, SERVICE_SET_TEMPERATURE, { ATTR_ENTITY_ID: entity_id, @@ -800,14 +800,14 @@ async def test_set_temperature_heat_cool(hass, device_climate_mock): manuf=MANUF_SINOPE, quirk=zhaquirks.sinope.thermostat.SinopeTechnologiesThermostat, ) - entity_id = await find_entity_id(DOMAIN, device_climate, hass) + entity_id = await find_entity_id(Platform.CLIMATE, device_climate, hass) thrm_cluster = device_climate.device.endpoints[1].thermostat state = hass.states.get(entity_id) assert state.state == HVAC_MODE_HEAT_COOL await hass.services.async_call( - DOMAIN, + Platform.CLIMATE, SERVICE_SET_TEMPERATURE, {ATTR_ENTITY_ID: entity_id, ATTR_TEMPERATURE: 21}, blocking=True, @@ -819,7 +819,7 @@ async def test_set_temperature_heat_cool(hass, device_climate_mock): assert thrm_cluster.write_attributes.await_count == 0 await hass.services.async_call( - DOMAIN, + Platform.CLIMATE, SERVICE_SET_TEMPERATURE, { ATTR_ENTITY_ID: entity_id, @@ -841,7 +841,7 @@ async def test_set_temperature_heat_cool(hass, device_climate_mock): } await hass.services.async_call( - DOMAIN, + Platform.CLIMATE, SERVICE_SET_PRESET_MODE, {ATTR_ENTITY_ID: entity_id, ATTR_PRESET_MODE: PRESET_AWAY}, blocking=True, @@ -849,7 +849,7 @@ async def test_set_temperature_heat_cool(hass, device_climate_mock): thrm_cluster.write_attributes.reset_mock() await hass.services.async_call( - DOMAIN, + Platform.CLIMATE, SERVICE_SET_TEMPERATURE, { ATTR_ENTITY_ID: entity_id, @@ -886,14 +886,14 @@ async def test_set_temperature_heat(hass, device_climate_mock): manuf=MANUF_SINOPE, quirk=zhaquirks.sinope.thermostat.SinopeTechnologiesThermostat, ) - entity_id = await find_entity_id(DOMAIN, device_climate, hass) + entity_id = await find_entity_id(Platform.CLIMATE, device_climate, hass) thrm_cluster = device_climate.device.endpoints[1].thermostat state = hass.states.get(entity_id) assert state.state == HVAC_MODE_HEAT await hass.services.async_call( - DOMAIN, + Platform.CLIMATE, SERVICE_SET_TEMPERATURE, { ATTR_ENTITY_ID: entity_id, @@ -910,7 +910,7 @@ async def test_set_temperature_heat(hass, device_climate_mock): assert thrm_cluster.write_attributes.await_count == 0 await hass.services.async_call( - DOMAIN, + Platform.CLIMATE, SERVICE_SET_TEMPERATURE, {ATTR_ENTITY_ID: entity_id, ATTR_TEMPERATURE: 21}, blocking=True, @@ -926,7 +926,7 @@ async def test_set_temperature_heat(hass, device_climate_mock): } await hass.services.async_call( - DOMAIN, + Platform.CLIMATE, SERVICE_SET_PRESET_MODE, {ATTR_ENTITY_ID: entity_id, ATTR_PRESET_MODE: PRESET_AWAY}, blocking=True, @@ -934,7 +934,7 @@ async def test_set_temperature_heat(hass, device_climate_mock): thrm_cluster.write_attributes.reset_mock() await hass.services.async_call( - DOMAIN, + Platform.CLIMATE, SERVICE_SET_TEMPERATURE, {ATTR_ENTITY_ID: entity_id, ATTR_TEMPERATURE: 22}, blocking=True, @@ -965,14 +965,14 @@ async def test_set_temperature_cool(hass, device_climate_mock): manuf=MANUF_SINOPE, quirk=zhaquirks.sinope.thermostat.SinopeTechnologiesThermostat, ) - entity_id = await find_entity_id(DOMAIN, device_climate, hass) + entity_id = await find_entity_id(Platform.CLIMATE, device_climate, hass) thrm_cluster = device_climate.device.endpoints[1].thermostat state = hass.states.get(entity_id) assert state.state == HVAC_MODE_COOL await hass.services.async_call( - DOMAIN, + Platform.CLIMATE, SERVICE_SET_TEMPERATURE, { ATTR_ENTITY_ID: entity_id, @@ -989,7 +989,7 @@ async def test_set_temperature_cool(hass, device_climate_mock): assert thrm_cluster.write_attributes.await_count == 0 await hass.services.async_call( - DOMAIN, + Platform.CLIMATE, SERVICE_SET_TEMPERATURE, {ATTR_ENTITY_ID: entity_id, ATTR_TEMPERATURE: 21}, blocking=True, @@ -1005,7 +1005,7 @@ async def test_set_temperature_cool(hass, device_climate_mock): } await hass.services.async_call( - DOMAIN, + Platform.CLIMATE, SERVICE_SET_PRESET_MODE, {ATTR_ENTITY_ID: entity_id, ATTR_PRESET_MODE: PRESET_AWAY}, blocking=True, @@ -1013,7 +1013,7 @@ async def test_set_temperature_cool(hass, device_climate_mock): thrm_cluster.write_attributes.reset_mock() await hass.services.async_call( - DOMAIN, + Platform.CLIMATE, SERVICE_SET_TEMPERATURE, {ATTR_ENTITY_ID: entity_id, ATTR_TEMPERATURE: 22}, blocking=True, @@ -1048,14 +1048,14 @@ async def test_set_temperature_wrong_mode(hass, device_climate_mock): }, manuf=MANUF_SINOPE, ) - entity_id = await find_entity_id(DOMAIN, device_climate, hass) + entity_id = await find_entity_id(Platform.CLIMATE, device_climate, hass) thrm_cluster = device_climate.device.endpoints[1].thermostat state = hass.states.get(entity_id) assert state.state == HVAC_MODE_DRY await hass.services.async_call( - DOMAIN, + Platform.CLIMATE, SERVICE_SET_TEMPERATURE, {ATTR_ENTITY_ID: entity_id, ATTR_TEMPERATURE: 24}, blocking=True, @@ -1071,14 +1071,14 @@ async def test_set_temperature_wrong_mode(hass, device_climate_mock): async def test_occupancy_reset(hass, device_climate_sinope): """Test away preset reset.""" - entity_id = await find_entity_id(DOMAIN, device_climate_sinope, hass) + entity_id = await find_entity_id(Platform.CLIMATE, device_climate_sinope, hass) thrm_cluster = device_climate_sinope.device.endpoints[1].thermostat state = hass.states.get(entity_id) assert state.attributes[ATTR_PRESET_MODE] == PRESET_NONE await hass.services.async_call( - DOMAIN, + Platform.CLIMATE, SERVICE_SET_PRESET_MODE, {ATTR_ENTITY_ID: entity_id, ATTR_PRESET_MODE: PRESET_AWAY}, blocking=True, @@ -1098,7 +1098,7 @@ async def test_occupancy_reset(hass, device_climate_sinope): async def test_fan_mode(hass, device_climate_fan): """Test fan mode.""" - entity_id = await find_entity_id(DOMAIN, device_climate_fan, hass) + entity_id = await find_entity_id(Platform.CLIMATE, device_climate_fan, hass) thrm_cluster = device_climate_fan.device.endpoints[1].thermostat state = hass.states.get(entity_id) @@ -1127,11 +1127,11 @@ async def test_fan_mode(hass, device_climate_fan): async def test_set_fan_mode_not_supported(hass, device_climate_fan): """Test fan setting unsupported mode.""" - entity_id = await find_entity_id(DOMAIN, device_climate_fan, hass) + entity_id = await find_entity_id(Platform.CLIMATE, device_climate_fan, hass) fan_cluster = device_climate_fan.device.endpoints[1].fan await hass.services.async_call( - DOMAIN, + Platform.CLIMATE, SERVICE_SET_FAN_MODE, {ATTR_ENTITY_ID: entity_id, ATTR_FAN_MODE: FAN_LOW}, blocking=True, @@ -1142,14 +1142,14 @@ async def test_set_fan_mode_not_supported(hass, device_climate_fan): async def test_set_fan_mode(hass, device_climate_fan): """Test fan mode setting.""" - entity_id = await find_entity_id(DOMAIN, device_climate_fan, hass) + entity_id = await find_entity_id(Platform.CLIMATE, device_climate_fan, hass) fan_cluster = device_climate_fan.device.endpoints[1].fan state = hass.states.get(entity_id) assert state.attributes[ATTR_FAN_MODE] == FAN_AUTO await hass.services.async_call( - DOMAIN, + Platform.CLIMATE, SERVICE_SET_FAN_MODE, {ATTR_ENTITY_ID: entity_id, ATTR_FAN_MODE: FAN_ON}, blocking=True, @@ -1159,7 +1159,7 @@ async def test_set_fan_mode(hass, device_climate_fan): fan_cluster.write_attributes.reset_mock() await hass.services.async_call( - DOMAIN, + Platform.CLIMATE, SERVICE_SET_FAN_MODE, {ATTR_ENTITY_ID: entity_id, ATTR_FAN_MODE: FAN_AUTO}, blocking=True, @@ -1171,14 +1171,14 @@ async def test_set_fan_mode(hass, device_climate_fan): async def test_set_moes_preset(hass, device_climate_moes): """Test setting preset for moes trv.""" - entity_id = await find_entity_id(DOMAIN, device_climate_moes, hass) + entity_id = await find_entity_id(Platform.CLIMATE, device_climate_moes, hass) thrm_cluster = device_climate_moes.device.endpoints[1].thermostat state = hass.states.get(entity_id) assert state.attributes[ATTR_PRESET_MODE] == PRESET_NONE await hass.services.async_call( - DOMAIN, + Platform.CLIMATE, SERVICE_SET_PRESET_MODE, {ATTR_ENTITY_ID: entity_id, ATTR_PRESET_MODE: PRESET_AWAY}, blocking=True, @@ -1191,7 +1191,7 @@ async def test_set_moes_preset(hass, device_climate_moes): thrm_cluster.write_attributes.reset_mock() await hass.services.async_call( - DOMAIN, + Platform.CLIMATE, SERVICE_SET_PRESET_MODE, {ATTR_ENTITY_ID: entity_id, ATTR_PRESET_MODE: PRESET_SCHEDULE}, blocking=True, @@ -1207,7 +1207,7 @@ async def test_set_moes_preset(hass, device_climate_moes): thrm_cluster.write_attributes.reset_mock() await hass.services.async_call( - DOMAIN, + Platform.CLIMATE, SERVICE_SET_PRESET_MODE, {ATTR_ENTITY_ID: entity_id, ATTR_PRESET_MODE: PRESET_COMFORT}, blocking=True, @@ -1223,7 +1223,7 @@ async def test_set_moes_preset(hass, device_climate_moes): thrm_cluster.write_attributes.reset_mock() await hass.services.async_call( - DOMAIN, + Platform.CLIMATE, SERVICE_SET_PRESET_MODE, {ATTR_ENTITY_ID: entity_id, ATTR_PRESET_MODE: PRESET_ECO}, blocking=True, @@ -1239,7 +1239,7 @@ async def test_set_moes_preset(hass, device_climate_moes): thrm_cluster.write_attributes.reset_mock() await hass.services.async_call( - DOMAIN, + Platform.CLIMATE, SERVICE_SET_PRESET_MODE, {ATTR_ENTITY_ID: entity_id, ATTR_PRESET_MODE: PRESET_BOOST}, blocking=True, @@ -1255,7 +1255,7 @@ async def test_set_moes_preset(hass, device_climate_moes): thrm_cluster.write_attributes.reset_mock() await hass.services.async_call( - DOMAIN, + Platform.CLIMATE, SERVICE_SET_PRESET_MODE, {ATTR_ENTITY_ID: entity_id, ATTR_PRESET_MODE: PRESET_COMPLEX}, blocking=True, @@ -1271,7 +1271,7 @@ async def test_set_moes_preset(hass, device_climate_moes): thrm_cluster.write_attributes.reset_mock() await hass.services.async_call( - DOMAIN, + Platform.CLIMATE, SERVICE_SET_PRESET_MODE, {ATTR_ENTITY_ID: entity_id, ATTR_PRESET_MODE: PRESET_NONE}, blocking=True, @@ -1286,7 +1286,7 @@ async def test_set_moes_preset(hass, device_climate_moes): async def test_set_moes_operation_mode(hass, device_climate_moes): """Test setting preset for moes trv.""" - entity_id = await find_entity_id(DOMAIN, device_climate_moes, hass) + entity_id = await find_entity_id(Platform.CLIMATE, device_climate_moes, hass) thrm_cluster = device_climate_moes.device.endpoints[1].thermostat await send_attributes_report(hass, thrm_cluster, {"operation_preset": 0}) diff --git a/tests/components/zha/test_cover.py b/tests/components/zha/test_cover.py index e002e2c26f0..45c5928797d 100644 --- a/tests/components/zha/test_cover.py +++ b/tests/components/zha/test_cover.py @@ -11,7 +11,6 @@ import zigpy.zcl.foundation as zcl_f from homeassistant.components.cover import ( ATTR_CURRENT_POSITION, - DOMAIN, SERVICE_CLOSE_COVER, SERVICE_OPEN_COVER, SERVICE_SET_COVER_POSITION, @@ -22,6 +21,7 @@ from homeassistant.const import ( STATE_CLOSED, STATE_OPEN, STATE_UNAVAILABLE, + Platform, ) from homeassistant.core import CoreState, State @@ -116,7 +116,7 @@ async def test_cover(m1, hass, zha_device_joined_restored, zigpy_cover_device): assert cluster.read_attributes.call_count == 2 assert "current_position_lift_percentage" in cluster.read_attributes.call_args[0][0] - entity_id = await find_entity_id(DOMAIN, zha_device, hass) + entity_id = await find_entity_id(Platform.COVER, zha_device, hass) assert entity_id is not None await async_enable_traffic(hass, [zha_device], enabled=False) @@ -140,7 +140,7 @@ async def test_cover(m1, hass, zha_device_joined_restored, zigpy_cover_device): "zigpy.zcl.Cluster.request", return_value=mock_coro([0x1, zcl_f.Status.SUCCESS]) ): await hass.services.async_call( - DOMAIN, SERVICE_CLOSE_COVER, {"entity_id": entity_id}, blocking=True + Platform.COVER, SERVICE_CLOSE_COVER, {"entity_id": entity_id}, blocking=True ) assert cluster.request.call_count == 1 assert cluster.request.call_args[0][0] is False @@ -153,7 +153,7 @@ async def test_cover(m1, hass, zha_device_joined_restored, zigpy_cover_device): "zigpy.zcl.Cluster.request", return_value=mock_coro([0x0, zcl_f.Status.SUCCESS]) ): await hass.services.async_call( - DOMAIN, SERVICE_OPEN_COVER, {"entity_id": entity_id}, blocking=True + Platform.COVER, SERVICE_OPEN_COVER, {"entity_id": entity_id}, blocking=True ) assert cluster.request.call_count == 1 assert cluster.request.call_args[0][0] is False @@ -166,7 +166,7 @@ async def test_cover(m1, hass, zha_device_joined_restored, zigpy_cover_device): "zigpy.zcl.Cluster.request", return_value=mock_coro([0x5, zcl_f.Status.SUCCESS]) ): await hass.services.async_call( - DOMAIN, + Platform.COVER, SERVICE_SET_COVER_POSITION, {"entity_id": entity_id, "position": 47}, blocking=True, @@ -183,7 +183,7 @@ async def test_cover(m1, hass, zha_device_joined_restored, zigpy_cover_device): "zigpy.zcl.Cluster.request", return_value=mock_coro([0x2, zcl_f.Status.SUCCESS]) ): await hass.services.async_call( - DOMAIN, SERVICE_STOP_COVER, {"entity_id": entity_id}, blocking=True + Platform.COVER, SERVICE_STOP_COVER, {"entity_id": entity_id}, blocking=True ) assert cluster.request.call_count == 1 assert cluster.request.call_args[0][0] is False @@ -204,7 +204,7 @@ async def test_shade(hass, zha_device_joined_restored, zigpy_shade_device): cluster_on_off = zigpy_shade_device.endpoints.get(1).on_off cluster_level = zigpy_shade_device.endpoints.get(1).level - entity_id = await find_entity_id(DOMAIN, zha_device, hass) + entity_id = await find_entity_id(Platform.COVER, zha_device, hass) assert entity_id is not None await async_enable_traffic(hass, [zha_device], enabled=False) @@ -226,7 +226,7 @@ async def test_shade(hass, zha_device_joined_restored, zigpy_shade_device): # close from UI command fails with patch("zigpy.zcl.Cluster.request", side_effect=asyncio.TimeoutError): await hass.services.async_call( - DOMAIN, SERVICE_CLOSE_COVER, {"entity_id": entity_id}, blocking=True + Platform.COVER, SERVICE_CLOSE_COVER, {"entity_id": entity_id}, blocking=True ) assert cluster_on_off.request.call_count == 1 assert cluster_on_off.request.call_args[0][0] is False @@ -237,7 +237,7 @@ async def test_shade(hass, zha_device_joined_restored, zigpy_shade_device): "zigpy.zcl.Cluster.request", AsyncMock(return_value=[0x1, zcl_f.Status.SUCCESS]) ): await hass.services.async_call( - DOMAIN, SERVICE_CLOSE_COVER, {"entity_id": entity_id}, blocking=True + Platform.COVER, SERVICE_CLOSE_COVER, {"entity_id": entity_id}, blocking=True ) assert cluster_on_off.request.call_count == 1 assert cluster_on_off.request.call_args[0][0] is False @@ -249,7 +249,7 @@ async def test_shade(hass, zha_device_joined_restored, zigpy_shade_device): await send_attributes_report(hass, cluster_level, {0: 0}) with patch("zigpy.zcl.Cluster.request", side_effect=asyncio.TimeoutError): await hass.services.async_call( - DOMAIN, SERVICE_OPEN_COVER, {"entity_id": entity_id}, blocking=True + Platform.COVER, SERVICE_OPEN_COVER, {"entity_id": entity_id}, blocking=True ) assert cluster_on_off.request.call_count == 1 assert cluster_on_off.request.call_args[0][0] is False @@ -261,7 +261,7 @@ async def test_shade(hass, zha_device_joined_restored, zigpy_shade_device): "zigpy.zcl.Cluster.request", AsyncMock(return_value=[0x0, zcl_f.Status.SUCCESS]) ): await hass.services.async_call( - DOMAIN, SERVICE_OPEN_COVER, {"entity_id": entity_id}, blocking=True + Platform.COVER, SERVICE_OPEN_COVER, {"entity_id": entity_id}, blocking=True ) assert cluster_on_off.request.call_count == 1 assert cluster_on_off.request.call_args[0][0] is False @@ -271,7 +271,7 @@ async def test_shade(hass, zha_device_joined_restored, zigpy_shade_device): # set position UI command fails with patch("zigpy.zcl.Cluster.request", side_effect=asyncio.TimeoutError): await hass.services.async_call( - DOMAIN, + Platform.COVER, SERVICE_SET_COVER_POSITION, {"entity_id": entity_id, "position": 47}, blocking=True, @@ -287,7 +287,7 @@ async def test_shade(hass, zha_device_joined_restored, zigpy_shade_device): "zigpy.zcl.Cluster.request", AsyncMock(return_value=[0x5, zcl_f.Status.SUCCESS]) ): await hass.services.async_call( - DOMAIN, + Platform.COVER, SERVICE_SET_COVER_POSITION, {"entity_id": entity_id, "position": 47}, blocking=True, @@ -313,7 +313,7 @@ async def test_shade(hass, zha_device_joined_restored, zigpy_shade_device): # test cover stop with patch("zigpy.zcl.Cluster.request", side_effect=asyncio.TimeoutError): await hass.services.async_call( - DOMAIN, + Platform.COVER, SERVICE_STOP_COVER, {"entity_id": entity_id}, blocking=True, @@ -340,7 +340,7 @@ async def test_restore_state(hass, zha_device_restored, zigpy_shade_device): hass.state = CoreState.starting zha_device = await zha_device_restored(zigpy_shade_device) - entity_id = await find_entity_id(DOMAIN, zha_device, hass) + entity_id = await find_entity_id(Platform.COVER, zha_device, hass) assert entity_id is not None # test that the cover was created and that it is unavailable @@ -356,7 +356,7 @@ async def test_keen_vent(hass, zha_device_joined_restored, zigpy_keen_vent): cluster_on_off = zigpy_keen_vent.endpoints.get(1).on_off cluster_level = zigpy_keen_vent.endpoints.get(1).level - entity_id = await find_entity_id(DOMAIN, zha_device, hass) + entity_id = await find_entity_id(Platform.COVER, zha_device, hass) assert entity_id is not None await async_enable_traffic(hass, [zha_device], enabled=False) @@ -377,7 +377,7 @@ async def test_keen_vent(hass, zha_device_joined_restored, zigpy_keen_vent): with p1, p2: await hass.services.async_call( - DOMAIN, SERVICE_OPEN_COVER, {"entity_id": entity_id}, blocking=True + Platform.COVER, SERVICE_OPEN_COVER, {"entity_id": entity_id}, blocking=True ) assert cluster_on_off.request.call_count == 1 assert cluster_on_off.request.call_args[0][0] is False @@ -391,7 +391,7 @@ async def test_keen_vent(hass, zha_device_joined_restored, zigpy_keen_vent): with p1, p2: await hass.services.async_call( - DOMAIN, SERVICE_OPEN_COVER, {"entity_id": entity_id}, blocking=True + Platform.COVER, SERVICE_OPEN_COVER, {"entity_id": entity_id}, blocking=True ) await asyncio.sleep(0) assert cluster_on_off.request.call_count == 1 diff --git a/tests/components/zha/test_device_tracker.py b/tests/components/zha/test_device_tracker.py index 60dd136b9fd..e345918179e 100644 --- a/tests/components/zha/test_device_tracker.py +++ b/tests/components/zha/test_device_tracker.py @@ -6,11 +6,11 @@ import pytest import zigpy.profiles.zha import zigpy.zcl.clusters.general as general -from homeassistant.components.device_tracker import DOMAIN, SOURCE_TYPE_ROUTER +from homeassistant.components.device_tracker import SOURCE_TYPE_ROUTER from homeassistant.components.zha.core.registries import ( SMARTTHINGS_ARRIVAL_SENSOR_DEVICE_TYPE, ) -from homeassistant.const import STATE_HOME, STATE_NOT_HOME, STATE_UNAVAILABLE +from homeassistant.const import STATE_HOME, STATE_NOT_HOME, STATE_UNAVAILABLE, Platform import homeassistant.util.dt as dt_util from .common import ( @@ -49,7 +49,7 @@ async def test_device_tracker(hass, zha_device_joined_restored, zigpy_device_dt) zha_device = await zha_device_joined_restored(zigpy_device_dt) cluster = zigpy_device_dt.endpoints.get(1).power - entity_id = await find_entity_id(DOMAIN, zha_device, hass) + entity_id = await find_entity_id(Platform.DEVICE_TRACKER, zha_device, hass) assert entity_id is not None assert hass.states.get(entity_id).state == STATE_HOME @@ -80,7 +80,7 @@ async def test_device_tracker(hass, zha_device_joined_restored, zigpy_device_dt) assert hass.states.get(entity_id).state == STATE_HOME - entity = hass.data[DOMAIN].get_entity(entity_id) + entity = hass.data[Platform.DEVICE_TRACKER].get_entity(entity_id) assert entity.is_connected is True assert entity.source_type == SOURCE_TYPE_ROUTER diff --git a/tests/components/zha/test_discover.py b/tests/components/zha/test_discover.py index d765ede0e5f..6b34590f4ad 100644 --- a/tests/components/zha/test_discover.py +++ b/tests/components/zha/test_discover.py @@ -27,6 +27,7 @@ import homeassistant.components.zha.light import homeassistant.components.zha.lock import homeassistant.components.zha.sensor import homeassistant.components.zha.switch +from homeassistant.const import Platform import homeassistant.helpers.entity_registry from .common import get_zha_gateway @@ -150,7 +151,7 @@ async def test_devices( ha_comp, ha_unique_id, ha_channels = ha_ent_info[ (test_unique_id_head, test_ent_class) ] - assert component is ha_comp + assert component is ha_comp.value # unique_id used for discover is the same for "multi entities" assert unique_id.startswith(ha_unique_id) assert {ch.name for ch in ha_channels} == set(ent_info[DEV_SIG_CHANNELS]) @@ -193,9 +194,9 @@ def test_discover_entities(m1, m2): @pytest.mark.parametrize( "device_type, component, hit", [ - (zigpy.profiles.zha.DeviceType.ON_OFF_LIGHT, zha_const.LIGHT, True), - (zigpy.profiles.zha.DeviceType.ON_OFF_BALLAST, zha_const.SWITCH, True), - (zigpy.profiles.zha.DeviceType.SMART_PLUG, zha_const.SWITCH, True), + (zigpy.profiles.zha.DeviceType.ON_OFF_LIGHT, Platform.LIGHT, True), + (zigpy.profiles.zha.DeviceType.ON_OFF_BALLAST, Platform.SWITCH, True), + (zigpy.profiles.zha.DeviceType.SMART_PLUG, Platform.SWITCH, True), (0xFFFF, None, False), ], ) @@ -234,7 +235,7 @@ def test_discover_by_device_type_override(): ep_mock.return_value.device_type = 0x0100 type(ep_channels).endpoint = ep_mock - overrides = {ep_channels.unique_id: {"type": zha_const.SWITCH}} + overrides = {ep_channels.unique_id: {"type": Platform.SWITCH}} get_entity_mock = mock.MagicMock( return_value=(mock.sentinel.entity_cls, mock.sentinel.claimed) ) @@ -247,7 +248,7 @@ def test_discover_by_device_type_override(): assert ep_channels.claim_channels.call_count == 1 assert ep_channels.claim_channels.call_args[0][0] is mock.sentinel.claimed assert ep_channels.async_new_entity.call_count == 1 - assert ep_channels.async_new_entity.call_args[0][0] == zha_const.SWITCH + assert ep_channels.async_new_entity.call_args[0][0] == Platform.SWITCH assert ep_channels.async_new_entity.call_args[0][1] == mock.sentinel.entity_cls @@ -268,13 +269,13 @@ def test_discover_probe_single_cluster(): "homeassistant.components.zha.core.registries.ZHA_ENTITIES.get_entity", get_entity_mock, ): - disc.PROBE.probe_single_cluster(zha_const.SWITCH, channel_mock, ep_channels) + disc.PROBE.probe_single_cluster(Platform.SWITCH, channel_mock, ep_channels) assert get_entity_mock.call_count == 1 assert ep_channels.claim_channels.call_count == 1 assert ep_channels.claim_channels.call_args[0][0] is mock.sentinel.claimed assert ep_channels.async_new_entity.call_count == 1 - assert ep_channels.async_new_entity.call_args[0][0] == zha_const.SWITCH + assert ep_channels.async_new_entity.call_args[0][0] == Platform.SWITCH assert ep_channels.async_new_entity.call_args[0][1] == mock.sentinel.entity_cls assert ep_channels.async_new_entity.call_args[0][3] == mock.sentinel.claimed @@ -320,7 +321,7 @@ async def test_discover_endpoint(device_info, channels_mock, hass): ha_comp, ha_unique_id, ha_channels = ha_ent_info[ (test_unique_id_head, test_ent_class) ] - assert component is ha_comp + assert component is ha_comp.value # unique_id used for discover is the same for "multi entities" assert unique_id.startswith(ha_unique_id) assert {ch.name for ch in ha_channels} == set(ent_info[DEV_SIG_CHANNELS]) @@ -372,11 +373,11 @@ def _test_single_input_cluster_device_class(probe_mock): disc.ProbeEndpoint().discover_by_cluster_id(ch_pool) assert probe_mock.call_count == len(ch_pool.unclaimed_channels()) probes = ( - (zha_const.LOCK, door_ch), - (zha_const.COVER, cover_ch), - (zha_const.SENSOR, multistate_ch), - (zha_const.BINARY_SENSOR, ias_ch), - (zha_const.SENSOR, analog_ch), + (Platform.LOCK, door_ch), + (Platform.COVER, cover_ch), + (Platform.SENSOR, multistate_ch), + (Platform.BINARY_SENSOR, ias_ch), + (Platform.SENSOR, analog_ch), ) for call, details in zip(probe_mock.call_args_list, probes): component, ch = details @@ -392,11 +393,11 @@ def test_single_input_cluster_device_class(): def test_single_input_cluster_device_class_by_cluster_class(): """Test SINGLE_INPUT_CLUSTER_DEVICE_CLASS matching by cluster id or class.""" mock_reg = { - zigpy.zcl.clusters.closures.DoorLock.cluster_id: zha_const.LOCK, - zigpy.zcl.clusters.closures.WindowCovering.cluster_id: zha_const.COVER, - zigpy.zcl.clusters.general.AnalogInput: zha_const.SENSOR, - zigpy.zcl.clusters.general.MultistateInput: zha_const.SENSOR, - zigpy.zcl.clusters.security.IasZone: zha_const.BINARY_SENSOR, + zigpy.zcl.clusters.closures.DoorLock.cluster_id: Platform.LOCK, + zigpy.zcl.clusters.closures.WindowCovering.cluster_id: Platform.COVER, + zigpy.zcl.clusters.general.AnalogInput: Platform.SENSOR, + zigpy.zcl.clusters.general.MultistateInput: Platform.SENSOR, + zigpy.zcl.clusters.security.IasZone: Platform.BINARY_SENSOR, } with mock.patch.dict( diff --git a/tests/components/zha/test_fan.py b/tests/components/zha/test_fan.py index 212152e231d..e94c028acd8 100644 --- a/tests/components/zha/test_fan.py +++ b/tests/components/zha/test_fan.py @@ -14,7 +14,6 @@ from homeassistant.components.fan import ( ATTR_PERCENTAGE_STEP, ATTR_PRESET_MODE, ATTR_SPEED, - DOMAIN, SERVICE_SET_PRESET_MODE, SERVICE_SET_SPEED, SPEED_HIGH, @@ -23,7 +22,6 @@ from homeassistant.components.fan import ( SPEED_OFF, NotValidPresetModeError, ) -from homeassistant.components.light import DOMAIN as LIGHT_DOMAIN from homeassistant.components.zha.core.discovery import GROUP_PROBE from homeassistant.components.zha.core.group import GroupMember from homeassistant.components.zha.fan import ( @@ -38,6 +36,7 @@ from homeassistant.const import ( STATE_OFF, STATE_ON, STATE_UNAVAILABLE, + Platform, ) from homeassistant.setup import async_setup_component @@ -151,7 +150,7 @@ async def test_fan(hass, zha_device_joined_restored, zigpy_device): zha_device = await zha_device_joined_restored(zigpy_device) cluster = zigpy_device.endpoints.get(1).fan - entity_id = await find_entity_id(DOMAIN, zha_device, hass) + entity_id = await find_entity_id(Platform.FAN, zha_device, hass) assert entity_id is not None assert hass.states.get(entity_id).state == STATE_OFF @@ -217,14 +216,14 @@ async def async_turn_on(hass, entity_id, speed=None): if value is not None } - await hass.services.async_call(DOMAIN, SERVICE_TURN_ON, data, blocking=True) + await hass.services.async_call(Platform.FAN, SERVICE_TURN_ON, data, blocking=True) async def async_turn_off(hass, entity_id): """Turn fan off.""" data = {ATTR_ENTITY_ID: entity_id} if entity_id else {} - await hass.services.async_call(DOMAIN, SERVICE_TURN_OFF, data, blocking=True) + await hass.services.async_call(Platform.FAN, SERVICE_TURN_OFF, data, blocking=True) async def async_set_speed(hass, entity_id, speed=None): @@ -235,7 +234,7 @@ async def async_set_speed(hass, entity_id, speed=None): if value is not None } - await hass.services.async_call(DOMAIN, SERVICE_SET_SPEED, data, blocking=True) + await hass.services.async_call(Platform.FAN, SERVICE_SET_SPEED, data, blocking=True) async def async_set_preset_mode(hass, entity_id, preset_mode=None): @@ -246,7 +245,9 @@ async def async_set_preset_mode(hass, entity_id, preset_mode=None): if value is not None } - await hass.services.async_call(DOMAIN, SERVICE_SET_PRESET_MODE, data, blocking=True) + await hass.services.async_call( + Platform.FAN, SERVICE_SET_PRESET_MODE, data, blocking=True + ) @patch( @@ -282,10 +283,10 @@ async def test_zha_group_fan_entity(hass, device_fan_1, device_fan_2, coordinato entity_domains = GROUP_PROBE.determine_entity_domains(hass, zha_group) assert len(entity_domains) == 2 - assert LIGHT_DOMAIN in entity_domains - assert DOMAIN in entity_domains + assert Platform.LIGHT in entity_domains + assert Platform.FAN in entity_domains - entity_id = async_find_group_entity_id(hass, DOMAIN, zha_group) + entity_id = async_find_group_entity_id(hass, Platform.FAN, zha_group) assert hass.states.get(entity_id) is not None group_fan_cluster = zha_group.endpoint[hvac.Fan.cluster_id] @@ -396,10 +397,10 @@ async def test_zha_group_fan_entity_failure_state( entity_domains = GROUP_PROBE.determine_entity_domains(hass, zha_group) assert len(entity_domains) == 2 - assert LIGHT_DOMAIN in entity_domains - assert DOMAIN in entity_domains + assert Platform.LIGHT in entity_domains + assert Platform.FAN in entity_domains - entity_id = async_find_group_entity_id(hass, DOMAIN, zha_group) + entity_id = async_find_group_entity_id(hass, Platform.FAN, zha_group) assert hass.states.get(entity_id) is not None group_fan_cluster = zha_group.endpoint[hvac.Fan.cluster_id] @@ -450,7 +451,7 @@ async def test_fan_init( cluster.PLUGGED_ATTR_READS = plug_read zha_device = await zha_device_joined_restored(zigpy_device) - entity_id = await find_entity_id(DOMAIN, zha_device, hass) + entity_id = await find_entity_id(Platform.FAN, zha_device, hass) assert entity_id is not None assert hass.states.get(entity_id).state == expected_state assert hass.states.get(entity_id).attributes[ATTR_SPEED] == expected_speed @@ -469,7 +470,7 @@ async def test_fan_update_entity( cluster.PLUGGED_ATTR_READS = {"fan_mode": 0} zha_device = await zha_device_joined_restored(zigpy_device) - entity_id = await find_entity_id(DOMAIN, zha_device, hass) + entity_id = await find_entity_id(Platform.FAN, zha_device, hass) assert entity_id is not None assert hass.states.get(entity_id).state == STATE_OFF assert hass.states.get(entity_id).attributes[ATTR_SPEED] == SPEED_OFF diff --git a/tests/components/zha/test_gateway.py b/tests/components/zha/test_gateway.py index 6662f0c2c9f..a263a6d7ed3 100644 --- a/tests/components/zha/test_gateway.py +++ b/tests/components/zha/test_gateway.py @@ -8,9 +8,9 @@ import zigpy.profiles.zha as zha import zigpy.zcl.clusters.general as general import zigpy.zcl.clusters.lighting as lighting -from homeassistant.components.light import DOMAIN as LIGHT_DOMAIN from homeassistant.components.zha.core.group import GroupMember from homeassistant.components.zha.core.store import TOMBSTONE_LIFETIME +from homeassistant.const import Platform from .common import async_enable_traffic, async_find_group_entity_id, get_zha_gateway from .conftest import SIG_EP_INPUT, SIG_EP_OUTPUT, SIG_EP_PROFILE, SIG_EP_TYPE @@ -144,7 +144,7 @@ async def test_gateway_group_methods(hass, device_light_1, device_light_2, coord for member in zha_group.members: assert member.device.ieee in member_ieee_addresses - entity_id = async_find_group_entity_id(hass, LIGHT_DOMAIN, zha_group) + entity_id = async_find_group_entity_id(hass, Platform.LIGHT, zha_group) assert hass.states.get(entity_id) is not None # test get group by name @@ -158,7 +158,7 @@ async def test_gateway_group_methods(hass, device_light_1, device_light_2, coord assert zha_gateway.async_get_group_by_name(zha_group.name) is None # the group entity should be cleaned up - assert entity_id not in hass.states.async_entity_ids(LIGHT_DOMAIN) + assert entity_id not in hass.states.async_entity_ids(Platform.LIGHT) # test creating a group with 1 member zha_group = await zha_gateway.async_create_zigpy_group( @@ -172,7 +172,7 @@ async def test_gateway_group_methods(hass, device_light_1, device_light_2, coord assert member.device.ieee in [device_light_1.ieee] # the group entity should not have been cleaned up - assert entity_id not in hass.states.async_entity_ids(LIGHT_DOMAIN) + assert entity_id not in hass.states.async_entity_ids(Platform.LIGHT) with patch("zigpy.zcl.Cluster.request", side_effect=asyncio.TimeoutError): await zha_group.members[0].async_remove_from_group() diff --git a/tests/components/zha/test_light.py b/tests/components/zha/test_light.py index d1a3b5dabb0..ee437fc63c9 100644 --- a/tests/components/zha/test_light.py +++ b/tests/components/zha/test_light.py @@ -9,10 +9,10 @@ import zigpy.zcl.clusters.general as general import zigpy.zcl.clusters.lighting as lighting import zigpy.zcl.foundation as zcl_f -from homeassistant.components.light import DOMAIN, FLASH_LONG, FLASH_SHORT +from homeassistant.components.light import FLASH_LONG, FLASH_SHORT from homeassistant.components.zha.core.group import GroupMember from homeassistant.components.zha.light import FLASH_EFFECTS -from homeassistant.const import STATE_OFF, STATE_ON, STATE_UNAVAILABLE +from homeassistant.const import STATE_OFF, STATE_ON, STATE_UNAVAILABLE, Platform import homeassistant.util.dt as dt_util from .common import ( @@ -187,7 +187,7 @@ async def test_light_refresh(hass, zigpy_device_mock, zha_device_joined_restored on_off_cluster = zigpy_device.endpoints[1].on_off on_off_cluster.PLUGGED_ATTR_READS = {"on_off": 0} zha_device = await zha_device_joined_restored(zigpy_device) - entity_id = await find_entity_id(DOMAIN, zha_device, hass) + entity_id = await find_entity_id(Platform.LIGHT, zha_device, hass) # allow traffic to flow through the gateway and device await async_enable_traffic(hass, [zha_device]) @@ -245,7 +245,7 @@ async def test_light( # create zigpy devices zigpy_device = zigpy_device_mock(device) zha_device = await zha_device_joined_restored(zigpy_device) - entity_id = await find_entity_id(DOMAIN, zha_device, hass) + entity_id = await find_entity_id(Platform.LIGHT, zha_device, hass) assert entity_id is not None @@ -327,7 +327,7 @@ async def async_test_on_off_from_hass(hass, cluster, entity_id): # turn on via UI cluster.request.reset_mock() await hass.services.async_call( - DOMAIN, "turn_on", {"entity_id": entity_id}, blocking=True + Platform.LIGHT, "turn_on", {"entity_id": entity_id}, blocking=True ) assert cluster.request.call_count == 1 assert cluster.request.await_count == 1 @@ -344,7 +344,7 @@ async def async_test_off_from_hass(hass, cluster, entity_id): # turn off via UI cluster.request.reset_mock() await hass.services.async_call( - DOMAIN, "turn_off", {"entity_id": entity_id}, blocking=True + Platform.LIGHT, "turn_off", {"entity_id": entity_id}, blocking=True ) assert cluster.request.call_count == 1 assert cluster.request.await_count == 1 @@ -362,7 +362,7 @@ async def async_test_level_on_off_from_hass( level_cluster.request.reset_mock() # turn on via UI await hass.services.async_call( - DOMAIN, "turn_on", {"entity_id": entity_id}, blocking=True + Platform.LIGHT, "turn_on", {"entity_id": entity_id}, blocking=True ) assert on_off_cluster.request.call_count == 1 assert on_off_cluster.request.await_count == 1 @@ -375,7 +375,10 @@ async def async_test_level_on_off_from_hass( level_cluster.request.reset_mock() await hass.services.async_call( - DOMAIN, "turn_on", {"entity_id": entity_id, "transition": 10}, blocking=True + Platform.LIGHT, + "turn_on", + {"entity_id": entity_id, "transition": 10}, + blocking=True, ) assert on_off_cluster.request.call_count == 1 assert on_off_cluster.request.await_count == 1 @@ -399,7 +402,10 @@ async def async_test_level_on_off_from_hass( level_cluster.request.reset_mock() await hass.services.async_call( - DOMAIN, "turn_on", {"entity_id": entity_id, "brightness": 10}, blocking=True + Platform.LIGHT, + "turn_on", + {"entity_id": entity_id, "brightness": 10}, + blocking=True, ) # the onoff cluster is now not used when brightness is present by default assert on_off_cluster.request.call_count == 0 @@ -442,7 +448,10 @@ async def async_test_flash_from_hass(hass, cluster, entity_id, flash): # turn on via UI cluster.request.reset_mock() await hass.services.async_call( - DOMAIN, "turn_on", {"entity_id": entity_id, "flash": flash}, blocking=True + Platform.LIGHT, + "turn_on", + {"entity_id": entity_id, "flash": flash}, + blocking=True, ) assert cluster.request.call_count == 1 assert cluster.request.await_count == 1 @@ -505,9 +514,9 @@ async def test_zha_group_light_entity( assert member.group == zha_group assert member.endpoint is not None - device_1_entity_id = await find_entity_id(DOMAIN, device_light_1, hass) - device_2_entity_id = await find_entity_id(DOMAIN, device_light_2, hass) - device_3_entity_id = await find_entity_id(DOMAIN, device_light_3, hass) + device_1_entity_id = await find_entity_id(Platform.LIGHT, device_light_1, hass) + device_2_entity_id = await find_entity_id(Platform.LIGHT, device_light_2, hass) + device_3_entity_id = await find_entity_id(Platform.LIGHT, device_light_3, hass) assert ( device_1_entity_id != device_2_entity_id @@ -515,7 +524,7 @@ async def test_zha_group_light_entity( ) assert device_2_entity_id != device_3_entity_id - group_entity_id = async_find_group_entity_id(hass, DOMAIN, zha_group) + group_entity_id = async_find_group_entity_id(hass, Platform.LIGHT, zha_group) assert hass.states.get(group_entity_id) is not None assert device_1_entity_id in zha_group.member_entity_ids diff --git a/tests/components/zha/test_lock.py b/tests/components/zha/test_lock.py index ca9b7961d38..c8685996c25 100644 --- a/tests/components/zha/test_lock.py +++ b/tests/components/zha/test_lock.py @@ -7,8 +7,12 @@ import zigpy.zcl.clusters.closures as closures import zigpy.zcl.clusters.general as general import zigpy.zcl.foundation as zcl_f -from homeassistant.components.lock import DOMAIN -from homeassistant.const import STATE_LOCKED, STATE_UNAVAILABLE, STATE_UNLOCKED +from homeassistant.const import ( + STATE_LOCKED, + STATE_UNAVAILABLE, + STATE_UNLOCKED, + Platform, +) from .common import async_enable_traffic, find_entity_id, send_attributes_report from .conftest import SIG_EP_INPUT, SIG_EP_OUTPUT, SIG_EP_TYPE @@ -44,7 +48,7 @@ async def test_lock(hass, lock): """Test zha lock platform.""" zha_device, cluster = lock - entity_id = await find_entity_id(DOMAIN, zha_device, hass) + entity_id = await find_entity_id(Platform.LOCK, zha_device, hass) assert entity_id is not None assert hass.states.get(entity_id).state == STATE_UNLOCKED @@ -92,7 +96,7 @@ async def async_lock(hass, cluster, entity_id): ): # lock via UI await hass.services.async_call( - DOMAIN, "lock", {"entity_id": entity_id}, blocking=True + Platform.LOCK, "lock", {"entity_id": entity_id}, blocking=True ) assert cluster.request.call_count == 1 assert cluster.request.call_args[0][0] is False @@ -106,7 +110,7 @@ async def async_unlock(hass, cluster, entity_id): ): # lock via UI await hass.services.async_call( - DOMAIN, "unlock", {"entity_id": entity_id}, blocking=True + Platform.LOCK, "unlock", {"entity_id": entity_id}, blocking=True ) assert cluster.request.call_count == 1 assert cluster.request.call_args[0][0] is False diff --git a/tests/components/zha/test_number.py b/tests/components/zha/test_number.py index c27cd9fd654..ac72a00d802 100644 --- a/tests/components/zha/test_number.py +++ b/tests/components/zha/test_number.py @@ -7,8 +7,7 @@ import zigpy.types import zigpy.zcl.clusters.general as general import zigpy.zcl.foundation as zcl_f -from homeassistant.components.number import DOMAIN -from homeassistant.const import STATE_UNAVAILABLE +from homeassistant.const import STATE_UNAVAILABLE, Platform from homeassistant.setup import async_setup_component from .common import ( @@ -67,7 +66,7 @@ async def test_number(hass, zha_device_joined_restored, zigpy_analog_output_devi assert "engineering_units" in attr_reads assert "application_type" in attr_reads - entity_id = await find_entity_id(DOMAIN, zha_device, hass) + entity_id = await find_entity_id(Platform.NUMBER, zha_device, hass) assert entity_id is not None await async_enable_traffic(hass, [zha_device], enabled=False) @@ -110,7 +109,10 @@ async def test_number(hass, zha_device_joined_restored, zigpy_analog_output_devi ): # set value via UI await hass.services.async_call( - DOMAIN, "set_value", {"entity_id": entity_id, "value": 30.0}, blocking=True + Platform.NUMBER, + "set_value", + {"entity_id": entity_id, "value": 30.0}, + blocking=True, ) assert len(cluster.write_attributes.mock_calls) == 1 assert cluster.write_attributes.call_args == call({"present_value": 30.0}) diff --git a/tests/components/zha/test_sensor.py b/tests/components/zha/test_sensor.py index af4bb082b03..468458cdc51 100644 --- a/tests/components/zha/test_sensor.py +++ b/tests/components/zha/test_sensor.py @@ -8,7 +8,6 @@ import zigpy.zcl.clusters.homeautomation as homeautomation import zigpy.zcl.clusters.measurement as measurement import zigpy.zcl.clusters.smartenergy as smartenergy -from homeassistant.components.sensor import DOMAIN from homeassistant.components.zha.core.const import ZHA_CHANNEL_READS_PER_REQ import homeassistant.config as config_util from homeassistant.const import ( @@ -32,6 +31,7 @@ from homeassistant.const import ( TEMP_FAHRENHEIT, VOLUME_CUBIC_FEET, VOLUME_CUBIC_METERS, + Platform, ) from homeassistant.helpers import restore_state from homeassistant.helpers.entity_component import async_update_entity @@ -505,7 +505,7 @@ async def test_temp_uom( ) cluster = zigpy_device.endpoints[1].temperature zha_device = await zha_device_restored(zigpy_device) - entity_id = await find_entity_id(DOMAIN, zha_device, hass) + entity_id = await find_entity_id(Platform.SENSOR, zha_device, hass) if not restore: await async_enable_traffic(hass, [zha_device], enabled=False) @@ -545,7 +545,7 @@ async def test_electrical_measurement_init( ) cluster = zigpy_device.endpoints[1].in_clusters[cluster_id] zha_device = await zha_device_joined(zigpy_device) - entity_id = await find_entity_id(DOMAIN, zha_device, hass) + entity_id = await find_entity_id(Platform.SENSOR, zha_device, hass) # allow traffic to flow through the gateway and devices await async_enable_traffic(hass, [zha_device]) @@ -681,7 +681,7 @@ async def test_unsupported_attributes_sensor( await async_enable_traffic(hass, [zha_device], enabled=False) await hass.async_block_till_done() - present_entity_ids = set(await find_entity_ids(DOMAIN, zha_device, hass)) + present_entity_ids = set(await find_entity_ids(Platform.SENSOR, zha_device, hass)) assert present_entity_ids == entity_ids assert missing_entity_ids not in present_entity_ids diff --git a/tests/components/zha/test_siren.py b/tests/components/zha/test_siren.py index d9c173fd932..1414879c0f0 100644 --- a/tests/components/zha/test_siren.py +++ b/tests/components/zha/test_siren.py @@ -9,7 +9,6 @@ import zigpy.zcl.clusters.general as general import zigpy.zcl.clusters.security as security import zigpy.zcl.foundation as zcl_f -from homeassistant.components.siren import DOMAIN from homeassistant.components.siren.const import ( ATTR_DURATION, ATTR_TONE, @@ -19,7 +18,7 @@ from homeassistant.components.zha.core.const import ( WARNING_DEVICE_MODE_EMERGENCY_PANIC, WARNING_DEVICE_SOUND_MEDIUM, ) -from homeassistant.const import STATE_OFF, STATE_ON, STATE_UNAVAILABLE +from homeassistant.const import STATE_OFF, STATE_ON, STATE_UNAVAILABLE, Platform import homeassistant.util.dt as dt_util from .common import async_enable_traffic, find_entity_id @@ -52,7 +51,7 @@ async def test_siren(hass, siren): zha_device, cluster = siren assert cluster is not None - entity_id = await find_entity_id(DOMAIN, zha_device, hass) + entity_id = await find_entity_id(Platform.SIREN, zha_device, hass) assert entity_id is not None assert hass.states.get(entity_id).state == STATE_OFF @@ -73,7 +72,7 @@ async def test_siren(hass, siren): ): # turn on via UI await hass.services.async_call( - DOMAIN, "turn_on", {"entity_id": entity_id}, blocking=True + Platform.SIREN, "turn_on", {"entity_id": entity_id}, blocking=True ) assert len(cluster.request.mock_calls) == 1 assert cluster.request.call_args[0][0] is False @@ -93,7 +92,7 @@ async def test_siren(hass, siren): ): # turn off via UI await hass.services.async_call( - DOMAIN, "turn_off", {"entity_id": entity_id}, blocking=True + Platform.SIREN, "turn_off", {"entity_id": entity_id}, blocking=True ) assert len(cluster.request.mock_calls) == 1 assert cluster.request.call_args[0][0] is False @@ -113,7 +112,7 @@ async def test_siren(hass, siren): ): # turn on via UI await hass.services.async_call( - DOMAIN, + Platform.SIREN, "turn_on", { "entity_id": entity_id, diff --git a/tests/components/zha/test_switch.py b/tests/components/zha/test_switch.py index 04f43344b98..879bc26db9f 100644 --- a/tests/components/zha/test_switch.py +++ b/tests/components/zha/test_switch.py @@ -6,9 +6,8 @@ import zigpy.profiles.zha as zha import zigpy.zcl.clusters.general as general import zigpy.zcl.foundation as zcl_f -from homeassistant.components.switch import DOMAIN from homeassistant.components.zha.core.group import GroupMember -from homeassistant.const import STATE_OFF, STATE_ON, STATE_UNAVAILABLE +from homeassistant.const import STATE_OFF, STATE_ON, STATE_UNAVAILABLE, Platform from .common import ( async_enable_traffic, @@ -108,7 +107,7 @@ async def test_switch(hass, zha_device_joined_restored, zigpy_device): zha_device = await zha_device_joined_restored(zigpy_device) cluster = zigpy_device.endpoints.get(1).on_off - entity_id = await find_entity_id(DOMAIN, zha_device, hass) + entity_id = await find_entity_id(Platform.SWITCH, zha_device, hass) assert entity_id is not None assert hass.states.get(entity_id).state == STATE_OFF @@ -137,7 +136,7 @@ async def test_switch(hass, zha_device_joined_restored, zigpy_device): ): # turn on via UI await hass.services.async_call( - DOMAIN, "turn_on", {"entity_id": entity_id}, blocking=True + Platform.SWITCH, "turn_on", {"entity_id": entity_id}, blocking=True ) assert len(cluster.request.mock_calls) == 1 assert cluster.request.call_args == call( @@ -151,7 +150,7 @@ async def test_switch(hass, zha_device_joined_restored, zigpy_device): ): # turn off via UI await hass.services.async_call( - DOMAIN, "turn_off", {"entity_id": entity_id}, blocking=True + Platform.SWITCH, "turn_off", {"entity_id": entity_id}, blocking=True ) assert len(cluster.request.mock_calls) == 1 assert cluster.request.call_args == call( @@ -193,7 +192,7 @@ async def test_zha_group_switch_entity( assert member.group == zha_group assert member.endpoint is not None - entity_id = async_find_group_entity_id(hass, DOMAIN, zha_group) + entity_id = async_find_group_entity_id(hass, Platform.SWITCH, zha_group) assert hass.states.get(entity_id) is not None group_cluster_on_off = zha_group.endpoint[general.OnOff.cluster_id] @@ -220,7 +219,7 @@ async def test_zha_group_switch_entity( ): # turn on via UI await hass.services.async_call( - DOMAIN, "turn_on", {"entity_id": entity_id}, blocking=True + Platform.SWITCH, "turn_on", {"entity_id": entity_id}, blocking=True ) assert len(group_cluster_on_off.request.mock_calls) == 1 assert group_cluster_on_off.request.call_args == call( @@ -235,7 +234,7 @@ async def test_zha_group_switch_entity( ): # turn off via UI await hass.services.async_call( - DOMAIN, "turn_off", {"entity_id": entity_id}, blocking=True + Platform.SWITCH, "turn_off", {"entity_id": entity_id}, blocking=True ) assert len(group_cluster_on_off.request.mock_calls) == 1 assert group_cluster_on_off.request.call_args == call(