diff --git a/homeassistant/components/insteon/__init__.py b/homeassistant/components/insteon/__init__.py index 3105214bad4..1667f5fb779 100644 --- a/homeassistant/components/insteon/__init__.py +++ b/homeassistant/components/insteon/__init__.py @@ -24,11 +24,10 @@ from .const import ( CONF_X10, DOMAIN, INSTEON_PLATFORMS, - ON_OFF_EVENTS, ) from .schemas import convert_yaml_to_config_flow from .utils import ( - add_on_off_event_device, + add_insteon_events, async_register_services, get_device_platforms, register_new_device_callback, @@ -159,8 +158,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: for address in devices: device = devices[address] platforms = get_device_platforms(device) - if ON_OFF_EVENTS in platforms: - add_on_off_event_device(hass, device) + add_insteon_events(hass, device) + if not platforms: create_insteon_device(hass, device, entry.entry_id) _LOGGER.debug("Insteon device count: %s", len(devices)) diff --git a/homeassistant/components/insteon/binary_sensor.py b/homeassistant/components/insteon/binary_sensor.py index 1357cbaed5b..9d1ec352bed 100644 --- a/homeassistant/components/insteon/binary_sensor.py +++ b/homeassistant/components/insteon/binary_sensor.py @@ -14,11 +14,11 @@ from pyinsteon.groups import ( ) from homeassistant.components.binary_sensor import ( - DOMAIN as BINARY_SENSOR_DOMAIN, BinarySensorDeviceClass, BinarySensorEntity, ) 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 @@ -54,13 +54,13 @@ async def async_setup_entry( """Add the Insteon entities for the platform.""" async_add_insteon_entities( hass, - BINARY_SENSOR_DOMAIN, + Platform.BINARY_SENSOR, InsteonBinarySensorEntity, async_add_entities, discovery_info, ) - signal = f"{SIGNAL_ADD_ENTITIES}_{BINARY_SENSOR_DOMAIN}" + signal = f"{SIGNAL_ADD_ENTITIES}_{Platform.BINARY_SENSOR}" async_dispatcher_connect(hass, signal, async_add_insteon_binary_sensor_entities) async_add_insteon_binary_sensor_entities() diff --git a/homeassistant/components/insteon/climate.py b/homeassistant/components/insteon/climate.py index f88dadf1223..cf5f4ac2c0c 100644 --- a/homeassistant/components/insteon/climate.py +++ b/homeassistant/components/insteon/climate.py @@ -9,7 +9,6 @@ from pyinsteon.constants import ThermostatMode from homeassistant.components.climate import ( ATTR_TARGET_TEMP_HIGH, ATTR_TARGET_TEMP_LOW, - DOMAIN as CLIMATE_DOMAIN, FAN_AUTO, ClimateEntity, ClimateEntityFeature, @@ -17,7 +16,7 @@ from homeassistant.components.climate import ( HVACMode, ) from homeassistant.config_entries import ConfigEntry -from homeassistant.const import ATTR_TEMPERATURE, UnitOfTemperature +from homeassistant.const import ATTR_TEMPERATURE, Platform, UnitOfTemperature from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -64,13 +63,13 @@ async def async_setup_entry( """Add the Insteon entities for the platform.""" async_add_insteon_entities( hass, - CLIMATE_DOMAIN, + Platform.CLIMATE, InsteonClimateEntity, async_add_entities, discovery_info, ) - signal = f"{SIGNAL_ADD_ENTITIES}_{CLIMATE_DOMAIN}" + signal = f"{SIGNAL_ADD_ENTITIES}_{Platform.CLIMATE}" async_dispatcher_connect(hass, signal, async_add_insteon_climate_entities) async_add_insteon_climate_entities() diff --git a/homeassistant/components/insteon/const.py b/homeassistant/components/insteon/const.py index 5337ccd36c3..69040199589 100644 --- a/homeassistant/components/insteon/const.py +++ b/homeassistant/components/insteon/const.py @@ -130,7 +130,6 @@ EVENT_GROUP_OFF = "insteon.button_off" EVENT_GROUP_ON_FAST = "insteon.button_on_fast" EVENT_GROUP_OFF_FAST = "insteon.button_off_fast" EVENT_CONF_BUTTON = "button" -ON_OFF_EVENTS = "on_off_events" STATE_NAME_LABEL_MAP = { DIMMABLE_LIGHT_MAIN: "Main", diff --git a/homeassistant/components/insteon/cover.py b/homeassistant/components/insteon/cover.py index 645450166b9..69a66d304ce 100644 --- a/homeassistant/components/insteon/cover.py +++ b/homeassistant/components/insteon/cover.py @@ -4,11 +4,11 @@ from typing import Any from homeassistant.components.cover import ( ATTR_POSITION, - DOMAIN as COVER_DOMAIN, CoverEntity, CoverEntityFeature, ) 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 @@ -29,10 +29,10 @@ async def async_setup_entry( def async_add_insteon_cover_entities(discovery_info=None): """Add the Insteon entities for the platform.""" async_add_insteon_entities( - hass, COVER_DOMAIN, InsteonCoverEntity, async_add_entities, discovery_info + hass, Platform.COVER, InsteonCoverEntity, async_add_entities, discovery_info ) - signal = f"{SIGNAL_ADD_ENTITIES}_{COVER_DOMAIN}" + signal = f"{SIGNAL_ADD_ENTITIES}_{Platform.COVER}" async_dispatcher_connect(hass, signal, async_add_insteon_cover_entities) async_add_insteon_cover_entities() diff --git a/homeassistant/components/insteon/fan.py b/homeassistant/components/insteon/fan.py index c7512ba0278..b0d664a821b 100644 --- a/homeassistant/components/insteon/fan.py +++ b/homeassistant/components/insteon/fan.py @@ -4,12 +4,9 @@ from __future__ import annotations import math from typing import Any -from homeassistant.components.fan import ( - DOMAIN as FAN_DOMAIN, - FanEntity, - FanEntityFeature, -) +from homeassistant.components.fan import FanEntity, FanEntityFeature 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 @@ -36,10 +33,10 @@ async def async_setup_entry( def async_add_insteon_fan_entities(discovery_info=None): """Add the Insteon entities for the platform.""" async_add_insteon_entities( - hass, FAN_DOMAIN, InsteonFanEntity, async_add_entities, discovery_info + hass, Platform.FAN, InsteonFanEntity, async_add_entities, discovery_info ) - signal = f"{SIGNAL_ADD_ENTITIES}_{FAN_DOMAIN}" + signal = f"{SIGNAL_ADD_ENTITIES}_{Platform.FAN}" async_dispatcher_connect(hass, signal, async_add_insteon_fan_entities) async_add_insteon_fan_entities() diff --git a/homeassistant/components/insteon/ipdb.py b/homeassistant/components/insteon/ipdb.py index fea1262bffd..ee799e103f9 100644 --- a/homeassistant/components/insteon/ipdb.py +++ b/homeassistant/components/insteon/ipdb.py @@ -17,11 +17,6 @@ from pyinsteon.device_types.ipdb import ( DimmableLightingControl_SwitchLinc02, DimmableLightingControl_ToggleLinc, EnergyManagement_LoadController, - GeneralController_ControlLinc, - GeneralController_MiniRemote_4, - GeneralController_MiniRemote_8, - GeneralController_MiniRemote_Switch, - GeneralController_RemoteLinc, SecurityHealthSafety_DoorSensor, SecurityHealthSafety_LeakSensor, SecurityHealthSafety_MotionSensor, @@ -47,76 +42,62 @@ from pyinsteon.device_types.ipdb import ( X10OnOffSensor, ) -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.fan import DOMAIN as FAN -from homeassistant.components.light import DOMAIN as LIGHT -from homeassistant.components.lock import DOMAIN as LOCK -from homeassistant.components.switch import DOMAIN as SWITCH - -from .const import ON_OFF_EVENTS +from homeassistant.const import Platform DEVICE_PLATFORM = { - AccessControl_Morningstar: {LOCK: [1]}, - DimmableLightingControl: {LIGHT: [1], ON_OFF_EVENTS: [1]}, - DimmableLightingControl_Dial: {LIGHT: [1], ON_OFF_EVENTS: [1]}, - DimmableLightingControl_DinRail: {LIGHT: [1], ON_OFF_EVENTS: [1]}, - DimmableLightingControl_FanLinc: {LIGHT: [1], FAN: [2], ON_OFF_EVENTS: [1, 2]}, - DimmableLightingControl_InLineLinc01: {LIGHT: [1], ON_OFF_EVENTS: [1]}, - DimmableLightingControl_InLineLinc02: {LIGHT: [1], ON_OFF_EVENTS: [1]}, + AccessControl_Morningstar: {Platform.LOCK: [1]}, + DimmableLightingControl: {Platform.LIGHT: [1]}, + DimmableLightingControl_Dial: {Platform.LIGHT: [1]}, + DimmableLightingControl_DinRail: {Platform.LIGHT: [1]}, + DimmableLightingControl_FanLinc: {Platform.LIGHT: [1], Platform.FAN: [2]}, + DimmableLightingControl_InLineLinc01: {Platform.LIGHT: [1]}, + DimmableLightingControl_InLineLinc02: {Platform.LIGHT: [1]}, DimmableLightingControl_KeypadLinc_6: { - LIGHT: [1], - SWITCH: [3, 4, 5, 6], - ON_OFF_EVENTS: [1, 3, 4, 5, 6], + Platform.LIGHT: [1], + Platform.SWITCH: [3, 4, 5, 6], }, DimmableLightingControl_KeypadLinc_8: { - LIGHT: [1], - SWITCH: range(2, 9), - ON_OFF_EVENTS: range(1, 9), + Platform.LIGHT: [1], + Platform.SWITCH: range(2, 9), }, - DimmableLightingControl_LampLinc: {LIGHT: [1], ON_OFF_EVENTS: [1]}, - DimmableLightingControl_OutletLinc: {LIGHT: [1], ON_OFF_EVENTS: [1]}, - DimmableLightingControl_SwitchLinc01: {LIGHT: [1], ON_OFF_EVENTS: [1]}, - DimmableLightingControl_SwitchLinc02: {LIGHT: [1], ON_OFF_EVENTS: [1]}, - DimmableLightingControl_ToggleLinc: {LIGHT: [1], ON_OFF_EVENTS: [1]}, - EnergyManagement_LoadController: {SWITCH: [1], BINARY_SENSOR: [2]}, - GeneralController_ControlLinc: {ON_OFF_EVENTS: [1]}, - GeneralController_MiniRemote_4: {ON_OFF_EVENTS: range(1, 5)}, - GeneralController_MiniRemote_8: {ON_OFF_EVENTS: range(1, 9)}, - GeneralController_MiniRemote_Switch: {ON_OFF_EVENTS: [1, 2]}, - GeneralController_RemoteLinc: {ON_OFF_EVENTS: [1]}, - SecurityHealthSafety_DoorSensor: {BINARY_SENSOR: [1, 3, 4], ON_OFF_EVENTS: [1]}, - SecurityHealthSafety_LeakSensor: {BINARY_SENSOR: [2, 4]}, - SecurityHealthSafety_MotionSensor: {BINARY_SENSOR: [1, 2, 3], ON_OFF_EVENTS: [1]}, - SecurityHealthSafety_OpenCloseSensor: {BINARY_SENSOR: [1]}, - SecurityHealthSafety_Smokebridge: {BINARY_SENSOR: [1, 2, 3, 4, 6, 7]}, - SensorsActuators_IOLink: {SWITCH: [1], BINARY_SENSOR: [2], ON_OFF_EVENTS: [1, 2]}, - SwitchedLightingControl: {SWITCH: [1], ON_OFF_EVENTS: [1]}, - SwitchedLightingControl_ApplianceLinc: {SWITCH: [1], ON_OFF_EVENTS: [1]}, - SwitchedLightingControl_DinRail: {SWITCH: [1], ON_OFF_EVENTS: [1]}, - SwitchedLightingControl_I3Outlet: {SWITCH: [1, 2], ON_OFF_EVENTS: [1, 2]}, - SwitchedLightingControl_InLineLinc01: {SWITCH: [1], ON_OFF_EVENTS: [1]}, - SwitchedLightingControl_InLineLinc02: {SWITCH: [1], ON_OFF_EVENTS: [1]}, + DimmableLightingControl_LampLinc: {Platform.LIGHT: [1]}, + DimmableLightingControl_OutletLinc: {Platform.LIGHT: [1]}, + DimmableLightingControl_SwitchLinc01: {Platform.LIGHT: [1]}, + DimmableLightingControl_SwitchLinc02: {Platform.LIGHT: [1]}, + DimmableLightingControl_ToggleLinc: {Platform.LIGHT: [1]}, + EnergyManagement_LoadController: { + Platform.SWITCH: [1], + Platform.BINARY_SENSOR: [2], + }, + SecurityHealthSafety_DoorSensor: {Platform.BINARY_SENSOR: [1, 3, 4]}, + SecurityHealthSafety_LeakSensor: {Platform.BINARY_SENSOR: [2, 4]}, + SecurityHealthSafety_MotionSensor: {Platform.BINARY_SENSOR: [1, 2, 3]}, + SecurityHealthSafety_OpenCloseSensor: {Platform.BINARY_SENSOR: [1]}, + SecurityHealthSafety_Smokebridge: {Platform.BINARY_SENSOR: [1, 2, 3, 4, 6, 7]}, + SensorsActuators_IOLink: {Platform.SWITCH: [1], Platform.BINARY_SENSOR: [2]}, + SwitchedLightingControl: {Platform.SWITCH: [1]}, + SwitchedLightingControl_ApplianceLinc: {Platform.SWITCH: [1]}, + SwitchedLightingControl_DinRail: {Platform.SWITCH: [1]}, + SwitchedLightingControl_I3Outlet: {Platform.SWITCH: [1, 2]}, + SwitchedLightingControl_InLineLinc01: {Platform.SWITCH: [1]}, + SwitchedLightingControl_InLineLinc02: {Platform.SWITCH: [1]}, SwitchedLightingControl_KeypadLinc_6: { - SWITCH: [1, 3, 4, 5, 6], - ON_OFF_EVENTS: [1, 3, 4, 5, 6], + Platform.SWITCH: [1, 3, 4, 5, 6], }, SwitchedLightingControl_KeypadLinc_8: { - SWITCH: range(1, 9), - ON_OFF_EVENTS: range(1, 9), + Platform.SWITCH: range(1, 9), }, - SwitchedLightingControl_OnOffOutlet: {SWITCH: [1, 2], ON_OFF_EVENTS: [1, 2]}, - SwitchedLightingControl_OutletLinc: {SWITCH: [1], ON_OFF_EVENTS: [1]}, - SwitchedLightingControl_SwitchLinc01: {SWITCH: [1], ON_OFF_EVENTS: [1]}, - SwitchedLightingControl_SwitchLinc02: {SWITCH: [1], ON_OFF_EVENTS: [1]}, - SwitchedLightingControl_ToggleLinc: {SWITCH: [1], ON_OFF_EVENTS: [1]}, - ClimateControl_Thermostat: {CLIMATE: [1]}, - ClimateControl_WirelessThermostat: {CLIMATE: [1]}, - WindowCovering: {COVER: [1]}, - X10Dimmable: {LIGHT: [1]}, - X10OnOff: {SWITCH: [1]}, - X10OnOffSensor: {BINARY_SENSOR: [1]}, + SwitchedLightingControl_OnOffOutlet: {Platform.SWITCH: [1, 2]}, + SwitchedLightingControl_OutletLinc: {Platform.SWITCH: [1]}, + SwitchedLightingControl_SwitchLinc01: {Platform.SWITCH: [1]}, + SwitchedLightingControl_SwitchLinc02: {Platform.SWITCH: [1]}, + SwitchedLightingControl_ToggleLinc: {Platform.SWITCH: [1]}, + ClimateControl_Thermostat: {Platform.CLIMATE: [1]}, + ClimateControl_WirelessThermostat: {Platform.CLIMATE: [1]}, + WindowCovering: {Platform.COVER: [1]}, + X10Dimmable: {Platform.LIGHT: [1]}, + X10OnOff: {Platform.SWITCH: [1]}, + X10OnOffSensor: {Platform.BINARY_SENSOR: [1]}, } diff --git a/homeassistant/components/insteon/light.py b/homeassistant/components/insteon/light.py index 579945e6f82..44574c696b4 100644 --- a/homeassistant/components/insteon/light.py +++ b/homeassistant/components/insteon/light.py @@ -3,13 +3,9 @@ from typing import Any from pyinsteon.config import ON_LEVEL -from homeassistant.components.light import ( - ATTR_BRIGHTNESS, - DOMAIN as LIGHT_DOMAIN, - ColorMode, - LightEntity, -) +from homeassistant.components.light import ATTR_BRIGHTNESS, ColorMode, LightEntity 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 @@ -32,10 +28,14 @@ async def async_setup_entry( def async_add_insteon_light_entities(discovery_info=None): """Add the Insteon entities for the platform.""" async_add_insteon_entities( - hass, LIGHT_DOMAIN, InsteonDimmerEntity, async_add_entities, discovery_info + hass, + Platform.LIGHT, + InsteonDimmerEntity, + async_add_entities, + discovery_info, ) - signal = f"{SIGNAL_ADD_ENTITIES}_{LIGHT_DOMAIN}" + signal = f"{SIGNAL_ADD_ENTITIES}_{Platform.LIGHT}" async_dispatcher_connect(hass, signal, async_add_insteon_light_entities) async_add_insteon_light_entities() diff --git a/homeassistant/components/insteon/lock.py b/homeassistant/components/insteon/lock.py index 17a7cf20111..75487e7696c 100644 --- a/homeassistant/components/insteon/lock.py +++ b/homeassistant/components/insteon/lock.py @@ -2,8 +2,9 @@ from typing import Any -from homeassistant.components.lock import DOMAIN as LOCK_DOMAIN, LockEntity +from homeassistant.components.lock import LockEntity 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 @@ -24,10 +25,10 @@ async def async_setup_entry( def async_add_insteon_lock_entities(discovery_info=None): """Add the Insteon entities for the platform.""" async_add_insteon_entities( - hass, LOCK_DOMAIN, InsteonLockEntity, async_add_entities, discovery_info + hass, Platform.LOCK, InsteonLockEntity, async_add_entities, discovery_info ) - signal = f"{SIGNAL_ADD_ENTITIES}_{LOCK_DOMAIN}" + signal = f"{SIGNAL_ADD_ENTITIES}_{Platform.LOCK}" async_dispatcher_connect(hass, signal, async_add_insteon_lock_entities) async_add_insteon_lock_entities() diff --git a/homeassistant/components/insteon/switch.py b/homeassistant/components/insteon/switch.py index d9a15d383c0..8f7c396f213 100644 --- a/homeassistant/components/insteon/switch.py +++ b/homeassistant/components/insteon/switch.py @@ -1,8 +1,9 @@ """Support for INSTEON dimmers via PowerLinc Modem.""" from typing import Any -from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN, SwitchEntity +from homeassistant.components.switch import SwitchEntity 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 @@ -23,10 +24,14 @@ async def async_setup_entry( def async_add_insteon_switch_entities(discovery_info=None): """Add the Insteon entities for the platform.""" async_add_insteon_entities( - hass, SWITCH_DOMAIN, InsteonSwitchEntity, async_add_entities, discovery_info + hass, + Platform.SWITCH, + InsteonSwitchEntity, + async_add_entities, + discovery_info, ) - signal = f"{SIGNAL_ADD_ENTITIES}_{SWITCH_DOMAIN}" + signal = f"{SIGNAL_ADD_ENTITIES}_{Platform.SWITCH}" async_dispatcher_connect(hass, signal, async_add_insteon_switch_entities) async_add_insteon_switch_entities() diff --git a/homeassistant/components/insteon/utils.py b/homeassistant/components/insteon/utils.py index 0df823e49b1..8915342d2e1 100644 --- a/homeassistant/components/insteon/utils.py +++ b/homeassistant/components/insteon/utils.py @@ -49,7 +49,6 @@ from .const import ( EVENT_GROUP_OFF_FAST, EVENT_GROUP_ON, EVENT_GROUP_ON_FAST, - ON_OFF_EVENTS, SIGNAL_ADD_DEFAULT_LINKS, SIGNAL_ADD_DEVICE_OVERRIDE, SIGNAL_ADD_ENTITIES, @@ -102,8 +101,8 @@ def _register_event(event: Event, listener: Callable) -> None: event.subscribe(listener, force_strong_ref=True) -def add_on_off_event_device(hass: HomeAssistant, device: Device) -> None: - """Register an Insteon device as an on/off event device.""" +def add_insteon_events(hass: HomeAssistant, device: Device) -> None: + """Register Insteon device events.""" @callback def async_fire_group_on_off_event( @@ -157,12 +156,8 @@ def register_new_device_callback(hass): await device.async_status() platforms = get_device_platforms(device) for platform in platforms: - if platform == ON_OFF_EVENTS: - add_on_off_event_device(hass, device) - - else: - signal = f"{SIGNAL_ADD_ENTITIES}_{platform}" - dispatcher_send(hass, signal, {"address": device.address}) + signal = f"{SIGNAL_ADD_ENTITIES}_{platform}" + dispatcher_send(hass, signal, {"address": device.address}) devices.subscribe(async_new_insteon_device, force_strong_ref=True)