Beispiel #1
0
def setup_platform(hass, config, add_entities, discovery_info=None):
    """Set up the KWB component."""
    host = config.get(CONF_HOST)
    port = config.get(CONF_PORT)
    device = config.get(CONF_DEVICE)
    connection_type = config.get(CONF_TYPE)
    raw = config.get(CONF_RAW)
    client_name = config.get(CONF_NAME)

    from pykwb import kwb

    if connection_type == 'serial':
        easyfire = kwb.KWBEasyfire(MODE_SERIAL, "", 0, device)
    elif connection_type == 'tcp':
        easyfire = kwb.KWBEasyfire(MODE_TCP, host, port)
    else:
        return False

    easyfire.run_thread()

    sensors = []
    for sensor in easyfire.get_sensors():
        if ((sensor.sensor_type != kwb.PROP_SENSOR_RAW)
                or (sensor.sensor_type == kwb.PROP_SENSOR_RAW and raw)):
            sensors.append(KWBSensor(easyfire, sensor, client_name))

    hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP,
                         lambda event: easyfire.stop_thread())

    add_entities(sensors)
def setup_platform(
    hass: HomeAssistant,
    config: ConfigType,
    add_entities: AddEntitiesCallback,
    discovery_info: DiscoveryInfoType | None = None,
) -> None:
    """Set up the KWB component."""
    host = config.get(CONF_HOST)
    port = config.get(CONF_PORT)
    device = config.get(CONF_DEVICE)
    connection_type = config.get(CONF_TYPE)
    raw = config.get(CONF_RAW)
    client_name = config.get(CONF_NAME)

    if connection_type == "serial":
        easyfire = kwb.KWBEasyfire(MODE_SERIAL, "", 0, device)
    elif connection_type == "tcp":
        easyfire = kwb.KWBEasyfire(MODE_TCP, host, port)
    else:
        return

    easyfire.run_thread()

    sensors = []
    for sensor in easyfire.get_sensors():
        if (sensor.sensor_type != kwb.PROP_SENSOR_RAW) or (
                sensor.sensor_type == kwb.PROP_SENSOR_RAW and raw):
            sensors.append(KWBSensor(easyfire, sensor, client_name))

    hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP,
                         lambda event: easyfire.stop_thread())

    add_entities(sensors)
Beispiel #3
0
def setup_platform(hass, config, add_devices, discovery_info=None):
    """Setup the KWB component."""
    host = config.get(CONF_HOST)
    port = config.get(CONF_PORT)
    type = config.get(CONF_TYPE)

    from pykwb import kwb

    _LOGGER.info('KWB: initializing')
    
    if (type == 'serial'):
        easyfire = kwb.KWBEasyfire(MODE_SERIAL, "", 0, port)
    elif (type == 'tcp'):
        easyfire = kwb.KWBEasyfire(MODE_TCP, host, port)
    else:
        return False
    
    sensors=[]
    for sensor in easyfire.get_sensors():
        sensors.append(KWBSensor(easyfire, sensor))
    
    add_devices(sensors)

    _LOGGER.info('KWB: starting thread')
    easyfire.run_thread()
    _LOGGER.info('KWB: thread started')