Update to buienradar json api; and additional monitored_conditions (#24463)

* Update to json api; and additional sensors

* remove unneeded coordinate rounding

* minor optimizations

* Update CODEOWNERS

* Update sensor.py

unit conversion for:
- windgust (ms to km/h)
- windspeed (m/s to km/h)
- windspeed_1d (ms/km/h)
- visibility (m to km)

* Update weather.py

unit conversion for windspeed (m/s to km/h)

* Update sensor.py

* Update weather.py

* Update weather.py

* Update CODEOWNERS

* Update manifest.json

* Update CODEOWNERS

* Update CODEOWNERS

yet another try to get CODEOWNERS accepted...

* update codeowners

* update codeowners

* update

* updated codeowners to match manifest
This commit is contained in:
MJJ 2019-07-28 22:08:20 +02:00 committed by Martin Hjelmare
parent c6c4c07f2d
commit 14c3b38461
5 changed files with 153 additions and 69 deletions

View File

@ -48,7 +48,7 @@ homeassistant/components/braviatv/* @robbiet480
homeassistant/components/broadlink/* @danielhiversen homeassistant/components/broadlink/* @danielhiversen
homeassistant/components/brunt/* @eavanvalkenburg homeassistant/components/brunt/* @eavanvalkenburg
homeassistant/components/bt_smarthub/* @jxwolstenholme homeassistant/components/bt_smarthub/* @jxwolstenholme
homeassistant/components/buienradar/* @ties homeassistant/components/buienradar/* @mjj4791 @ties
homeassistant/components/cisco_ios/* @fbradyirl homeassistant/components/cisco_ios/* @fbradyirl
homeassistant/components/cisco_mobility_express/* @fbradyirl homeassistant/components/cisco_mobility_express/* @fbradyirl
homeassistant/components/cisco_webex_teams/* @fbradyirl homeassistant/components/cisco_webex_teams/* @fbradyirl

View File

@ -3,8 +3,10 @@
"name": "Buienradar", "name": "Buienradar",
"documentation": "https://www.home-assistant.io/components/buienradar", "documentation": "https://www.home-assistant.io/components/buienradar",
"requirements": [ "requirements": [
"buienradar==0.91" "buienradar==1.0.1"
], ],
"dependencies": [], "dependencies": [],
"codeowners": ["@ties"] "codeowners": [
"@mjj4791", "@ties"
]
} }

View File

@ -32,28 +32,40 @@ SCHEDULE_NOK = 2
# Key: ['label', unit, icon] # Key: ['label', unit, icon]
SENSOR_TYPES = { SENSOR_TYPES = {
'stationname': ['Stationname', None, None], 'stationname': ['Stationname', None, None],
# new in json api (>1.0.0):
'barometerfc': ['Barometer value', None, 'mdi:gauge'],
# new in json api (>1.0.0):
'barometerfcname': ['Barometer', None, 'mdi:gauge'],
# new in json api (>1.0.0):
'barometerfcnamenl': ['Barometer', None, 'mdi:gauge'],
'condition': ['Condition', None, None], 'condition': ['Condition', None, None],
'conditioncode': ['Condition code', None, None], 'conditioncode': ['Condition code', None, None],
'conditiondetailed': ['Detailed condition', None, None], 'conditiondetailed': ['Detailed condition', None, None],
'conditionexact': ['Full condition', None, None], 'conditionexact': ['Full condition', None, None],
'symbol': ['Symbol', None, None], 'symbol': ['Symbol', None, None],
# new in json api (>1.0.0):
'feeltemperature': ['Feel temperature', TEMP_CELSIUS, 'mdi:thermometer'],
'humidity': ['Humidity', '%', 'mdi:water-percent'], 'humidity': ['Humidity', '%', 'mdi:water-percent'],
'temperature': ['Temperature', TEMP_CELSIUS, 'mdi:thermometer'], 'temperature': ['Temperature', TEMP_CELSIUS, 'mdi:thermometer'],
'groundtemperature': ['Ground temperature', TEMP_CELSIUS, 'groundtemperature': ['Ground temperature', TEMP_CELSIUS,
'mdi:thermometer'], 'mdi:thermometer'],
'windspeed': ['Wind speed', 'm/s', 'mdi:weather-windy'], 'windspeed': ['Wind speed', 'km/h', 'mdi:weather-windy'],
'windforce': ['Wind force', 'Bft', 'mdi:weather-windy'], 'windforce': ['Wind force', 'Bft', 'mdi:weather-windy'],
'winddirection': ['Wind direction', None, 'mdi:compass-outline'], 'winddirection': ['Wind direction', None, 'mdi:compass-outline'],
'windazimuth': ['Wind direction azimuth', '°', 'mdi:compass-outline'], 'windazimuth': ['Wind direction azimuth', '°', 'mdi:compass-outline'],
'pressure': ['Pressure', 'hPa', 'mdi:gauge'], 'pressure': ['Pressure', 'hPa', 'mdi:gauge'],
'visibility': ['Visibility', 'm', None], 'visibility': ['Visibility', 'km', None],
'windgust': ['Wind gust', 'm/s', 'mdi:weather-windy'], 'windgust': ['Wind gust', 'km/h', 'mdi:weather-windy'],
'precipitation': ['Precipitation', 'mm/h', 'mdi:weather-pouring'], 'precipitation': ['Precipitation', 'mm/h', 'mdi:weather-pouring'],
'irradiance': ['Irradiance', 'W/m2', 'mdi:sunglasses'], 'irradiance': ['Irradiance', 'W/m2', 'mdi:sunglasses'],
'precipitation_forecast_average': ['Precipitation forecast average', 'precipitation_forecast_average': ['Precipitation forecast average',
'mm/h', 'mdi:weather-pouring'], 'mm/h', 'mdi:weather-pouring'],
'precipitation_forecast_total': ['Precipitation forecast total', 'precipitation_forecast_total': ['Precipitation forecast total',
'mm', 'mdi:weather-pouring'], 'mm', 'mdi:weather-pouring'],
# new in json api (>1.0.0):
'rainlast24hour': ['Rain last 24h', 'mm', 'mdi:weather-pouring'],
# new in json api (>1.0.0):
'rainlasthour': ['Rain last hour', 'mm', 'mdi:weather-pouring'],
'temperature_1d': ['Temperature 1d', TEMP_CELSIUS, 'mdi:thermometer'], 'temperature_1d': ['Temperature 1d', TEMP_CELSIUS, 'mdi:thermometer'],
'temperature_2d': ['Temperature 2d', TEMP_CELSIUS, 'mdi:thermometer'], 'temperature_2d': ['Temperature 2d', TEMP_CELSIUS, 'mdi:thermometer'],
'temperature_3d': ['Temperature 3d', TEMP_CELSIUS, 'mdi:thermometer'], 'temperature_3d': ['Temperature 3d', TEMP_CELSIUS, 'mdi:thermometer'],
@ -69,11 +81,18 @@ SENSOR_TYPES = {
'rain_3d': ['Rain 3d', 'mm', 'mdi:weather-pouring'], 'rain_3d': ['Rain 3d', 'mm', 'mdi:weather-pouring'],
'rain_4d': ['Rain 4d', 'mm', 'mdi:weather-pouring'], 'rain_4d': ['Rain 4d', 'mm', 'mdi:weather-pouring'],
'rain_5d': ['Rain 5d', 'mm', 'mdi:weather-pouring'], 'rain_5d': ['Rain 5d', 'mm', 'mdi:weather-pouring'],
'snow_1d': ['Snow 1d', 'cm', 'mdi:snowflake'], # new in json api (>1.0.0):
'snow_2d': ['Snow 2d', 'cm', 'mdi:snowflake'], 'minrain_1d': ['Minimum rain 1d', 'mm', 'mdi:weather-pouring'],
'snow_3d': ['Snow 3d', 'cm', 'mdi:snowflake'], 'minrain_2d': ['Minimum rain 2d', 'mm', 'mdi:weather-pouring'],
'snow_4d': ['Snow 4d', 'cm', 'mdi:snowflake'], 'minrain_3d': ['Minimum rain 3d', 'mm', 'mdi:weather-pouring'],
'snow_5d': ['Snow 5d', 'cm', 'mdi:snowflake'], 'minrain_4d': ['Minimum rain 4d', 'mm', 'mdi:weather-pouring'],
'minrain_5d': ['Minimum rain 5d', 'mm', 'mdi:weather-pouring'],
# new in json api (>1.0.0):
'maxrain_1d': ['Maximum rain 1d', 'mm', 'mdi:weather-pouring'],
'maxrain_2d': ['Maximum rain 2d', 'mm', 'mdi:weather-pouring'],
'maxrain_3d': ['Maximum rain 3d', 'mm', 'mdi:weather-pouring'],
'maxrain_4d': ['Maximum rain 4d', 'mm', 'mdi:weather-pouring'],
'maxrain_5d': ['Maximum rain 5d', 'mm', 'mdi:weather-pouring'],
'rainchance_1d': ['Rainchance 1d', '%', 'mdi:weather-pouring'], 'rainchance_1d': ['Rainchance 1d', '%', 'mdi:weather-pouring'],
'rainchance_2d': ['Rainchance 2d', '%', 'mdi:weather-pouring'], 'rainchance_2d': ['Rainchance 2d', '%', 'mdi:weather-pouring'],
'rainchance_3d': ['Rainchance 3d', '%', 'mdi:weather-pouring'], 'rainchance_3d': ['Rainchance 3d', '%', 'mdi:weather-pouring'],
@ -89,6 +108,26 @@ SENSOR_TYPES = {
'windforce_3d': ['Wind force 3d', 'Bft', 'mdi:weather-windy'], 'windforce_3d': ['Wind force 3d', 'Bft', 'mdi:weather-windy'],
'windforce_4d': ['Wind force 4d', 'Bft', 'mdi:weather-windy'], 'windforce_4d': ['Wind force 4d', 'Bft', 'mdi:weather-windy'],
'windforce_5d': ['Wind force 5d', 'Bft', 'mdi:weather-windy'], 'windforce_5d': ['Wind force 5d', 'Bft', 'mdi:weather-windy'],
'windspeed_1d': ['Wind speed 1d', 'km/h', 'mdi:weather-windy'],
'windspeed_2d': ['Wind speed 2d', 'km/h', 'mdi:weather-windy'],
'windspeed_3d': ['Wind speed 3d', 'km/h', 'mdi:weather-windy'],
'windspeed_4d': ['Wind speed 4d', 'km/h', 'mdi:weather-windy'],
'windspeed_5d': ['Wind speed 5d', 'km/h', 'mdi:weather-windy'],
'winddirection_1d': ['Wind direction 1d', None, 'mdi:compass-outline'],
'winddirection_2d': ['Wind direction 2d', None, 'mdi:compass-outline'],
'winddirection_3d': ['Wind direction 3d', None, 'mdi:compass-outline'],
'winddirection_4d': ['Wind direction 4d', None, 'mdi:compass-outline'],
'winddirection_5d': ['Wind direction 5d', None, 'mdi:compass-outline'],
'windazimuth_1d': ['Wind direction azimuth 1d', '°',
'mdi:compass-outline'],
'windazimuth_2d': ['Wind direction azimuth 2d', '°',
'mdi:compass-outline'],
'windazimuth_3d': ['Wind direction azimuth 3d', '°',
'mdi:compass-outline'],
'windazimuth_4d': ['Wind direction azimuth 4d', '°',
'mdi:compass-outline'],
'windazimuth_5d': ['Wind direction azimuth 5d', '°',
'mdi:compass-outline'],
'condition_1d': ['Condition 1d', None, None], 'condition_1d': ['Condition 1d', None, None],
'condition_2d': ['Condition 2d', None, None], 'condition_2d': ['Condition 2d', None, None],
'condition_3d': ['Condition 3d', None, None], 'condition_3d': ['Condition 3d', None, None],
@ -113,7 +152,7 @@ SENSOR_TYPES = {
'symbol_2d': ['Symbol 2d', None, None], 'symbol_2d': ['Symbol 2d', None, None],
'symbol_3d': ['Symbol 3d', None, None], 'symbol_3d': ['Symbol 3d', None, None],
'symbol_4d': ['Symbol 4d', None, None], 'symbol_4d': ['Symbol 4d', None, None],
'symbol_5d': ['Symbol 5d', None, None], 'symbol_5d': ['Symbol 5d', None, None]
} }
CONF_TIMEFRAME = 'timeframe' CONF_TIMEFRAME = 'timeframe'
@ -168,7 +207,7 @@ class BrSensor(Entity):
def __init__(self, sensor_type, client_name, coordinates): def __init__(self, sensor_type, client_name, coordinates):
"""Initialize the sensor.""" """Initialize the sensor."""
from buienradar.buienradar import (PRECIPITATION_FORECAST, CONDITION) from buienradar.constants import (PRECIPITATION_FORECAST, CONDITION)
self.client_name = client_name self.client_name = client_name
self._name = SENSOR_TYPES[sensor_type][0] self._name = SENSOR_TYPES[sensor_type][0]
@ -198,11 +237,12 @@ class BrSensor(Entity):
def load_data(self, data): def load_data(self, data):
"""Load the sensor with relevant data.""" """Load the sensor with relevant data."""
# Find sensor # Find sensor
from buienradar.buienradar import (ATTRIBUTION, CONDITION, CONDCODE, from buienradar.constants import (ATTRIBUTION, CONDITION, CONDCODE,
DETAILED, EXACT, EXACTNL, FORECAST, DETAILED, EXACT, EXACTNL, FORECAST,
IMAGE, MEASURED, IMAGE, MEASURED,
PRECIPITATION_FORECAST, STATIONNAME, PRECIPITATION_FORECAST, STATIONNAME,
TIMEFRAME) TIMEFRAME, VISIBILITY, WINDGUST,
WINDSPEED)
# Check if we have a new measurement, # Check if we have a new measurement,
# otherwise we do not have to update the sensor # otherwise we do not have to update the sensor
@ -219,6 +259,7 @@ class BrSensor(Entity):
self.type.endswith('_4d') or \ self.type.endswith('_4d') or \
self.type.endswith('_5d'): self.type.endswith('_5d'):
# update forcasting sensors:
fcday = 0 fcday = 0
if self.type.endswith('_2d'): if self.type.endswith('_2d'):
fcday = 1 fcday = 1
@ -229,7 +270,7 @@ class BrSensor(Entity):
if self.type.endswith('_5d'): if self.type.endswith('_5d'):
fcday = 4 fcday = 4
# update all other sensors # update weather symbol & status text
if self.type.startswith(SYMBOL) or self.type.startswith(CONDITION): if self.type.startswith(SYMBOL) or self.type.startswith(CONDITION):
try: try:
condition = data.get(FORECAST)[fcday].get(CONDITION) condition = data.get(FORECAST)[fcday].get(CONDITION)
@ -256,6 +297,18 @@ class BrSensor(Entity):
return True return True
return False return False
if self.type.startswith(WINDSPEED):
# hass wants windspeeds in km/h not m/s, so convert:
try:
self._state = data.get(FORECAST)[fcday].get(self.type[:-3])
if self._state is not None:
self._state = round(self._state * 3.6, 1)
return True
except IndexError:
_LOGGER.warning("No forecast for fcday=%s...", fcday)
return False
# update all other sensors
try: try:
self._state = data.get(FORECAST)[fcday].get(self.type[:-3]) self._state = data.get(FORECAST)[fcday].get(self.type[:-3])
return True return True
@ -294,6 +347,20 @@ class BrSensor(Entity):
self._state = nested.get(self.type[len(PRECIPITATION_FORECAST)+1:]) self._state = nested.get(self.type[len(PRECIPITATION_FORECAST)+1:])
return True return True
if self.type == WINDSPEED or self.type == WINDGUST:
# hass wants windspeeds in km/h not m/s, so convert:
self._state = data.get(self.type)
if self._state is not None:
self._state = round(data.get(self.type) * 3.6, 1)
return True
if self.type == VISIBILITY:
# hass wants visibility in km (not m), so convert:
self._state = data.get(self.type)
if self._state is not None:
self._state = round(self._state / 1000, 1)
return True
# update all other sensors # update all other sensors
self._state = data.get(self.type) self._state = data.get(self.type)
return True return True
@ -331,7 +398,7 @@ class BrSensor(Entity):
@property @property
def device_state_attributes(self): def device_state_attributes(self):
"""Return the state attributes.""" """Return the state attributes."""
from buienradar.buienradar import (PRECIPITATION_FORECAST) from buienradar.constants import (PRECIPITATION_FORECAST)
if self.type.startswith(PRECIPITATION_FORECAST): if self.type.startswith(PRECIPITATION_FORECAST):
result = {ATTR_ATTRIBUTION: self._attribution} result = {ATTR_ATTRIBUTION: self._attribution}
@ -399,7 +466,7 @@ class BrData:
async def get_data(self, url): async def get_data(self, url):
"""Load data from specified url.""" """Load data from specified url."""
from buienradar.buienradar import (CONTENT, from buienradar.constants import (CONTENT,
MESSAGE, STATUS_CODE, SUCCESS) MESSAGE, STATUS_CODE, SUCCESS)
_LOGGER.debug("Calling url: %s...", url) _LOGGER.debug("Calling url: %s...", url)
@ -427,16 +494,17 @@ class BrData:
async def async_update(self, *_): async def async_update(self, *_):
"""Update the data from buienradar.""" """Update the data from buienradar."""
from buienradar.buienradar import (parse_data, CONTENT, from buienradar.constants import (CONTENT, DATA, MESSAGE,
DATA, MESSAGE, STATUS_CODE, SUCCESS) STATUS_CODE, SUCCESS)
from buienradar.buienradar import (parse_data)
from buienradar.urls import (JSON_FEED_URL,
json_precipitation_forecast_url)
content = await self.get_data('http://xml.buienradar.nl') content = await self.get_data(JSON_FEED_URL)
if not content.get(SUCCESS, False):
content = await self.get_data('http://api.buienradar.nl')
if content.get(SUCCESS) is not True: if content.get(SUCCESS) is not True:
# unable to get the data # unable to get the data
_LOGGER.warning("Unable to retrieve xml data from Buienradar." _LOGGER.warning("Unable to retrieve json data from Buienradar."
"(Msg: %s, status: %s,)", "(Msg: %s, status: %s,)",
content.get(MESSAGE), content.get(MESSAGE),
content.get(STATUS_CODE),) content.get(STATUS_CODE),)
@ -445,11 +513,9 @@ class BrData:
return return
# rounding coordinates prevents unnecessary redirects/calls # rounding coordinates prevents unnecessary redirects/calls
rainurl = 'http://gadgets.buienradar.nl/data/raintext/?lat={}&lon={}' lat = self.coordinates[CONF_LATITUDE]
rainurl = rainurl.format( lon = self.coordinates[CONF_LONGITUDE]
round(self.coordinates[CONF_LATITUDE], 2), rainurl = json_precipitation_forecast_url(lat, lon)
round(self.coordinates[CONF_LONGITUDE], 2)
)
raincontent = await self.get_data(rainurl) raincontent = await self.get_data(rainurl)
if raincontent.get(SUCCESS) is not True: if raincontent.get(SUCCESS) is not True:
@ -466,7 +532,8 @@ class BrData:
raincontent.get(CONTENT), raincontent.get(CONTENT),
self.coordinates[CONF_LATITUDE], self.coordinates[CONF_LATITUDE],
self.coordinates[CONF_LONGITUDE], self.coordinates[CONF_LONGITUDE],
self.timeframe) self.timeframe,
False)
_LOGGER.debug("Buienradar parsed data: %s", result) _LOGGER.debug("Buienradar parsed data: %s", result)
if result.get(SUCCESS) is not True: if result.get(SUCCESS) is not True:
@ -484,25 +551,25 @@ class BrData:
@property @property
def attribution(self): def attribution(self):
"""Return the attribution.""" """Return the attribution."""
from buienradar.buienradar import ATTRIBUTION from buienradar.constants import ATTRIBUTION
return self.data.get(ATTRIBUTION) return self.data.get(ATTRIBUTION)
@property @property
def stationname(self): def stationname(self):
"""Return the name of the selected weatherstation.""" """Return the name of the selected weatherstation."""
from buienradar.buienradar import STATIONNAME from buienradar.constants import STATIONNAME
return self.data.get(STATIONNAME) return self.data.get(STATIONNAME)
@property @property
def condition(self): def condition(self):
"""Return the condition.""" """Return the condition."""
from buienradar.buienradar import CONDITION from buienradar.constants import CONDITION
return self.data.get(CONDITION) return self.data.get(CONDITION)
@property @property
def temperature(self): def temperature(self):
"""Return the temperature, or None.""" """Return the temperature, or None."""
from buienradar.buienradar import TEMPERATURE from buienradar.constants import TEMPERATURE
try: try:
return float(self.data.get(TEMPERATURE)) return float(self.data.get(TEMPERATURE))
except (ValueError, TypeError): except (ValueError, TypeError):
@ -511,7 +578,7 @@ class BrData:
@property @property
def pressure(self): def pressure(self):
"""Return the pressure, or None.""" """Return the pressure, or None."""
from buienradar.buienradar import PRESSURE from buienradar.constants import PRESSURE
try: try:
return float(self.data.get(PRESSURE)) return float(self.data.get(PRESSURE))
except (ValueError, TypeError): except (ValueError, TypeError):
@ -520,7 +587,7 @@ class BrData:
@property @property
def humidity(self): def humidity(self):
"""Return the humidity, or None.""" """Return the humidity, or None."""
from buienradar.buienradar import HUMIDITY from buienradar.constants import HUMIDITY
try: try:
return int(self.data.get(HUMIDITY)) return int(self.data.get(HUMIDITY))
except (ValueError, TypeError): except (ValueError, TypeError):
@ -529,7 +596,7 @@ class BrData:
@property @property
def visibility(self): def visibility(self):
"""Return the visibility, or None.""" """Return the visibility, or None."""
from buienradar.buienradar import VISIBILITY from buienradar.constants import VISIBILITY
try: try:
return int(self.data.get(VISIBILITY)) return int(self.data.get(VISIBILITY))
except (ValueError, TypeError): except (ValueError, TypeError):
@ -538,7 +605,7 @@ class BrData:
@property @property
def wind_speed(self): def wind_speed(self):
"""Return the windspeed, or None.""" """Return the windspeed, or None."""
from buienradar.buienradar import WINDSPEED from buienradar.constants import WINDSPEED
try: try:
return float(self.data.get(WINDSPEED)) return float(self.data.get(WINDSPEED))
except (ValueError, TypeError): except (ValueError, TypeError):
@ -547,7 +614,7 @@ class BrData:
@property @property
def wind_bearing(self): def wind_bearing(self):
"""Return the wind bearing, or None.""" """Return the wind bearing, or None."""
from buienradar.buienradar import WINDAZIMUTH from buienradar.constants import WINDAZIMUTH
try: try:
return int(self.data.get(WINDAZIMUTH)) return int(self.data.get(WINDAZIMUTH))
except (ValueError, TypeError): except (ValueError, TypeError):
@ -556,5 +623,5 @@ class BrData:
@property @property
def forecast(self): def forecast(self):
"""Return the forecast data.""" """Return the forecast data."""
from buienradar.buienradar import FORECAST from buienradar.constants import FORECAST
return self.data.get(FORECAST) return self.data.get(FORECAST)

View File

@ -6,7 +6,8 @@ import voluptuous as vol
from homeassistant.components.weather import ( from homeassistant.components.weather import (
ATTR_FORECAST_CONDITION, ATTR_FORECAST_TEMP, ATTR_FORECAST_TEMP_LOW, ATTR_FORECAST_CONDITION, ATTR_FORECAST_TEMP, ATTR_FORECAST_TEMP_LOW,
ATTR_FORECAST_TIME, PLATFORM_SCHEMA, WeatherEntity, ATTR_FORECAST_TIME, PLATFORM_SCHEMA, WeatherEntity,
ATTR_FORECAST_PRECIPITATION) ATTR_FORECAST_PRECIPITATION, ATTR_FORECAST_WIND_BEARING,
ATTR_FORECAST_WIND_SPEED)
from homeassistant.const import ( from homeassistant.const import (
CONF_LATITUDE, CONF_LONGITUDE, CONF_NAME, TEMP_CELSIUS) CONF_LATITUDE, CONF_LONGITUDE, CONF_NAME, TEMP_CELSIUS)
from homeassistant.helpers import config_validation as cv from homeassistant.helpers import config_validation as cv
@ -104,7 +105,8 @@ class BrWeather(WeatherEntity):
@property @property
def condition(self): def condition(self):
"""Return the current condition.""" """Return the current condition."""
from buienradar.buienradar import (CONDCODE) from buienradar.constants import (CONDCODE)
if self._data and self._data.condition: if self._data and self._data.condition:
ccode = self._data.condition.get(CONDCODE) ccode = self._data.condition.get(CONDCODE)
if ccode: if ccode:
@ -129,13 +131,17 @@ class BrWeather(WeatherEntity):
@property @property
def visibility(self): def visibility(self):
"""Return the current visibility.""" """Return the current visibility in km."""
return self._data.visibility if self._data.visibility is None:
return None
return round(self._data.visibility / 1000, 1)
@property @property
def wind_speed(self): def wind_speed(self):
"""Return the current windspeed.""" """Return the current windspeed in km/h."""
return self._data.wind_speed if self._data.wind_speed is None:
return None
return round(self._data.wind_speed * 3.6, 1)
@property @property
def wind_bearing(self): def wind_bearing(self):
@ -150,24 +156,33 @@ class BrWeather(WeatherEntity):
@property @property
def forecast(self): def forecast(self):
"""Return the forecast array.""" """Return the forecast array."""
from buienradar.buienradar import (CONDITION, CONDCODE, RAIN, DATETIME, from buienradar.constants import (CONDITION, CONDCODE, RAIN, DATETIME,
MIN_TEMP, MAX_TEMP) MIN_TEMP, MAX_TEMP, WINDAZIMUTH,
WINDSPEED)
if not self._forecast:
return None
if self._forecast:
fcdata_out = [] fcdata_out = []
cond = self.hass.data[DATA_CONDITION] cond = self.hass.data[DATA_CONDITION]
if self._data.forecast:
if not self._data.forecast:
return None
for data_in in self._data.forecast: for data_in in self._data.forecast:
# remap keys from external library to # remap keys from external library to
# keys understood by the weather component: # keys understood by the weather component:
data_out = {}
condcode = data_in.get(CONDITION, []).get(CONDCODE) condcode = data_in.get(CONDITION, []).get(CONDCODE)
data_out = {
data_out[ATTR_FORECAST_TIME] = data_in.get(DATETIME) ATTR_FORECAST_TIME: data_in.get(DATETIME),
data_out[ATTR_FORECAST_CONDITION] = cond[condcode] ATTR_FORECAST_CONDITION: cond[condcode],
data_out[ATTR_FORECAST_TEMP_LOW] = data_in.get(MIN_TEMP) ATTR_FORECAST_TEMP_LOW: data_in.get(MIN_TEMP),
data_out[ATTR_FORECAST_TEMP] = data_in.get(MAX_TEMP) ATTR_FORECAST_TEMP: data_in.get(MAX_TEMP),
data_out[ATTR_FORECAST_PRECIPITATION] = data_in.get(RAIN) ATTR_FORECAST_PRECIPITATION: data_in.get(RAIN),
ATTR_FORECAST_WIND_BEARING: data_in.get(WINDAZIMUTH),
ATTR_FORECAST_WIND_SPEED:
round(data_in.get(WINDSPEED) * 3.6, 1)
}
fcdata_out.append(data_out) fcdata_out.append(data_out)

View File

@ -314,7 +314,7 @@ bthomehub5-devicelist==0.1.1
btsmarthub_devicelist==0.1.3 btsmarthub_devicelist==0.1.3
# homeassistant.components.buienradar # homeassistant.components.buienradar
buienradar==0.91 buienradar==1.0.1
# homeassistant.components.caldav # homeassistant.components.caldav
caldav==0.6.1 caldav==0.6.1