示例#1
0
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
    """Configure the netio platform."""
    from pynetio import Netio

    if validate_config({"conf": config}, {"conf": [CONF_OUTLETS, CONF_HOST]}, _LOGGER):
        if len(DEVICES) == 0:
            hass.wsgi.register_view(NetioApiView)

        dev = Netio(
            config[CONF_HOST],
            config.get(CONF_PORT, DEFAULT_PORT),
            config.get(CONF_USERNAME, DEFAULT_USERNAME),
            config.get(CONF_PASSWORD, DEFAULT_USERNAME),
        )

        DEVICES[config[CONF_HOST]] = Device(dev, [])

        # Throttle the update for all NetioSwitches of one Netio
        dev.update = util.Throttle(MIN_TIME_BETWEEN_SCANS)(dev.update)

        for key in config[CONF_OUTLETS]:
            switch = NetioSwitch(DEVICES[config[CONF_HOST]].netio, key, config[CONF_OUTLETS][key])
            DEVICES[config[CONF_HOST]].entities.append(switch)

        add_devices_callback(DEVICES[config[CONF_HOST]].entities)

    hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, dispose)
    return True
示例#2
0
def setup_platform(hass, config, add_entities, discovery_info=None):
    """Set up the Netio platform."""

    host = config.get(CONF_HOST)
    username = config.get(CONF_USERNAME)
    password = config.get(CONF_PASSWORD)
    port = config.get(CONF_PORT)

    if not DEVICES:
        hass.http.register_view(NetioApiView)

    dev = Netio(host, port, username, password)

    DEVICES[host] = Device(dev, [])

    # Throttle the update for all Netio switches of one Netio
    dev.update = util.Throttle(MIN_TIME_BETWEEN_SCANS)(dev.update)

    for key in config[CONF_OUTLETS]:
        switch = NetioSwitch(DEVICES[host].netio, key, config[CONF_OUTLETS][key])
        DEVICES[host].entities.append(switch)

    add_entities(DEVICES[host].entities)

    hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, dispose)
    return True
示例#3
0
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
    """Configure the netio platform."""
    from pynetio import Netio

    if validate_config({"conf": config}, {"conf": [CONF_OUTLETS, CONF_HOST]},
                       _LOGGER):
        if len(DEVICES) == 0:
            hass.wsgi.register_view(NetioApiView)

        dev = Netio(config[CONF_HOST], config.get(CONF_PORT, DEFAULT_PORT),
                    config.get(CONF_USERNAME, DEFAULT_USERNAME),
                    config.get(CONF_PASSWORD, DEFAULT_USERNAME))

        DEVICES[config[CONF_HOST]] = Device(dev, [])

        # Throttle the update for all NetioSwitches of one Netio
        dev.update = util.Throttle(MIN_TIME_BETWEEN_SCANS)(dev.update)

        for key in config[CONF_OUTLETS]:
            switch = NetioSwitch(DEVICES[config[CONF_HOST]].netio, key,
                                 config[CONF_OUTLETS][key])
            DEVICES[config[CONF_HOST]].entities.append(switch)

        add_devices_callback(DEVICES[config[CONF_HOST]].entities)

    hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, dispose)
    return True
示例#4
0
def setup_platform(hass, config, add_entities, discovery_info=None):
    """Set up the Netio platform."""
    from pynetio import Netio

    host = config.get(CONF_HOST)
    username = config.get(CONF_USERNAME)
    password = config.get(CONF_PASSWORD)
    port = config.get(CONF_PORT)

    if not DEVICES:
        hass.http.register_view(NetioApiView)

    dev = Netio(host, port, username, password)

    DEVICES[host] = Device(dev, [])

    # Throttle the update for all Netio switches of one Netio
    dev.update = util.Throttle(MIN_TIME_BETWEEN_SCANS)(dev.update)

    for key in config[CONF_OUTLETS]:
        switch = NetioSwitch(
            DEVICES[host].netio, key, config[CONF_OUTLETS][key])
        DEVICES[host].entities.append(switch)

    add_entities(DEVICES[host].entities)

    hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, dispose)
    return True
示例#5
0
def setup_platform(
    hass: HomeAssistant,
    config: ConfigType,
    add_entities: AddEntitiesCallback,
    discovery_info: DiscoveryInfoType | None = None,
) -> None:
    """Set up the Netio platform."""

    host = config[CONF_HOST]
    username = config[CONF_USERNAME]
    password = config[CONF_PASSWORD]
    port = config[CONF_PORT]

    if not DEVICES:
        hass.http.register_view(NetioApiView)

    dev = Netio(host, port, username, password)

    DEVICES[host] = Device(dev, [])

    # Throttle the update for all Netio switches of one Netio
    dev.update = util.Throttle(MIN_TIME_BETWEEN_SCANS)(dev.update)

    for key in config[CONF_OUTLETS]:
        switch = NetioSwitch(DEVICES[host].netio, key,
                             config[CONF_OUTLETS][key])
        DEVICES[host].entities.append(switch)

    add_entities(DEVICES[host].entities)

    hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, dispose)