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