core/homeassistant/components/eufy/__init__.py

83 lines
2.1 KiB
Python
Raw Normal View History

"""Support for Eufy devices."""
import logging
import lakeside
import voluptuous as vol
from homeassistant.const import (
2019-07-31 19:25:30 +00:00
CONF_ACCESS_TOKEN,
CONF_ADDRESS,
CONF_DEVICES,
CONF_NAME,
CONF_PASSWORD,
CONF_TYPE,
CONF_USERNAME,
)
from homeassistant.helpers import discovery
import homeassistant.helpers.config_validation as cv
_LOGGER = logging.getLogger(__name__)
2019-07-31 19:25:30 +00:00
DOMAIN = "eufy"
2019-07-31 19:25:30 +00:00
DEVICE_SCHEMA = vol.Schema(
{
vol.Required(CONF_ADDRESS): cv.string,
vol.Required(CONF_ACCESS_TOKEN): cv.string,
vol.Required(CONF_TYPE): cv.string,
vol.Optional(CONF_NAME): cv.string,
}
)
2019-07-31 19:25:30 +00:00
CONFIG_SCHEMA = vol.Schema(
{
DOMAIN: vol.Schema(
{
vol.Optional(CONF_DEVICES, default=[]): vol.All(
cv.ensure_list, [DEVICE_SCHEMA]
),
vol.Inclusive(CONF_USERNAME, "authentication"): cv.string,
vol.Inclusive(CONF_PASSWORD, "authentication"): cv.string,
}
)
},
extra=vol.ALLOW_EXTRA,
)
EUFY_DISPATCH = {
2019-07-31 19:25:30 +00:00
"T1011": "light",
"T1012": "light",
"T1013": "light",
"T1201": "switch",
"T1202": "switch",
"T1203": "switch",
"T1211": "switch",
}
def setup(hass, config):
"""Set up Eufy devices."""
if CONF_USERNAME in config[DOMAIN] and CONF_PASSWORD in config[DOMAIN]:
2019-07-31 19:25:30 +00:00
data = lakeside.get_devices(
config[DOMAIN][CONF_USERNAME], config[DOMAIN][CONF_PASSWORD]
)
for device in data:
2019-07-31 19:25:30 +00:00
kind = device["type"]
if kind not in EUFY_DISPATCH:
continue
2019-07-31 19:25:30 +00:00
discovery.load_platform(hass, EUFY_DISPATCH[kind], DOMAIN, device, config)
for device_info in config[DOMAIN][CONF_DEVICES]:
2019-07-31 19:25:30 +00:00
kind = device_info["type"]
if kind not in EUFY_DISPATCH:
continue
device = {}
2019-07-31 19:25:30 +00:00
device["address"] = device_info["address"]
device["code"] = device_info["access_token"]
device["type"] = device_info["type"]
device["name"] = device_info["name"]
discovery.load_platform(hass, EUFY_DISPATCH[kind], DOMAIN, device, config)
return True