Skip to content

Commit f8a1c98

Browse files
authored
Merge pull request #29 from golles/add_relative_humidity
Add relative humidity sensor
2 parents 2dca772 + 4c07da6 commit f8a1c98

File tree

2 files changed

+24
-51
lines changed

2 files changed

+24
-51
lines changed

custom_components/knmi/const.py

+20-47
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
"""Constants for knmi."""
22

33
from homeassistant.const import (
4-
DEVICE_CLASS_TEMPERATURE,
4+
PERCENTAGE,
55
TEMP_CELSIUS,
66
)
77
from homeassistant.components.binary_sensor import (
8-
DEVICE_CLASS_SAFETY,
8+
BinarySensorDeviceClass,
99
)
1010
from homeassistant.components.sensor import (
11-
STATE_CLASS_MEASUREMENT,
12-
ATTR_STATE_CLASS,
11+
SensorDeviceClass,
12+
SensorStateClass,
1313
)
1414
from homeassistant.components.weather import (
1515
ATTR_CONDITION_CLEAR_NIGHT,
@@ -34,6 +34,9 @@
3434
VERSION = "1.1.9"
3535
ATTRIBUTION = "KNMI Weergegevens via https://weerlive.nl/"
3636

37+
# Defaults
38+
DEFAULT_NAME = NAME
39+
3740
# Platforms.
3841
BINARY_SENSOR = "binary_sensor"
3942
SENSOR = "sensor"
@@ -47,7 +50,7 @@
4750
"unit": "",
4851
"icon": "mdi:alert",
4952
"key": "alarm",
50-
"device_class": DEVICE_CLASS_SAFETY,
53+
"device_class": BinarySensorDeviceClass.SAFETY,
5154
"attributes": [
5255
{
5356
"name": "Waarschuwing",
@@ -74,32 +77,27 @@
7477
"unit_of_measurement": TEMP_CELSIUS,
7578
"icon": "mdi:thermometer",
7679
"key": "dauwp",
77-
"device_class": DEVICE_CLASS_TEMPERATURE,
78-
"attributes": [
79-
{
80-
"name": ATTR_STATE_CLASS,
81-
"value": STATE_CLASS_MEASUREMENT,
82-
},
83-
],
80+
"device_class": SensorDeviceClass.TEMPERATURE,
81+
"state_class": SensorStateClass.MEASUREMENT,
8482
},
8583
{
8684
"name": "Gevoelstemperatuur",
8785
"unit_of_measurement": TEMP_CELSIUS,
8886
"icon": "mdi:thermometer",
8987
"key": "gtemp",
90-
"device_class": DEVICE_CLASS_TEMPERATURE,
91-
"attributes": [
92-
{
93-
"name": ATTR_STATE_CLASS,
94-
"value": STATE_CLASS_MEASUREMENT,
95-
},
96-
],
88+
"device_class": SensorDeviceClass.TEMPERATURE,
89+
"state_class": SensorStateClass.MEASUREMENT,
90+
},
91+
{
92+
"name": "Relatieve luchtvochtigheid",
93+
"unit_of_measurement": PERCENTAGE,
94+
"icon": "mdi:water-percent",
95+
"key": "lv",
96+
"device_class": SensorDeviceClass.HUMIDITY,
97+
"state_class": SensorStateClass.MEASUREMENT,
9798
},
9899
]
99100

100-
# Defaults
101-
DEFAULT_NAME = NAME
102-
103101
# Map weather conditions from KNMI to HA.
104102
CONDITIONS_MAP = {
105103
"zonnig": ATTR_CONDITION_SUNNY,
@@ -117,28 +115,3 @@
117115
"helderenacht": ATTR_CONDITION_CLEAR_NIGHT,
118116
"wolkennacht": ATTR_CONDITION_CLOUDY,
119117
}
120-
121-
# Map wind direction from KNMI string to number.
122-
WIND_DIRECTION_MAP = {
123-
"VAR": None,
124-
"N": 360,
125-
"Noord": 360,
126-
"NNO": 22.5,
127-
"NO": 45,
128-
"ONO": 67.5,
129-
"O": 90,
130-
"Oost": 90,
131-
"OZO": 112.5,
132-
"ZO": 135,
133-
"ZZO": 157.5,
134-
"Z": 180,
135-
"Zuid": 180,
136-
"ZZW": 202.5,
137-
"ZW": 225,
138-
"WZW": 247.5,
139-
"W": 270,
140-
"West": 270,
141-
"WNW": 292.5,
142-
"NW": 315,
143-
"NNW": 337.5,
144-
}

custom_components/knmi/weather.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
CONF_NAME,
1717
)
1818

19-
from .const import CONDITIONS_MAP, DEFAULT_NAME, DOMAIN, WIND_DIRECTION_MAP
19+
from .const import CONDITIONS_MAP, DEFAULT_NAME, DOMAIN
2020
from .entity import KnmiEntity
2121

2222

@@ -77,7 +77,7 @@ def native_wind_speed(self):
7777
def wind_bearing(self):
7878
"""Return the wind direction."""
7979
if super().get_data("windr") is not None:
80-
return WIND_DIRECTION_MAP[super().get_data("windr")]
80+
return int(super().get_data("windrgr"))
8181
return None
8282

8383
@property
@@ -101,8 +101,8 @@ def forecast(self):
101101
else None
102102
)
103103
wind_bearing = (
104-
WIND_DIRECTION_MAP[super().get_data(f"d{i}windr")]
105-
if super().get_data(f"d{i}windr") is not None
104+
int(super().get_data(f"d{i}windrgr"))
105+
if super().get_data(f"d{i}windrgr") is not None
106106
else None
107107
)
108108
temp_low = (

0 commit comments

Comments
 (0)