Replace hard-coded domain strings with constants in the Wemo module (#44222)

This commit is contained in:
Eric Severance 2020-12-14 20:03:02 -08:00 committed by GitHub
parent 1003464544
commit d4ab7880af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,24 +7,28 @@ import requests
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.switch import DOMAIN as SWITCH_DOMAIN
from homeassistant.const import EVENT_HOMEASSISTANT_STOP from homeassistant.const import EVENT_HOMEASSISTANT_STOP
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
from .const import DOMAIN from .const import DOMAIN
# Mapping from Wemo model_name to component. # Mapping from Wemo model_name to domain.
WEMO_MODEL_DISPATCH = { WEMO_MODEL_DISPATCH = {
"Bridge": "light", "Bridge": LIGHT_DOMAIN,
"CoffeeMaker": "switch", "CoffeeMaker": SWITCH_DOMAIN,
"Dimmer": "light", "Dimmer": LIGHT_DOMAIN,
"Humidifier": "fan", "Humidifier": FAN_DOMAIN,
"Insight": "switch", "Insight": SWITCH_DOMAIN,
"LightSwitch": "switch", "LightSwitch": SWITCH_DOMAIN,
"Maker": "switch", "Maker": SWITCH_DOMAIN,
"Motion": "binary_sensor", "Motion": BINARY_SENSOR_DOMAIN,
"Sensor": "binary_sensor", "Sensor": BINARY_SENSOR_DOMAIN,
"Socket": "switch", "Socket": SWITCH_DOMAIN,
} }
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -135,7 +139,7 @@ async def async_setup_entry(hass, entry):
device.serialnumber, device.serialnumber,
) )
component = WEMO_MODEL_DISPATCH.get(device.model_name, "switch") component = WEMO_MODEL_DISPATCH.get(device.model_name, SWITCH_DOMAIN)
# 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