1 """Switch platform integration for Numato USB GPIO expanders."""
3 from __future__
import annotations
8 from numato_gpio
import NumatoGpioError
21 from .
import CONF_INVERT_LOGIC, CONF_PORTS, DATA_API, DOMAIN
23 _LOGGER = logging.getLogger(__name__)
29 add_entities: AddEntitiesCallback,
30 discovery_info: DiscoveryInfoType |
None =
None,
32 """Set up the configured Numato USB GPIO switch ports."""
33 if discovery_info
is None:
36 api = hass.data[DOMAIN][DATA_API]
38 devices = hass.data[DOMAIN][CONF_DEVICES]
39 for device
in [d
for d
in devices
if CONF_SWITCHES
in d]:
40 device_id = device[CONF_ID]
41 platform = device[CONF_SWITCHES]
42 invert_logic = platform[CONF_INVERT_LOGIC]
43 ports = platform[CONF_PORTS]
44 for port, port_name
in ports.items():
46 api.setup_output(device_id, port)
47 api.write_output(device_id, port, 1
if invert_logic
else 0)
48 except NumatoGpioError
as err:
50 "Failed to initialize switch '%s' on Numato device %s port %s: %s",
70 """Representation of a Numato USB GPIO switch port."""
72 _attr_should_poll =
False
74 def __init__(self, name, device_id, port, invert_logic, api):
75 """Initialize the port."""
84 """Turn the port on."""
91 except NumatoGpioError
as err:
93 "Failed to turn on Numato device %s port %s: %s",
100 """Turn the port off."""
107 except NumatoGpioError
as err:
109 "Failed to turn off Numato device %s port %s: %s",
None turn_on(self, **Any kwargs)
None turn_off(self, **Any kwargs)
def __init__(self, name, device_id, port, invert_logic, api)
None schedule_update_ha_state(self, bool force_refresh=False)
None add_entities(AsusWrtRouter router, AddEntitiesCallback async_add_entities, set[str] tracked)
None setup_platform(HomeAssistant hass, ConfigType config, AddEntitiesCallback add_entities, DiscoveryInfoType|None discovery_info=None)
def write_output(switch, value)