Beispiel #1
0
    def post(self, request, *args, **kwargs):
        config = Config.load()
        if "location" in request.POST:
            location = request.POST["location"]
            try:
                meteofranceClient(location)
                config.location = location
            except meteofranceError as exp:
                return JsonResponse(
                    {
                        "status": "unknownLocationError",
                        "message": _("Unknown location"),
                    },
                    status=406,
                )
        if "unit" in request.POST:
            unit = request.POST["unit"]
            config.unit = int(unit)

        if "weather_animation_type" in request.POST:
            weather_animation_type = request.POST["weather_animation_type"]
            config.weather_animation_type = weather_animation_type

        config.save()
        NabWeatherd.signal_daemon()
        context = self.get_context_data(**kwargs)
        return render(request, SettingsView.template_name, context=context)
def setup(hass, config):
    """Set up the Meteo-France component."""
    hass.data[DATA_METEO_FRANCE] = {}

    for location in config[DOMAIN]:

        city = location[CONF_CITY]

        from meteofrance.client import meteofranceClient, meteofranceError

        try:
            client = meteofranceClient(city)
        except meteofranceError as exp:
            _LOGGER.error(exp)
            return

        client.need_rain_forecast = bool(
            CONF_MONITORED_CONDITIONS in location and 'next_rain' in
            location[CONF_MONITORED_CONDITIONS])

        hass.data[DATA_METEO_FRANCE][city] = MeteoFranceUpdater(client)
        hass.data[DATA_METEO_FRANCE][city].update()

        if CONF_MONITORED_CONDITIONS in location:
            monitored_conditions = location[CONF_MONITORED_CONDITIONS]
            load_platform(
                hass, 'sensor', DOMAIN, {
                    CONF_CITY: city,
                    CONF_MONITORED_CONDITIONS: monitored_conditions}, config)

        load_platform(hass, 'weather', DOMAIN, {CONF_CITY: city}, config)

    return True
Beispiel #3
0
 def test_marseille(self):
   client = meteofranceClient(13000, True)
   data = client.get_data()
   self.assertNotIn('next_rain_intervals', data)
   self.assertNotIn('next_rain', data)
   self.assertNotIn('rain_forecast_text', data)
   self.assertNotIn('rain_forecast', data)
Beispiel #4
0
 def test_rouen(self):
   client = meteofranceClient(76000, True)
   data = client.get_data()
   self.assertIn('next_rain_intervals', data)
   self.assertIn('next_rain', data)
   self.assertIn('rain_forecast_text', data)
   self.assertIn('rain_forecast', data)
Beispiel #5
0
def setup(hass, config):
    """Set up the Meteo-France component."""
    hass.data[DATA_METEO_FRANCE] = {}

    for location in config[DOMAIN]:

        city = location[CONF_CITY]

        from meteofrance.client import meteofranceClient, meteofranceError

        try:
            client = meteofranceClient(city)
        except meteofranceError as exp:
            _LOGGER.error(exp)
            return

        client.need_rain_forecast = bool(
            CONF_MONITORED_CONDITIONS in location
            and 'next_rain' in location[CONF_MONITORED_CONDITIONS])

        hass.data[DATA_METEO_FRANCE][city] = MeteoFranceUpdater(client)
        hass.data[DATA_METEO_FRANCE][city].update()

        if CONF_MONITORED_CONDITIONS in location:
            monitored_conditions = location[CONF_MONITORED_CONDITIONS]
            load_platform(hass, 'sensor', DOMAIN, {
                CONF_CITY: city,
                CONF_MONITORED_CONDITIONS: monitored_conditions
            }, config)

        load_platform(hass, 'weather', DOMAIN, {CONF_CITY: city}, config)

    return True
