Skip to content

Commit

Permalink
Merge pull request #9 from DjMoren/feature/wind-max-speed
Browse files Browse the repository at this point in the history
Add wind_max_speed to sensor
  • Loading branch information
kalanda authored Dec 6, 2019
2 parents 8d4ac47 + ca68050 commit 2789e66
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 27 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ sensor:
- snow
- visibility
- wind_speed
- wind_max_speed
- wind_bearing
```

Expand Down
52 changes: 26 additions & 26 deletions custom_components/aemet/AemetApi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,28 @@
ATTR_WEATHER_PRECIPITATION = 'precipitation'
ATTR_WEATHER_SNOW = 'snow'
ATTR_WEATHER_WIND_SPEED = 'wind_speed'
ATTR_WEATHER_WIND_MAX_SPEED = 'wind_max_speed'
ATTR_WEATHER_WIND_BEARING = 'wind_bearing'

ATTR_MAPPINGS = {
ATTR_LONGITUDE: 'lon',
ATTR_LATITUDE: 'lat',
ATTR_ELEVATION: 'alt',
ATTR_STATION_NAME: 'ubi',
ATTR_WEATHER_PRECIPITATION: 'prec',
ATTR_WEATHER_PRESSURE: 'pres',
ATTR_WEATHER_TEMPERATURE: 'ta',
ATTR_WEATHER_HUMIDITY: 'hr',
ATTR_LAST_UPDATE: 'fint',
ATTR_WEATHER_VISIBILITY: 'vis',
ATTR_WEATHER_SNOW: 'nieve',
ATTR_WEATHER_WIND_SPEED: 'vv',
ATTR_WEATHER_WIND_MAX_SPEED: 'vmax',
ATTR_WEATHER_WIND_BEARING: 'dv'
}

MS_TO_KMH_ATTRS = [ATTR_WEATHER_WIND_SPEED, ATTR_WEATHER_WIND_MAX_SPEED]

CONF_ATTRIBUTION = 'Data provided by AEMET'
CONF_STATION_ID = 'station_id'

Expand Down Expand Up @@ -72,32 +92,12 @@ def update(self):
def set_data(self, record):
"""Set data using the last record from API."""
state = {}
if 'lon' in record:
state[ATTR_LONGITUDE] = record['lon']
if 'lat' in record:
state[ATTR_LATITUDE] = record['lat']
if 'alt' in record:
state[ATTR_ELEVATION] = record['alt']
if 'ubi' in record:
state[ATTR_STATION_NAME] = record['ubi']
if 'prec' in record:
state[ATTR_WEATHER_PRECIPITATION] = record['prec']
if 'pres' in record:
state[ATTR_WEATHER_PRESSURE] = record['pres']
if 'ta' in record:
state[ATTR_WEATHER_TEMPERATURE] = record['ta']
if 'hr' in record:
state[ATTR_WEATHER_HUMIDITY] = record['hr']
if 'fint' in record:
state[ATTR_LAST_UPDATE] = record['fint']
if 'vis' in record:
state[ATTR_WEATHER_VISIBILITY] = record['vis']
if 'nieve' in record:
state[ATTR_WEATHER_SNOW] = record['nieve']
if 'vv' in record:
state[ATTR_WEATHER_WIND_SPEED] = record['vv'] * 3.6 # m/s to km/h
if 'dv' in record:
state[ATTR_WEATHER_WIND_BEARING] = record['dv']
for attr_name, attr_value in ATTR_MAPPINGS.items():
if attr_value in record:
state[attr_name] = record[attr_value]
for attr in MS_TO_KMH_ATTRS:
if attr in state:
state[attr] = round(state[attr] * 3.6, 1) # m/s to km/h
self.data = state

def get_data(self, variable):
Expand Down
4 changes: 3 additions & 1 deletion custom_components/aemet/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
ATTR_WEATHER_PRECIPITATION,
ATTR_WEATHER_SNOW,
ATTR_WEATHER_WIND_SPEED,
ATTR_WEATHER_WIND_MAX_SPEED,
ATTR_WEATHER_WIND_BEARING,
CONF_ATTRIBUTION,
CONF_STATION_ID,
Expand All @@ -52,7 +53,8 @@
ATTR_WEATHER_PRECIPITATION: ['Precipitation', 'mm', 'mdi:weather-pouring'],
ATTR_WEATHER_SNOW: ['Snow', LENGTH_CENTIMETERS, 'mdi:snowflake'],
ATTR_WEATHER_VISIBILITY: ['Visibility', LENGTH_KILOMETERS, 'mdi:eye'],
ATTR_WEATHER_WIND_SPEED: ['Wind speed', 'm/s', 'mdi:weather-windy'],
ATTR_WEATHER_WIND_SPEED: ['Wind speed', 'km/h', 'mdi:weather-windy'],
ATTR_WEATHER_WIND_MAX_SPEED: ['Wind max speed', 'km/h', 'mdi:weather-windy'],
ATTR_WEATHER_WIND_BEARING: ['Wind bearing', 'degrees', 'mdi:compass'],
}

Expand Down
1 change: 1 addition & 0 deletions info.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ sensor:
- snow
- visibility
- wind_speed
- wind_max_speed
- wind_bearing
```

Expand Down

0 comments on commit 2789e66

Please sign in to comment.