def setup_platform(hass, config, add_devices_callback, discovery_info=None): """Set up S20 switches.""" from orvibo.s20 import discover, S20, S20Exception switch_data = {} switches = [] switch_conf = config.get(CONF_SWITCHES, [config]) if config.get(CONF_DISCOVERY): _LOGGER.info("Discovering S20 switches ...") switch_data.update(discover()) for switch in switch_conf: switch_data[switch.get(CONF_HOST)] = switch for host, data in switch_data.items(): try: switches.append( S20Switch(data.get(CONF_NAME), S20(host, mac=data.get(CONF_MAC)))) _LOGGER.info("Initialized S20 at %s", host) except S20Exception: _LOGGER.error("S20 at %s couldn't be initialized", host) add_devices_callback(switches)
def socket_factory(): sockets = [] socket_names = {"ac:cf:23:83:73:28": 'tv', "ac:cf:23:82:d9:ae": 'pc'} hosts = discover() for host in hosts: mac = add_colons(binascii.hexlify(hosts[host]['mac'])) if mac in socket_names: sockets.append((socket_names[mac], host, mac)) return Pistorasia(sockets)
def setup_platform(hass, config, add_devices_callback, discovery_info=None): """Set up S20 switches.""" from orvibo.s20 import discover, S20, S20Exception switch_data = {} switches = [] switch_conf = config.get(CONF_SWITCHES, [config]) if config.get(CONF_DISCOVERY): _LOGGER.info("Discovering S20 switches ...") switch_data.update(discover()) for switch in switch_conf: switch_data[switch.get(CONF_HOST)] = switch for host, data in switch_data.items(): try: switches.append(S20Switch(data.get(CONF_NAME), S20(host, mac=data.get(CONF_MAC)))) _LOGGER.info("Initialized S20 at %s", host) except S20Exception: _LOGGER.error("S20 at %s couldn't be initialized", host) add_devices_callback(switches)