From 7cb847a3dcedf5032a097b35d2ce949e22837c4c Mon Sep 17 00:00:00 2001 From: Vincent A Date: Sun, 25 Mar 2018 23:07:22 +0200 Subject: [PATCH] weboob.capabilities.weather: add new fields --- weboob/capabilities/weather.py | 58 +++++++++++++++++++++++++++++++--- 1 file changed, 53 insertions(+), 5 deletions(-) diff --git a/weboob/capabilities/weather.py b/weboob/capabilities/weather.py index 0248f68d83..65417c1d5a 100644 --- a/weboob/capabilities/weather.py +++ b/weboob/capabilities/weather.py @@ -23,14 +23,48 @@ from weboob.tools.compat import basestring, unicode from .base import Capability, BaseObject, Field, FloatField, \ - StringField, UserError, NotLoaded + StringField, IntField, UserError, NotLoaded, EnumField, Enum from .date import DateField -__all__ = ['Forecast', 'Current', 'City', 'CityNotFound', 'Temperature', 'CapWeather'] +__all__ = [ + 'Forecast', 'Current', 'City', 'CityNotFound', 'Temperature', 'CapWeather', + 'BaseWeather', 'Direction', 'Precipitation', +] + + +class Direction(Enum): + S = 'South' + N = 'North' + E = 'East' + W = 'West' + SE = 'Southeast' + SW = 'Southwest' + NW = 'Northwest' + NE = 'Northeast' + SSE = 'South-Southeast' + SSW = 'South-Southwest' + NNW = 'North-Northwest' + NNE = 'North-Northeast' + ESE = 'East-Southeast' + ENE = 'East-Northeast' + WSW = 'West-Southwest' + WNW = 'West-Northwest' + + +# METAR keys +class Precipitation(Enum): + RA = 'Rain' + SN = 'Snow' + GR = 'Hail' + PL = 'Ice pellets' + GS = 'Small hail' + DZ = 'Drizzle' + IC = 'Ice cristals' + SG = 'Small grains' + UP = 'Unknown precipiation' class Temperature(BaseObject): - value = FloatField('Temperature value') unit = StringField('Input unit') @@ -63,7 +97,21 @@ def __repr__(self): return '' -class Forecast(BaseObject): +class BaseWeather(BaseObject): + precipitation = EnumField('Precipitation type', Precipitation) + precipitation_probability = FloatField('Probability of precipitation (ratio)') + + wind_direction = EnumField('Wind direction', Direction) + wind_speed = FloatField('Wind speed (in km/h)') + + humidity = FloatField('Relative humidity (ratio)') + pressure = FloatField('Atmospheric pressure (in hPa)') + + visibility = FloatField('Horizontal visibility distance (in km)') + cloud = IntField('Cloud coverage (in okta (0-8))') + + +class Forecast(BaseWeather): """ Weather forecast. """ @@ -80,7 +128,7 @@ def __init__(self, date=NotLoaded, low=None, high=None, text=None, unit=None, ur self.text = text -class Current(BaseObject): +class Current(BaseWeather): """ Current weather. """ -- GitLab