示例#1
0
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)
示例#2
0
def connect(ip, mac):
    try:
        s20 = S20(ip, mac)  # Supply IP and MAC address
        return s20
    except:
        print("Connection could not be established: An error occurred")
        return False
示例#3
0
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
    """ Find and return S20 switches. """
    if config.get('host') is None:
        _LOGGER.error("Missing required variable: host")
        return
    try:
        s20 = S20(config.get('host'))
        add_devices_callback(
            [S20Switch(config.get('name', DEFAULT_NAME), s20)])
    except S20Exception:
        _LOGGER.exception("S20 couldn't be initialized")
示例#4
0
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
    """ Find and return S20 switches. """
    from orvibo.s20 import S20, S20Exception

    switches = []
    switch_conf = config.get('switches', [config])

    for switch in switch_conf:
        if switch.get('host') is None:
            _LOGGER.error("Missing required variable: host")
            continue
        host = switch.get('host')
        try:
            switches.append(
                S20Switch(switch.get('name', DEFAULT_NAME), S20(host)))
            _LOGGER.info("Initialized S20 at %s", host)
        except S20Exception:
            _LOGGER.exception("S20 at %s couldn't be initialized", host)

    add_devices_callback(switches)
示例#5
0
 def __init__(self, sockets):
     self.pistorasiat = []
     for (name, ip, mac) in sockets:
         self.pistorasiat.append((name, S20(ip, mac)))