1 """Support for Ankuoo RecSwitch MS6126 devices."""
3 from __future__
import annotations
8 from pyrecswitch
import RSNetwork, RSNetworkError
9 import voluptuous
as vol
12 PLATFORM_SCHEMA
as SWITCH_PLATFORM_SCHEMA,
21 _LOGGER = logging.getLogger(__name__)
23 DEFAULT_NAME =
"RecSwitch {0}"
27 PLATFORM_SCHEMA = SWITCH_PLATFORM_SCHEMA.extend(
29 vol.Required(CONF_HOST): cv.string,
30 vol.Required(CONF_MAC): vol.All(cv.string, vol.Upper),
31 vol.Optional(CONF_NAME): cv.string,
39 async_add_entities: AddEntitiesCallback,
40 discovery_info: DiscoveryInfoType |
None =
None,
42 """Set up the device."""
44 host = config[CONF_HOST]
45 mac_address = config[CONF_MAC]
46 device_name = config.get(CONF_NAME)
48 if not hass.data.get(DATA_RSN):
49 hass.data[DATA_RSN] = RSNetwork()
50 job = hass.data[DATA_RSN].create_datagram_endpoint()
51 hass.async_create_task(job)
58 """Representation of a recswitch device."""
60 def __init__(self, device, device_name, mac_address):
61 """Initialize a recswitch device."""
71 """Return the switch unique ID."""
76 """Return the switch name."""
81 """Return true if switch is on."""
85 """Turn on the switch."""
89 """Turn off the switch."""
93 """Set the switch status."""
96 ret = await self.
devicedevice.set_gpio_status(status)
98 except RSNetworkError
as error:
99 _LOGGER.error(
"Setting status to %s: %r", self.
namenamename, error)
102 """Update the current switch status."""
105 ret = await self.
devicedevice.get_gpio_status()
107 except RSNetworkError
as error:
108 _LOGGER.error(
"Reading status from %s: %r", self.
namenamename, error)
def __init__(self, device, device_name, mac_address)
None async_turn_on(self, **Any kwargs)
def async_set_gpio_status(self, status)
None async_turn_off(self, **Any kwargs)
str|UndefinedType|None name(self)
def register_device(hass, api_key, name, device_id, device_ids, device_names)
None async_setup_platform(HomeAssistant hass, ConfigType config, AddEntitiesCallback async_add_entities, DiscoveryInfoType|None discovery_info=None)