1 """The myStrom integration."""
3 from __future__
import annotations
8 from pymystrom.bulb
import MyStromBulb
9 from pymystrom.exceptions
import MyStromConnectionError
10 from pymystrom.switch
import MyStromSwitch
17 from .const
import DOMAIN
18 from .models
import MyStromData
20 PLATFORMS_PLUGS = [Platform.SENSOR, Platform.SWITCH]
21 PLATFORMS_BULB = [Platform.LIGHT]
23 _LOGGER = logging.getLogger(__name__)
27 device: MyStromSwitch | MyStromBulb, ip_address: str
30 await device.get_state()
31 except MyStromConnectionError
as err:
32 _LOGGER.error(
"No route to myStrom plug: %s", ip_address)
33 raise ConfigEntryNotReady
from err
37 return MyStromBulb(host, mac)
41 return MyStromSwitch(host)
45 """Set up myStrom from a config entry."""
46 host = entry.data[CONF_HOST]
48 info = await pymystrom.get_device_info(host)
49 except MyStromConnectionError
as err:
50 _LOGGER.error(
"No route to myStrom plug: %s", host)
51 raise ConfigEntryNotReady
from err
53 info.setdefault(
"type", 101)
55 device_type = info[
"type"]
56 if device_type
in [101, 106, 107, 120]:
58 platforms = PLATFORMS_PLUGS
60 elif device_type
in [102, 105]:
63 platforms = PLATFORMS_BULB
65 if device.bulb_type
not in [
"rgblamp",
"strip"]:
67 "Device %s (%s) is not a myStrom bulb nor myStrom LED Strip",
73 _LOGGER.error(
"Unsupported myStrom device type: %s", device_type)
76 hass.data.setdefault(DOMAIN, {})[entry.entry_id] =
MyStromData(
80 await hass.config_entries.async_forward_entry_setups(entry, platforms)
86 """Unload a config entry."""
87 device_type = hass.data[DOMAIN][entry.entry_id].info[
"type"]
89 if device_type
in [101, 106, 107, 120]:
90 platforms.extend(PLATFORMS_PLUGS)
91 elif device_type
in [102, 105]:
92 platforms.extend(PLATFORMS_BULB)
93 if unload_ok := await hass.config_entries.async_unload_platforms(entry, platforms):
94 hass.data[DOMAIN].pop(entry.entry_id)
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
None _async_get_device_state(MyStromSwitch|MyStromBulb device, str ip_address)
MyStromSwitch _get_mystrom_switch(str host)
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)
MyStromBulb _get_mystrom_bulb(str host, str mac)