def test_wrong_input():
    """Test an invalid input."""
    dwd = DwdWeatherWarningsAPI(None)
    assert not dwd.data_valid
    assert dwd.warncell_id is None
    assert dwd.warncell_name is None
    assert dwd.last_update is None
    assert dwd.current_warning_level is None
    assert dwd.expected_warning_level is None
    assert dwd.current_warnings is None
    assert dwd.expected_warnings is None
Esempio n. 2
0
def setup_platform(hass, config, add_entities, discovery_info=None):
    """Set up the DWD-Weather-Warnings sensor."""
    name = config.get(CONF_NAME)
    region_name = config.get(CONF_REGION_NAME)

    api = WrappedDwDWWAPI(DwdWeatherWarningsAPI(region_name))

    sensors = []
    for sensor_type in config[CONF_MONITORED_CONDITIONS]:
        sensors.append(DwdWeatherWarningsSensor(api, name, sensor_type))

    add_entities(sensors, True)
Esempio n. 3
0
def setup_platform(hass, config, add_entities, discovery_info=None):
    """Set up the DWD-Weather-Warnings sensor."""
    name = config.get(CONF_NAME)
    region_name = config.get(CONF_REGION_NAME)

    api = WrappedDwDWWAPI(DwdWeatherWarningsAPI(region_name))

    sensors = [
        DwdWeatherWarningsSensor(api, name, description)
        for description in SENSOR_TYPES
        if description.key in config[CONF_MONITORED_CONDITIONS]
    ]

    add_entities(sensors, True)
def test_sea():
    """Test a sea warncell."""
    dwd = DwdWeatherWarningsAPI(WARNCELL_ID_SEA)
    assert dwd.data_valid
    assert dwd.warncell_id == WARNCELL_ID_SEA
    assert dwd.warncell_name == WARNCELL_NAME_SEA
    start_time = datetime.datetime.now(
        datetime.timezone.utc) - datetime.timedelta(0, TIME_TOLERANCE)
    stop_time = start_time + datetime.timedelta(0, (2 * TIME_TOLERANCE))
    assert start_time < dwd.last_update < stop_time
    assert MIN_WARNING_LEVEL <= dwd.current_warning_level <= MAX_WARNING_LEVEL
    assert MIN_WARNING_LEVEL <= dwd.expected_warning_level <= MAX_WARNING_LEVEL
    assert isinstance(dwd.current_warnings, list)
    assert isinstance(dwd.expected_warnings, list)
Esempio n. 5
0
def setup_platform(
    hass: HomeAssistant,
    config: ConfigType,
    add_entities: AddEntitiesCallback,
    discovery_info: DiscoveryInfoType | None = None,
) -> None:
    """Set up the DWD-Weather-Warnings sensor."""
    name = config.get(CONF_NAME)
    region_name = config.get(CONF_REGION_NAME)

    api = WrappedDwDWWAPI(DwdWeatherWarningsAPI(region_name))

    sensors = [
        DwdWeatherWarningsSensor(api, name, description)
        for description in SENSOR_TYPES
        if description.key in config[CONF_MONITORED_CONDITIONS]
    ]

    add_entities(sensors, True)