def test_petite_couronne(fix_local_data, dep):
    """Test 'Petite Couronne' specificity.

    Check code when we use a department in the Paris 'Petit Couronne' which are
    not in the vigilance.meteofrance.fr XML file. In this case we use the
    departement 75.
    """

    zone = DepartmentWeatherAlert(dep)
    assert zone.department == "75"
Exemple #2
0
def setup_platform(hass, config, add_entities, discovery_info=None):
    """Set up the Meteo-France sensor."""
    if discovery_info is None:
        return

    city = discovery_info[CONF_CITY]
    monitored_conditions = discovery_info[CONF_MONITORED_CONDITIONS]
    client = hass.data[DATA_METEO_FRANCE][city]
    weather_alert_client = hass.data[DATA_METEO_FRANCE]["weather_alert_client"]

    from vigilancemeteo import DepartmentWeatherAlert

    alert_watcher = None
    if "weather_alert" in monitored_conditions:
        datas = hass.data[DATA_METEO_FRANCE][city].get_data()
        # Check if a department code is available for this city.
        if "dept" in datas:
            try:
                # If yes create the watcher DepartmentWeatherAlert object.
                alert_watcher = DepartmentWeatherAlert(
                    datas["dept"], weather_alert_client
                )
            except ValueError as exp:
                _LOGGER.error(
                    "Unexpected error when creating the weather alert sensor for %s in department %s: %s",
                    city,
                    datas["dept"],
                    exp,
                )
                alert_watcher = None
            else:
                _LOGGER.info(
                    "Weather alert watcher added for %s in department %s",
                    city,
                    datas["dept"],
                )
        else:
            _LOGGER.warning(
                "No 'dept' key found for '%s'. So weather alert information won't be available",
                city,
            )
            # Exit and don't create the sensor if no department code available.
            return

    add_entities(
        [
            MeteoFranceSensor(variable, client, alert_watcher)
            for variable in monitored_conditions
        ],
        True,
    )
def test_department_color(fix_local_data, department, color):
    """Test synthesis property."""
    zone = DepartmentWeatherAlert(department)
    assert zone.department_color == color
def test_department_parameter_not_valid(fix_local_data, dep):
    """Test when creating Class instace with with wrong parameters."""
    with pytest.raises(ValueError, match=r"Department .*"):
        DepartmentWeatherAlert(dep)
def test_summary_message_error(fix_local_data):
    """Test if we call summary_message method with a wrong parameter value."""
    zone = DepartmentWeatherAlert("32")
    with pytest.raises(ValueError, match=r"msg_format .*"):
        zone.summary_message("wrong_format")