1 """Support for Orvibo S20 Wifi Smart Switches."""
3 from __future__
import annotations
8 from orvibo.s20
import S20, S20Exception, discover
9 import voluptuous
as vol
12 PLATFORM_SCHEMA
as SWITCH_PLATFORM_SCHEMA,
27 _LOGGER = logging.getLogger(__name__)
29 DEFAULT_NAME =
"Orvibo S20 Switch"
30 DEFAULT_DISCOVERY =
True
32 PLATFORM_SCHEMA = SWITCH_PLATFORM_SCHEMA.extend(
34 vol.Required(CONF_SWITCHES, default=[]): vol.All(
38 vol.Required(CONF_HOST): cv.string,
39 vol.Optional(CONF_MAC): cv.string,
40 vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
44 vol.Optional(CONF_DISCOVERY, default=DEFAULT_DISCOVERY): cv.boolean,
52 add_entities_callback: AddEntitiesCallback,
53 discovery_info: DiscoveryInfoType |
None =
None,
55 """Set up S20 switches."""
59 switch_conf = config.get(CONF_SWITCHES, [config])
61 if config.get(CONF_DISCOVERY):
62 _LOGGER.debug(
"Discovering S20 switches")
65 for switch
in switch_conf:
66 switch_data[switch.get(CONF_HOST)] = switch
68 for host, data
in switch_data.items():
71 S20Switch(data.get(CONF_NAME), S20(host, mac=data.get(CONF_MAC)))
73 _LOGGER.debug(
"Initialized S20 at %s", host)
75 _LOGGER.error(
"S20 at %s couldn't be initialized", host)
77 add_entities_callback(switches)
81 """Representation of an S20 switch."""
84 """Initialize the S20 device."""
89 self.
_exc_exc = S20Exception
93 """Return the name of the switch."""
94 return self.
_name_name
98 """Return true if device is on."""
102 """Update device state."""
105 except self.
_exc_exc:
106 _LOGGER.exception(
"Error while fetching S20 state")
109 """Turn the device on."""
111 self.
_s20_s20.on =
True
112 except self.
_exc_exc:
113 _LOGGER.exception(
"Error while turning on S20")
116 """Turn the device off."""
118 self.
_s20_s20.on =
False
119 except self.
_exc_exc:
120 _LOGGER.exception(
"Error while turning off S20")
None turn_off(self, **Any kwargs)
def __init__(self, name, s20)
None turn_on(self, **Any kwargs)
None setup_platform(HomeAssistant hass, ConfigType config, AddEntitiesCallback add_entities_callback, DiscoveryInfoType|None discovery_info=None)
list[tuple[str, int]] discover(HomeAssistant hass)