コード例 #1
0
def setup_platform(hass, config, add_entities, discovery_info=None):
    """Set up the NILU air quality sensor."""
    import niluclient as nilu
    name = config.get(CONF_NAME)
    area = config.get(CONF_AREA)
    stations = config.get(CONF_STATION)
    show_on_map = config.get(CONF_SHOW_ON_MAP)

    sensors = []

    if area:
        stations = nilu.lookup_stations_in_area(area)
    elif not area and not stations:
        latitude = config.get(CONF_LATITUDE, hass.config.latitude)
        longitude = config.get(CONF_LONGITUDE, hass.config.longitude)
        location_client = nilu.create_location_client(latitude, longitude)
        stations = location_client.station_names

    for station in stations:
        client = NiluData(nilu.create_station_client(station))
        client.update()
        if client.data.sensors:
            sensors.append(NiluSensor(client, name, show_on_map))
        else:
            _LOGGER.warning("%s didn't give any sensors results", station)

    add_entities(sensors, True)
コード例 #2
0
def setup_platform(hass, config, add_entities, discovery_info=None):
    """Set up the NILU air quality sensor."""
    name = config.get(CONF_NAME)
    area = config.get(CONF_AREA)
    stations = config.get(CONF_STATION)
    show_on_map = config.get(CONF_SHOW_ON_MAP)

    sensors = []

    if area:
        stations = lookup_stations_in_area(area)
    elif not area and not stations:
        latitude = config.get(CONF_LATITUDE, hass.config.latitude)
        longitude = config.get(CONF_LONGITUDE, hass.config.longitude)
        location_client = create_location_client(latitude, longitude)
        stations = location_client.station_names

    for station in stations:
        client = NiluData(create_station_client(station))
        client.update()
        if client.data.sensors:
            sensors.append(NiluSensor(client, name, show_on_map))
        else:
            _LOGGER.warning("%s didn't give any sensors results", station)

    add_entities(sensors, True)
コード例 #3
0
ファイル: air_quality.py プロジェクト: jbouwh/core
def setup_platform(
    hass: HomeAssistant,
    config: ConfigType,
    add_entities: AddEntitiesCallback,
    discovery_info: DiscoveryInfoType | None = None,
) -> None:
    """Set up the NILU air quality sensor."""
    name: str = config[CONF_NAME]
    area: str | None = config.get(CONF_AREA)
    stations: list[str] | None = config.get(CONF_STATION)
    show_on_map: bool = config[CONF_SHOW_ON_MAP]

    sensors = []

    if area:
        stations = lookup_stations_in_area(area)
    elif not stations:
        latitude = config.get(CONF_LATITUDE, hass.config.latitude)
        longitude = config.get(CONF_LONGITUDE, hass.config.longitude)
        location_client = create_location_client(latitude, longitude)
        stations = location_client.station_names

    assert stations is not None
    for station in stations:
        client = NiluData(create_station_client(station))
        client.update()
        if client.data.sensors:
            sensors.append(NiluSensor(client, name, show_on_map))
        else:
            _LOGGER.warning("%s didn't give any sensors results", station)

    add_entities(sensors, True)