Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """Support for EufyHome devices."""
2 
3 import lakeside
4 import voluptuous as vol
5 
6 from homeassistant.const import (
7  CONF_ACCESS_TOKEN,
8  CONF_ADDRESS,
9  CONF_DEVICES,
10  CONF_NAME,
11  CONF_PASSWORD,
12  CONF_TYPE,
13  CONF_USERNAME,
14  Platform,
15 )
16 from homeassistant.core import HomeAssistant
17 from homeassistant.helpers import discovery
19 from homeassistant.helpers.typing import ConfigType
20 
21 DOMAIN = "eufy"
22 
23 DEVICE_SCHEMA = vol.Schema(
24  {
25  vol.Required(CONF_ADDRESS): cv.string,
26  vol.Required(CONF_ACCESS_TOKEN): cv.string,
27  vol.Required(CONF_TYPE): cv.string,
28  vol.Optional(CONF_NAME): cv.string,
29  }
30 )
31 
32 CONFIG_SCHEMA = vol.Schema(
33  {
34  DOMAIN: vol.Schema(
35  {
36  vol.Optional(CONF_DEVICES, default=[]): vol.All(
37  cv.ensure_list, [DEVICE_SCHEMA]
38  ),
39  vol.Inclusive(CONF_USERNAME, "authentication"): cv.string,
40  vol.Inclusive(CONF_PASSWORD, "authentication"): cv.string,
41  }
42  )
43  },
44  extra=vol.ALLOW_EXTRA,
45 )
46 
47 PLATFORMS = {
48  "T1011": Platform.LIGHT,
49  "T1012": Platform.LIGHT,
50  "T1013": Platform.LIGHT,
51  "T1201": Platform.SWITCH,
52  "T1202": Platform.SWITCH,
53  "T1203": Platform.SWITCH,
54  "T1211": Platform.SWITCH,
55 }
56 
57 
58 def setup(hass: HomeAssistant, config: ConfigType) -> bool:
59  """Set up EufyHome devices."""
60 
61  if CONF_USERNAME in config[DOMAIN] and CONF_PASSWORD in config[DOMAIN]:
62  data = lakeside.get_devices(
63  config[DOMAIN][CONF_USERNAME], config[DOMAIN][CONF_PASSWORD]
64  )
65  for device in data:
66  kind = device["type"]
67  if kind not in PLATFORMS:
68  continue
69  discovery.load_platform(hass, PLATFORMS[kind], DOMAIN, device, config)
70 
71  for device_info in config[DOMAIN][CONF_DEVICES]:
72  kind = device_info["type"]
73  if kind not in PLATFORMS:
74  continue
75  device = {}
76  device["address"] = device_info["address"]
77  device["code"] = device_info["access_token"]
78  device["type"] = device_info["type"]
79  device["name"] = device_info["name"]
80  discovery.load_platform(hass, PLATFORMS[kind], DOMAIN, device, config)
81 
82  return True
bool setup(HomeAssistant hass, ConfigType config)
Definition: __init__.py:58