def setup_platform(hass, config, add_entities, discovery_info=None): """Set up PwrCtrl devices/switches.""" host = config.get(CONF_HOST) username = config[CONF_USERNAME] password = config[CONF_PASSWORD] port_recv = config[CONF_PORT_RECV] port_send = config[CONF_PORT_SEND] try: master = DeviceMaster( username=username, password=password, read_port=port_send, write_port=port_recv, ) master.query(ip_addr=host) except OSError as ex: _LOGGER.error("Unable to discover PwrCtrl device: %s", str(ex)) return False devices = [] for device in master.devices.values(): parent_device = PwrCtrlDevice(device) devices.extend( PwrCtrlSwitch(switch, parent_device) for switch in device.switches.values()) add_entities(devices)
def setup_platform( hass: HomeAssistant, config: ConfigType, add_entities: AddEntitiesCallback, discovery_info: DiscoveryInfoType | None = None, ) -> None: """Set up PwrCtrl devices/switches.""" host = config.get(CONF_HOST) username = config[CONF_USERNAME] password = config[CONF_PASSWORD] port_recv = config[CONF_PORT_RECV] port_send = config[CONF_PORT_SEND] try: master = DeviceMaster( username=username, password=password, read_port=port_send, write_port=port_recv, ) master.query(ip_addr=host) except OSError as ex: _LOGGER.error("Unable to discover PwrCtrl device: %s", str(ex)) return devices: list[SwitchEntity] = [] for device in master.devices.values(): parent_device = PwrCtrlDevice(device) devices.extend( PwrCtrlSwitch(switch, parent_device) for switch in device.switches.values()) add_entities(devices)
def setup_platform(hass, config, add_devices, discovery_info=None): """Set up PwrCtrl devices/switches.""" host = config.get(CONF_HOST, None) username = config.get(CONF_USERNAME) password = config.get(CONF_PASSWORD) port_recv = config.get(CONF_PORT_RECV) port_send = config.get(CONF_PORT_SEND) from anel_pwrctrl import DeviceMaster try: master = DeviceMaster( username=username, password=password, read_port=port_send, write_port=port_recv) master.query(ip_addr=host) except socket.error as ex: _LOGGER.error("Unable to discover PwrCtrl device: %s", str(ex)) return False devices = [] for device in master.devices.values(): parent_device = PwrCtrlDevice(device) devices.extend( PwrCtrlSwitch(switch, parent_device) for switch in device.switches.values() ) add_devices(devices)
def setup_platform(hass, config, add_devices, discovery_info=None): """Setup PwrCtrl devices/switches.""" host = config.get(CONF_HOST, None) username = config.get(CONF_USERNAME) password = config.get(CONF_PASSWORD) port_recv = config.get(CONF_PORT_RECV) port_send = config.get(CONF_PORT_SEND) from anel_pwrctrl import DeviceMaster try: master = DeviceMaster(username=username, password=password, read_port=port_send, write_port=port_recv) master.query(ip_addr=host) except socket.error as ex: _LOGGER.error('Unable to discover PwrCtrl device: %s', str(ex)) return False devices = [] for device in master.devices.values(): parent_device = PwrCtrlDevice(device) devices.extend( PwrCtrlSwitch(switch, parent_device) for switch in device.switches.values()) add_devices(devices)