Beispiel #6
0
def setup(hass, config):
    """Set up the Meteo-France component."""
    hass.data[DATA_METEO_FRANCE] = {}

    # Check if at least weather alert have to be monitored for one location.
    need_weather_alert_watcher = False
    for location in config[DOMAIN]:
        if CONF_MONITORED_CONDITIONS in location \
                 and 'weather_alert' in location[CONF_MONITORED_CONDITIONS]:
            need_weather_alert_watcher = True

    # If weather alert monitoring is expected initiate a client to be used by
    # all weather_alert entities.
    if need_weather_alert_watcher:
        from vigilancemeteo import VigilanceMeteoFranceProxy, \
            VigilanceMeteoError

        weather_alert_client = VigilanceMeteoFranceProxy()
        try:
            weather_alert_client.update_data()
        except VigilanceMeteoError as exp:
            _LOGGER.error(exp)
    else:
        weather_alert_client = None
    hass.data[DATA_METEO_FRANCE]['weather_alert_client'] = weather_alert_client

    for location in config[DOMAIN]:

        city = location[CONF_CITY]

        from meteofrance.client import meteofranceClient, meteofranceError

        try:
            client = meteofranceClient(city)
        except meteofranceError as exp:
            _LOGGER.error(exp)
            return

        client.need_rain_forecast = bool(
            CONF_MONITORED_CONDITIONS in location
            and 'next_rain' in location[CONF_MONITORED_CONDITIONS])

        hass.data[DATA_METEO_FRANCE][city] = MeteoFranceUpdater(client)
        hass.data[DATA_METEO_FRANCE][city].update()

        if CONF_MONITORED_CONDITIONS in location:
            monitored_conditions = location[CONF_MONITORED_CONDITIONS]
            _LOGGER.debug("meteo_france sensor platfrom loaded for %s", city)
            load_platform(hass, 'sensor', DOMAIN, {
                CONF_CITY: city,
                CONF_MONITORED_CONDITIONS: monitored_conditions
            }, config)

        load_platform(hass, 'weather', DOMAIN, {CONF_CITY: city}, config)

    return True
def setup_platform(hass, config, add_entities, discovery_info=None):
    """Set up the Meteo-France sensor."""
    postal_code = config[CONF_POSTAL_CODE]

    from meteofrance.client import meteofranceClient, meteofranceError

    try:
        meteofrance_client = meteofranceClient(postal_code)
    except meteofranceError as exp:
        _LOGGER.error(exp)
        return

    client = MeteoFranceUpdater(meteofrance_client)

    add_entities([MeteoFranceSensor(variable, client)
                  for variable in config[CONF_MONITORED_CONDITIONS]],
                 True)
def setup_platform(hass, config, add_entities, discovery_info=None):
    """Set up the Meteo-France sensor."""
    postal_code = config[CONF_POSTAL_CODE]

    from meteofrance.client import meteofranceClient, meteofranceError

    try:
        meteofrance_client = meteofranceClient(postal_code)
    except meteofranceError as exp:
        _LOGGER.error(exp)
        return

    client = MeteoFranceUpdater(meteofrance_client)

    add_entities([
        MeteoFranceSensor(variable, client)
        for variable in config[CONF_MONITORED_CONDITIONS]
    ], True)
Beispiel #9
0
 def test_rain_forecast_is_updated(self):
   client = meteofranceClient('01700')
   client.need_rain_forecast = False
   client.update()
   self.assertEqual(client.need_rain_forecast, False)
   data = client.get_data()
   self.assertNotIn('next_rain_intervals', data)
   self.assertNotIn('next_rain', data)
   self.assertNotIn('rain_forecast_text', data)
   self.assertNotIn('rain_forecast', data)
   client.need_rain_forecast = True
   client.update()
   self.assertEqual(client.need_rain_forecast, True)
   data = client.get_data()
   self.assertIn('next_rain_intervals', data)
   self.assertIn('next_rain', data)
   self.assertIn('rain_forecast_text', data)
   self.assertIn('rain_forecast', data)
Beispiel #10
0
 def test_pointe_a_pitre(self):
   client = meteofranceClient('Tokyo')
   client.need_rain_forecast = False
   client.update()
   data = client.get_data()
   self.assertIn('name', data)
   self.assertNotIn('dept', data)
   self.assertIn('fetched_at', data)
   self.assertIn('forecast', data)
   self.assertNotIn('freeze_chance', data)
   self.assertNotIn('rain_chance', data)
   self.assertNotIn('snow_chance', data)
   self.assertIn('temperature', data)
   self.assertNotIn('thunder_chance', data)
   self.assertNotIn('uv', data)
   self.assertIn('weather_class', data)
   self.assertIn('weather', data)
   self.assertIn('wind_bearing', data)
   self.assertIn('wind_speed', data)
   self.assertNotIn('next_rain_intervals', data)
   self.assertNotIn('next_rain', data)
   self.assertNotIn('rain_forecast_text', data)
   self.assertNotIn('rain_forecast', data)
   self.assertGreaterEqual(len(data['forecast']), 9)
