Exemplo n.º 1
0
def setup(hass, config):
    """Set up the eBusd component."""
    conf = config[DOMAIN]
    name = conf[CONF_NAME]
    circuit = conf[CONF_CIRCUIT]
    monitored_conditions = conf.get(CONF_MONITORED_CONDITIONS)
    server_address = (
        conf.get(CONF_HOST), conf.get(CONF_PORT))

    try:
        _LOGGER.debug("Ebusd component setup started")
        import ebusdpy
        ebusdpy.init(server_address)
        hass.data[DOMAIN] = EbusdData(server_address, circuit)

        sensor_config = {
            CONF_MONITORED_CONDITIONS: monitored_conditions,
            'client_name': name,
            'sensor_types': SENSOR_TYPES[circuit]
        }
        load_platform(hass, 'sensor', DOMAIN, sensor_config, config)

        hass.services.register(
            DOMAIN, SERVICE_EBUSD_WRITE, hass.data[DOMAIN].write)

        _LOGGER.debug("Ebusd component setup completed")
        return True
    except (socket.timeout, socket.error):
        return False
Exemplo n.º 2
0
def setup(hass, config):
    """Set up the eBusd component."""
    conf = config[DOMAIN]
    name = conf[CONF_NAME]
    circuit = conf[CONF_CIRCUIT]
    monitored_conditions = conf.get(CONF_MONITORED_CONDITIONS)
    server_address = (conf.get(CONF_HOST), conf.get(CONF_PORT))

    try:
        _LOGGER.debug("Ebusd integration setup started")

        ebusdpy.init(server_address)
        hass.data[DOMAIN] = EbusdData(server_address, circuit)

        sensor_config = {
            CONF_MONITORED_CONDITIONS: monitored_conditions,
            "client_name": name,
            "sensor_types": SENSOR_TYPES[circuit],
        }
        load_platform(hass, "sensor", DOMAIN, sensor_config, config)

        hass.services.register(DOMAIN, SERVICE_EBUSD_WRITE,
                               hass.data[DOMAIN].write)

        _LOGGER.debug("Ebusd integration setup completed")
        return True
    except (socket.timeout, OSError):
        return False
Exemplo n.º 3
0
def setup(hass, config):
    """Set up the eBusd component."""
    conf = config[DOMAIN]
    cache_ttl = conf[CONF_CACHE_TTL]
    server_address = (conf.get(CONF_HOST), conf.get(CONF_PORT))

    try:
        _LOGGER.debug("Ebusd integration setup started")
        import ebusdpy

        ebusdpy.init(server_address)
        hass.data[DOMAIN] = EbusdData(server_address, cache_ttl)

        for circuit_cfg in conf[CONF_CIRCUITS]:
            sensor_config = {
                "circuit": circuit_cfg["circuit"],
                CONF_MONITORED_CONDITIONS: circuit_cfg["monitored_conditions"],
                "client_name": circuit_cfg["name"],
                "sensor_types": SENSOR_TYPES[circuit_cfg["circuit"]],
            }
            load_platform(hass, "sensor", DOMAIN, sensor_config, config)
        """Always add virtual ebusd sensors to track signal etc."""
        sensor_config = {
            "circuit": DOMAIN,
            CONF_MONITORED_CONDITIONS: SENSOR_TYPES[DOMAIN],
            "client_name": DOMAIN + "ctl",
            "sensor_types": SENSOR_TYPES[DOMAIN],
        }
        load_platform(hass, "sensor", DOMAIN, sensor_config, config)

        hass.services.register(DOMAIN, SERVICE_EBUSD_WRITE,
                               hass.data[DOMAIN].write)

        _LOGGER.debug("Ebusd integration setup completed")
        return True
    except (socket.timeout, socket.error):
        return False