Cleanup Insteon to use Platform vs DOMAIN constants (#92366)

* Utilize Platform constant

* Use Platform constant
This commit is contained in:
Tom Harris 2023-05-05 15:32:51 -04:00 committed by GitHub
parent 2b3f7ad70d
commit bdd786b1f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 86 additions and 110 deletions

View File

@ -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))

View File

@ -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()

View File

@ -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()

View File

@ -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",

View File

@ -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()

View File

@ -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()

View File

@ -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]},
}

View File

@ -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()

View File

@ -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()

View File

@ -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()

View File

@ -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)