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
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.helpers import config_validation as cv
from homeassistant.helpers.dispatcher import async_dispatcher_send
from .const import DOMAIN
# Mapping from Wemo model_name to component.
# Mapping from Wemo model_name to domain.
WEMO_MODEL_DISPATCH = {
"Bridge": "light",
"CoffeeMaker": "switch",
"Dimmer": "light",
"Humidifier": "fan",
"Insight": "switch",
"LightSwitch": "switch",
"Maker": "switch",
"Motion": "binary_sensor",
"Sensor": "binary_sensor",
"Socket": "switch",
"Bridge": LIGHT_DOMAIN,
"CoffeeMaker": SWITCH_DOMAIN,
"Dimmer": LIGHT_DOMAIN,
"Humidifier": FAN_DOMAIN,
"Insight": SWITCH_DOMAIN,
"LightSwitch": SWITCH_DOMAIN,
"Maker": SWITCH_DOMAIN,
"Motion": BINARY_SENSOR_DOMAIN,
"Sensor": BINARY_SENSOR_DOMAIN,
"Socket": SWITCH_DOMAIN,
}
_LOGGER = logging.getLogger(__name__)
@ -135,7 +139,7 @@ async def async_setup_entry(hass, entry):
device.serialnumber,
)
component = WEMO_MODEL_DISPATCH.get(device.model_name, "switch")
component = WEMO_MODEL_DISPATCH.get(device.model_name, SWITCH_DOMAIN)
# Three cases:
# - First time we see component, we need to load it and initialize the backlog