Use the Platform enum in wemo (#62153)
parent
70947b14a3
commit
f50dc10276
|
@ -9,13 +9,8 @@ import pywemo
|
|||
import voluptuous as vol
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components.binary_sensor import DOMAIN as BINARY_SENSOR_DOMAIN
|
||||
from homeassistant.components.fan import DOMAIN as FAN_DOMAIN
|
||||
from homeassistant.components.light import DOMAIN as LIGHT_DOMAIN
|
||||
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
|
||||
from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_DISCOVERY, EVENT_HOMEASSISTANT_STOP
|
||||
from homeassistant.const import CONF_DISCOVERY, EVENT_HOMEASSISTANT_STOP, Platform
|
||||
from homeassistant.core import CALLBACK_TYPE, Event, HomeAssistant, callback
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
||||
|
@ -32,17 +27,17 @@ MAX_CONCURRENCY = 3
|
|||
|
||||
# Mapping from Wemo model_name to domain.
|
||||
WEMO_MODEL_DISPATCH = {
|
||||
"Bridge": [LIGHT_DOMAIN],
|
||||
"CoffeeMaker": [SWITCH_DOMAIN],
|
||||
"Dimmer": [LIGHT_DOMAIN],
|
||||
"Humidifier": [FAN_DOMAIN],
|
||||
"Insight": [BINARY_SENSOR_DOMAIN, SENSOR_DOMAIN, SWITCH_DOMAIN],
|
||||
"LightSwitch": [SWITCH_DOMAIN],
|
||||
"Maker": [BINARY_SENSOR_DOMAIN, SWITCH_DOMAIN],
|
||||
"Motion": [BINARY_SENSOR_DOMAIN],
|
||||
"OutdoorPlug": [SWITCH_DOMAIN],
|
||||
"Sensor": [BINARY_SENSOR_DOMAIN],
|
||||
"Socket": [SWITCH_DOMAIN],
|
||||
"Bridge": [Platform.LIGHT],
|
||||
"CoffeeMaker": [Platform.SWITCH],
|
||||
"Dimmer": [Platform.LIGHT],
|
||||
"Humidifier": [Platform.FAN],
|
||||
"Insight": [Platform.BINARY_SENSOR, Platform.SENSOR, Platform.SWITCH],
|
||||
"LightSwitch": [Platform.SWITCH],
|
||||
"Maker": [Platform.BINARY_SENSOR, Platform.SWITCH],
|
||||
"Motion": [Platform.BINARY_SENSOR],
|
||||
"OutdoorPlug": [Platform.SWITCH],
|
||||
"Sensor": [Platform.BINARY_SENSOR],
|
||||
"Socket": [Platform.SWITCH],
|
||||
}
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
@ -155,7 +150,7 @@ class WemoDispatcher:
|
|||
return
|
||||
|
||||
coordinator = await async_register_device(hass, self._config_entry, wemo)
|
||||
for component in WEMO_MODEL_DISPATCH.get(wemo.model_name, [SWITCH_DOMAIN]):
|
||||
for component in WEMO_MODEL_DISPATCH.get(wemo.model_name, [Platform.SWITCH]):
|
||||
# Three cases:
|
||||
# - First time we see component, we need to load it and initialize the backlog
|
||||
# - Component is being loaded, add to backlog
|
||||
|
|
|
@ -3,14 +3,13 @@
|
|||
import pytest
|
||||
from pywemo.exceptions import ActionException
|
||||
|
||||
from homeassistant.components.fan import DOMAIN as FAN_DOMAIN
|
||||
from homeassistant.components.homeassistant import (
|
||||
DOMAIN as HA_DOMAIN,
|
||||
SERVICE_UPDATE_ENTITY,
|
||||
)
|
||||
from homeassistant.components.wemo import fan
|
||||
from homeassistant.components.wemo.const import DOMAIN
|
||||
from homeassistant.const import ATTR_ENTITY_ID, STATE_OFF, STATE_ON
|
||||
from homeassistant.const import ATTR_ENTITY_ID, STATE_OFF, STATE_ON, Platform
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from . import entity_test_helpers
|
||||
|
@ -85,7 +84,7 @@ async def test_available_after_update(
|
|||
pywemo_device.set_state.side_effect = ActionException
|
||||
pywemo_device.get_state.return_value = 1
|
||||
await entity_test_helpers.test_avaliable_after_update(
|
||||
hass, pywemo_registry, pywemo_device, wemo_entity, FAN_DOMAIN
|
||||
hass, pywemo_registry, pywemo_device, wemo_entity, Platform.FAN
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -8,8 +8,8 @@ from homeassistant.components.homeassistant import (
|
|||
DOMAIN as HA_DOMAIN,
|
||||
SERVICE_UPDATE_ENTITY,
|
||||
)
|
||||
from homeassistant.components.light import ATTR_COLOR_TEMP, DOMAIN as LIGHT_DOMAIN
|
||||
from homeassistant.const import ATTR_ENTITY_ID, STATE_OFF, STATE_ON
|
||||
from homeassistant.components.light import ATTR_COLOR_TEMP
|
||||
from homeassistant.const import ATTR_ENTITY_ID, STATE_OFF, STATE_ON, Platform
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from . import entity_test_helpers
|
||||
|
@ -76,7 +76,7 @@ async def test_available_after_update(
|
|||
pywemo_bridge_light.turn_on.side_effect = pywemo.exceptions.ActionException
|
||||
pywemo_bridge_light.state["onoff"] = 1
|
||||
await entity_test_helpers.test_avaliable_after_update(
|
||||
hass, pywemo_registry, pywemo_device, wemo_entity, LIGHT_DOMAIN
|
||||
hass, pywemo_registry, pywemo_device, wemo_entity, Platform.LIGHT
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -7,8 +7,7 @@ from homeassistant.components.homeassistant import (
|
|||
DOMAIN as HA_DOMAIN,
|
||||
SERVICE_UPDATE_ENTITY,
|
||||
)
|
||||
from homeassistant.components.light import DOMAIN as LIGHT_DOMAIN
|
||||
from homeassistant.const import ATTR_ENTITY_ID, STATE_OFF, STATE_ON
|
||||
from homeassistant.const import ATTR_ENTITY_ID, STATE_OFF, STATE_ON, Platform
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from . import entity_test_helpers
|
||||
|
@ -41,7 +40,7 @@ async def test_available_after_update(
|
|||
pywemo_device.on.side_effect = ActionException
|
||||
pywemo_device.get_state.return_value = 1
|
||||
await entity_test_helpers.test_avaliable_after_update(
|
||||
hass, pywemo_registry, pywemo_device, wemo_entity, LIGHT_DOMAIN
|
||||
hass, pywemo_registry, pywemo_device, wemo_entity, Platform.LIGHT
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -7,8 +7,7 @@ from homeassistant.components.homeassistant import (
|
|||
DOMAIN as HA_DOMAIN,
|
||||
SERVICE_UPDATE_ENTITY,
|
||||
)
|
||||
from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN
|
||||
from homeassistant.const import ATTR_ENTITY_ID, STATE_OFF, STATE_ON
|
||||
from homeassistant.const import ATTR_ENTITY_ID, STATE_OFF, STATE_ON, Platform
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from . import entity_test_helpers
|
||||
|
@ -83,5 +82,5 @@ async def test_available_after_update(
|
|||
pywemo_device.on.side_effect = ActionException
|
||||
pywemo_device.get_state.return_value = 1
|
||||
await entity_test_helpers.test_avaliable_after_update(
|
||||
hass, pywemo_registry, pywemo_device, wemo_entity, SWITCH_DOMAIN
|
||||
hass, pywemo_registry, pywemo_device, wemo_entity, Platform.SWITCH
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue