Skip to content

Commit 3b71fe3

Browse files
committed
feat: Enhnaced the wind direciton function agian
1 parent fa1e815 commit 3b71fe3

File tree

1 file changed

+18
-20
lines changed
  • homeassistant/components/weatherflow_cloud

1 file changed

+18
-20
lines changed

homeassistant/components/weatherflow_cloud/sensor.py

+18-20
Original file line numberDiff line numberDiff line change
@@ -47,26 +47,24 @@
4747
from .const import DOMAIN
4848
from .entity import WeatherFlowCloudEntity
4949

50-
51-
def _get_wind_direction_icon(degree: int) -> str:
52-
"""Get the wind direction icon based on the degree."""
53-
54-
if degree is None or not isinstance(degree, (int, float)):
55-
raise ValueError("Degree must be a number")
56-
57-
# Use integer division to divide into correct sector
58-
sector = int(((degree % 360) + 22.5) / 45) % 8
59-
60-
return [
61-
"mdi:arrow-up", # N (337.5 - 22.5)
62-
"mdi:arrow-top-right", # NE (22.5 - 67.5)
63-
"mdi:arrow-right", # E (67.5 - 112.5)
64-
"mdi:arrow-bottom-right", # SE (112.5 - 157.5)
65-
"mdi:arrow-down", # S (157.5 - 202.5)
66-
"mdi:arrow-bottom-left", # SW (202.5 - 247.5)
67-
"mdi:arrow-left", # W (247.5 - 292.5)
68-
"mdi:arrow-top-left", # NW (292.5 - 337.5)
69-
][sector]
50+
DIRECTION_MAP = {
51+
0: "mdi:arrow-up", # N (337.5° - 22.5°)
52+
1: "mdi:arrow-top-right", # NE (22.5° - 67.5°)
53+
2: "mdi:arrow-right", # E (67.5° - 112.5°)
54+
3: "mdi:arrow-bottom-right", # SE (112.5° - 157.5°)
55+
4: "mdi:arrow-down", # S (157.5° - 202.5°)
56+
5: "mdi:arrow-bottom-left", # SW (202.5° - 247.5°)
57+
6: "mdi:arrow-left", # W (247.5° - 292.5°)
58+
7: "mdi:arrow-top-left", # NW (292.5° - 337.5°)
59+
}
60+
61+
62+
def _get_wind_direction_icon(wind_angle: float | None = None) -> str:
63+
"""Get the wind direction icon based on the wind angle."""
64+
if wind_angle is None:
65+
return "mdi:compass"
66+
sector = int(((wind_angle % 360) + 22.5) / 45) % 8
67+
return DIRECTION_MAP[sector]
7068

7169

7270
@dataclass(frozen=True, kw_only=True)

0 commit comments

Comments
 (0)