mirror of https://github.com/home-assistant/core
Add Insteon entities in event loop (#45829)
This commit is contained in:
parent
0feda9ce63
commit
b3e2f8f904
|
@ -27,6 +27,7 @@ from homeassistant.components.binary_sensor import (
|
|||
DOMAIN as BINARY_SENSOR_DOMAIN,
|
||||
BinarySensorEntity,
|
||||
)
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
|
||||
from .const import SIGNAL_ADD_ENTITIES
|
||||
|
@ -51,7 +52,8 @@ SENSOR_TYPES = {
|
|||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
"""Set up the Insteon binary sensors from a config entry."""
|
||||
|
||||
def add_entities(discovery_info=None):
|
||||
@callback
|
||||
def async_add_insteon_binary_sensor_entities(discovery_info=None):
|
||||
"""Add the Insteon entities for the platform."""
|
||||
async_add_insteon_entities(
|
||||
hass,
|
||||
|
@ -62,8 +64,8 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||
)
|
||||
|
||||
signal = f"{SIGNAL_ADD_ENTITIES}_{BINARY_SENSOR_DOMAIN}"
|
||||
async_dispatcher_connect(hass, signal, add_entities)
|
||||
add_entities()
|
||||
async_dispatcher_connect(hass, signal, async_add_insteon_binary_sensor_entities)
|
||||
async_add_insteon_binary_sensor_entities()
|
||||
|
||||
|
||||
class InsteonBinarySensorEntity(InsteonEntity, BinarySensorEntity):
|
||||
|
|
|
@ -25,6 +25,7 @@ from homeassistant.components.climate.const import (
|
|||
SUPPORT_TARGET_TEMPERATURE_RANGE,
|
||||
)
|
||||
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS, TEMP_FAHRENHEIT
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
|
||||
from .const import SIGNAL_ADD_ENTITIES
|
||||
|
@ -64,7 +65,8 @@ SUPPORTED_FEATURES = (
|
|||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
"""Set up the Insteon climate entities from a config entry."""
|
||||
|
||||
def add_entities(discovery_info=None):
|
||||
@callback
|
||||
def async_add_insteon_climate_entities(discovery_info=None):
|
||||
"""Add the Insteon entities for the platform."""
|
||||
async_add_insteon_entities(
|
||||
hass,
|
||||
|
@ -75,8 +77,8 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||
)
|
||||
|
||||
signal = f"{SIGNAL_ADD_ENTITIES}_{CLIMATE_DOMAIN}"
|
||||
async_dispatcher_connect(hass, signal, add_entities)
|
||||
add_entities()
|
||||
async_dispatcher_connect(hass, signal, async_add_insteon_climate_entities)
|
||||
async_add_insteon_climate_entities()
|
||||
|
||||
|
||||
class InsteonClimateEntity(InsteonEntity, ClimateEntity):
|
||||
|
|
|
@ -9,6 +9,7 @@ from homeassistant.components.cover import (
|
|||
SUPPORT_SET_POSITION,
|
||||
CoverEntity,
|
||||
)
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
|
||||
from .const import SIGNAL_ADD_ENTITIES
|
||||
|
@ -21,15 +22,16 @@ SUPPORTED_FEATURES = SUPPORT_OPEN | SUPPORT_CLOSE | SUPPORT_SET_POSITION
|
|||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
"""Set up the Insteon covers from a config entry."""
|
||||
|
||||
def add_entities(discovery_info=None):
|
||||
@callback
|
||||
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
|
||||
)
|
||||
|
||||
signal = f"{SIGNAL_ADD_ENTITIES}_{COVER_DOMAIN}"
|
||||
async_dispatcher_connect(hass, signal, add_entities)
|
||||
add_entities()
|
||||
async_dispatcher_connect(hass, signal, async_add_insteon_cover_entities)
|
||||
async_add_insteon_cover_entities()
|
||||
|
||||
|
||||
class InsteonCoverEntity(InsteonEntity, CoverEntity):
|
||||
|
|
|
@ -8,6 +8,7 @@ from homeassistant.components.fan import (
|
|||
SUPPORT_SET_SPEED,
|
||||
FanEntity,
|
||||
)
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
from homeassistant.util.percentage import (
|
||||
percentage_to_ranged_value,
|
||||
|
@ -24,15 +25,16 @@ SPEED_RANGE = (1, FanSpeed.HIGH) # off is not included
|
|||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
"""Set up the Insteon fans from a config entry."""
|
||||
|
||||
def add_entities(discovery_info=None):
|
||||
@callback
|
||||
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
|
||||
)
|
||||
|
||||
signal = f"{SIGNAL_ADD_ENTITIES}_{FAN_DOMAIN}"
|
||||
async_dispatcher_connect(hass, signal, add_entities)
|
||||
add_entities()
|
||||
async_dispatcher_connect(hass, signal, async_add_insteon_fan_entities)
|
||||
async_add_insteon_fan_entities()
|
||||
|
||||
|
||||
class InsteonFanEntity(InsteonEntity, FanEntity):
|
||||
|
|
|
@ -6,6 +6,7 @@ from homeassistant.components.light import (
|
|||
SUPPORT_BRIGHTNESS,
|
||||
LightEntity,
|
||||
)
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
|
||||
from .const import SIGNAL_ADD_ENTITIES
|
||||
|
@ -18,15 +19,16 @@ MAX_BRIGHTNESS = 255
|
|||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
"""Set up the Insteon lights from a config entry."""
|
||||
|
||||
def add_entities(discovery_info=None):
|
||||
@callback
|
||||
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
|
||||
)
|
||||
|
||||
signal = f"{SIGNAL_ADD_ENTITIES}_{LIGHT_DOMAIN}"
|
||||
async_dispatcher_connect(hass, signal, add_entities)
|
||||
add_entities()
|
||||
async_dispatcher_connect(hass, signal, async_add_insteon_light_entities)
|
||||
async_add_insteon_light_entities()
|
||||
|
||||
|
||||
class InsteonDimmerEntity(InsteonEntity, LightEntity):
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
"""Support for INSTEON dimmers via PowerLinc Modem."""
|
||||
from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN, SwitchEntity
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
|
||||
from .const import SIGNAL_ADD_ENTITIES
|
||||
|
@ -10,15 +11,16 @@ from .utils import async_add_insteon_entities
|
|||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
"""Set up the Insteon switches from a config entry."""
|
||||
|
||||
def add_entities(discovery_info=None):
|
||||
@callback
|
||||
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
|
||||
)
|
||||
|
||||
signal = f"{SIGNAL_ADD_ENTITIES}_{SWITCH_DOMAIN}"
|
||||
async_dispatcher_connect(hass, signal, add_entities)
|
||||
add_entities()
|
||||
async_dispatcher_connect(hass, signal, async_add_insteon_switch_entities)
|
||||
async_add_insteon_switch_entities()
|
||||
|
||||
|
||||
class InsteonSwitchEntity(InsteonEntity, SwitchEntity):
|
||||
|
|
Loading…
Reference in New Issue