Use the Platform enum in wemo (#62153)

pull/62363/head
Eric Severance 2021-12-19 21:11:40 -08:00 committed by GitHub
parent 70947b14a3
commit f50dc10276
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 22 additions and 30 deletions

View File

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

View File

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

View File

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

View File

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

View File

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