Skip to content

Commit 3d69a11

Browse files
committed
Visibility is now a number instead of a string
Wind direction mapping
1 parent 710d5d8 commit 3d69a11

File tree

3 files changed

+37
-12
lines changed

3 files changed

+37
-12
lines changed

custom_components/knmi/const.py

+27-6
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,27 @@
1313
ATTR_CONDITION_SUNNY,
1414
)
1515

16-
# Base component constants
16+
# Base component constants.
1717
NAME = "KNMI"
1818
DOMAIN = "knmi"
19-
VERSION = "1.0.0"
19+
VERSION = "1.0.1"
2020
ATTRIBUTION = "KNMI Weergegevens via https://weerlive.nl/"
2121

22-
# Icons
22+
# Icons.
2323
BINARY_SENSOR_ALARM_ICON = "mdi:alert"
2424

25-
# Sensor names
25+
# Sensor names.
2626
BINARY_SENSOR_ALARM_NAME = "Waarschuwing"
2727

28-
# Platforms
28+
# Platforms.
2929
BINARY_SENSOR = "binary_sensor"
3030
WEATHER = "weather"
3131
PLATFORMS = [BINARY_SENSOR, WEATHER]
3232

3333
# Defaults
3434
DEFAULT_NAME = NAME
3535

36+
# Map weather conditions from KNMI to HA.
3637
CONDITIONS_MAP = {
3738
"zonnig": ATTR_CONDITION_SUNNY,
3839
"bliksem": ATTR_CONDITION_LIGHTNING,
@@ -47,4 +48,24 @@
4748
"nachtmist": ATTR_CONDITION_FOG,
4849
"helderenacht": ATTR_CONDITION_CLEAR_NIGHT,
4950
"wolkennacht": ATTR_CONDITION_CLOUDY,
50-
}
51+
}
52+
53+
# Map wind direction from KNMI string to number.
54+
WIND_DIRECTION_MAP = {
55+
"N": 360,
56+
"NNO": 22.5,
57+
"NO": 45,
58+
"ONO": 67.5,
59+
"O": 90,
60+
"OZO": 112.5,
61+
"ZO": 135,
62+
"ZZO": 157.5,
63+
"Z": 180,
64+
"ZZW": 202.5,
65+
"ZW": 225,
66+
"WZW": 247.5,
67+
"W": 270,
68+
"WNW": 292.5,
69+
"NW": 315,
70+
"NNW": 337.5,
71+
}

custom_components/knmi/manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"documentation": "https://github.com/golles/ha-knmi/",
55
"iot_class": "cloud_polling",
66
"issue_tracker": "https://github.com/golles/ha-knmi//issues",
7-
"version": "1.0.0",
7+
"version": "1.0.1",
88
"config_flow": true,
99
"codeowners": [
1010
"@golles"

custom_components/knmi/weather.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
TEMP_CELSIUS,
1717
)
1818

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

2222

@@ -73,12 +73,12 @@ def wind_speed(self):
7373
@property
7474
def wind_bearing(self):
7575
"""Return the wind direction."""
76-
return self.coordinator.data["windr"]
76+
return WIND_DIRECTION_MAP[self.coordinator.data["windr"]]
7777

7878
@property
7979
def visibility(self):
8080
"""Return the wind direction."""
81-
return self.coordinator.data["zicht"]
81+
return float(self.coordinator.data["zicht"])
8282

8383
@property
8484
def forecast(self):
@@ -90,13 +90,17 @@ def forecast(self):
9090
date = today + timedelta(days=i)
9191
nextDay = {
9292
ATTR_FORECAST_TIME: date.isoformat(),
93-
ATTR_FORECAST_CONDITION: CONDITIONS_MAP[self.coordinator.data[f"d{i}weer"]],
93+
ATTR_FORECAST_CONDITION: CONDITIONS_MAP[
94+
self.coordinator.data[f"d{i}weer"]
95+
],
9496
ATTR_FORECAST_TEMP_LOW: float(self.coordinator.data[f"d{i}tmin"]),
9597
ATTR_FORECAST_TEMP: float(self.coordinator.data[f"d{i}tmax"]),
9698
ATTR_FORECAST_PRECIPITATION: float(
9799
self.coordinator.data[f"d{i}neerslag"]
98100
),
99-
ATTR_FORECAST_WIND_BEARING: self.coordinator.data[f"d{i}windr"],
101+
ATTR_FORECAST_WIND_BEARING: WIND_DIRECTION_MAP[
102+
self.coordinator.data[f"d{i}windr"]
103+
],
100104
ATTR_FORECAST_WIND_SPEED: float(self.coordinator.data[f"d{i}windkmh"]),
101105
}
102106
forecast.append(nextDay)

0 commit comments

Comments
 (0)