Beispiel #11
0
 def test_beynost(self):
   client = meteofranceClient('01700')
   client.need_rain_forecast = False
   client.update()
   data = client.get_data()
   self.assertIn('name', data)
   self.assertIn('dept', data)
   self.assertIn('fetched_at', data)
   self.assertIn('forecast', data)
   self.assertIn('freeze_chance', data)
   self.assertIn('rain_chance', data)
   self.assertIn('snow_chance', data)
   self.assertIn('temperature', data)
   self.assertIn('thunder_chance', data)
   self.assertIn('uv', data)
   self.assertIn('weather_class', data)
   self.assertIn('weather', data)
   self.assertIn('wind_bearing', data)
   self.assertIn('wind_speed', data)
   self.assertNotIn('next_rain_intervals', data)
   self.assertNotIn('next_rain', data)
   self.assertNotIn('next_rain_datetime', data)
   self.assertNotIn('rain_forecast_text', data)
   self.assertNotIn('rain_forecast', data)
Beispiel #12
0
 def test_postal_code(self):
   client = meteofranceClient('80000', True)
   data = client.get_data()
   self.assertEqual(data['name'], 'Amiens')
   self.assertEqual(data['dept'], '80')
   self.assertEqual(data['printName'], 'Amiens (80000)')
Beispiel #13
0
def setup(hass, config):
    """Set up the Meteo-France component."""
    hass.data[DATA_METEO_FRANCE] = {}

    # Check if at least weather alert have to be monitored for one location.
    need_weather_alert_watcher = False
    for location in config[DOMAIN]:
        if (
            CONF_MONITORED_CONDITIONS in location
            and "weather_alert" in location[CONF_MONITORED_CONDITIONS]
        ):
            need_weather_alert_watcher = True

    # If weather alert monitoring is expected initiate a client to be used by
    # all weather_alert entities.
    if need_weather_alert_watcher:
        _LOGGER.debug("Weather Alert monitoring expected. Loading vigilancemeteo")

        weather_alert_client = VigilanceMeteoFranceProxy()
        try:
            weather_alert_client.update_data()
        except VigilanceMeteoError as exp:
            _LOGGER.error(
                "Unexpected error when creating the vigilance_meteoFrance proxy: %s ",
                exp,
            )
    else:
        weather_alert_client = None
    hass.data[DATA_METEO_FRANCE]["weather_alert_client"] = weather_alert_client

    for location in config[DOMAIN]:

        city = location[CONF_CITY]

        try:
            client = meteofranceClient(city)
        except meteofranceError as exp:
            _LOGGER.error(
                "Unexpected error when creating the meteofrance proxy: %s", exp
            )
            return

        client.need_rain_forecast = bool(
            CONF_MONITORED_CONDITIONS in location
            and "next_rain" in location[CONF_MONITORED_CONDITIONS]
        )

        hass.data[DATA_METEO_FRANCE][city] = MeteoFranceUpdater(client)
        hass.data[DATA_METEO_FRANCE][city].update()

        if CONF_MONITORED_CONDITIONS in location:
            monitored_conditions = location[CONF_MONITORED_CONDITIONS]
            _LOGGER.debug("meteo_france sensor platform loaded for %s", city)
            load_platform(
                hass,
                "sensor",
                DOMAIN,
                {CONF_CITY: city, CONF_MONITORED_CONDITIONS: monitored_conditions},
                config,
            )

        load_platform(hass, "weather", DOMAIN, {CONF_CITY: city}, config)

    return True
Beispiel #14
0
 def test_oslo(self):
   client = meteofranceClient('oslo, norvege', True)
   data = client.get_data()
   self.assertEqual(data['name'], 'Oslo')
   self.assertEqual(data['printName'], u'Oslo (Norvège)')
Beispiel #15
0
 def f_test_invalid(self):
   meteofranceClient('foobar')
Beispiel #16
0
 def test_department(self):
   client = meteofranceClient('95', True)
   data = client.get_data()
   self.assertEqual(data['name'], 'Ableiges')
   self.assertEqual(data['printName'], 'Ableiges (95450)')
Beispiel #17
0
 def test_city_name(self):
   client = meteofranceClient('Brest', True)
   data = client.get_data()
   self.assertEqual(data['name'], 'Brest')
   self.assertEqual(data['printName'], u'Brest (Biélorussie)')
Beispiel #18
0
 def test_luxembourg(self):
   client = meteofranceClient('luxembourg', True)
   data = client.get_data()
   self.assertEqual(data['name'], 'Luxembourg')
   self.assertEqual(data['printName'], u'Luxembourg (Luxembourg )')