Map accuweather weather condition codes once (#98509)
Map accuweather condition codes once
This commit is contained in:
parent
8ed7d2dd3e
commit
b1053e8077
2 changed files with 8 additions and 12 deletions
|
@ -50,3 +50,8 @@ CONDITION_CLASSES: Final[dict[str, list[int]]] = {
|
|||
ATTR_CONDITION_SUNNY: [1, 2, 5],
|
||||
ATTR_CONDITION_WINDY: [32],
|
||||
}
|
||||
CONDITION_MAP = {
|
||||
cond_code: cond_ha
|
||||
for cond_ha, cond_codes in CONDITION_CLASSES.items()
|
||||
for cond_code in cond_codes
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ from .const import (
|
|||
ATTR_SPEED,
|
||||
ATTR_VALUE,
|
||||
ATTRIBUTION,
|
||||
CONDITION_CLASSES,
|
||||
CONDITION_MAP,
|
||||
DOMAIN,
|
||||
)
|
||||
|
||||
|
@ -80,14 +80,7 @@ class AccuWeatherEntity(
|
|||
@property
|
||||
def condition(self) -> str | None:
|
||||
"""Return the current condition."""
|
||||
try:
|
||||
return [
|
||||
k
|
||||
for k, v in CONDITION_CLASSES.items()
|
||||
if self.coordinator.data["WeatherIcon"] in v
|
||||
][0]
|
||||
except IndexError:
|
||||
return None
|
||||
return CONDITION_MAP.get(self.coordinator.data["WeatherIcon"])
|
||||
|
||||
@property
|
||||
def cloud_coverage(self) -> float:
|
||||
|
@ -177,9 +170,7 @@ class AccuWeatherEntity(
|
|||
],
|
||||
ATTR_FORECAST_UV_INDEX: item["UVIndex"][ATTR_VALUE],
|
||||
ATTR_FORECAST_WIND_BEARING: item["WindDay"][ATTR_DIRECTION]["Degrees"],
|
||||
ATTR_FORECAST_CONDITION: [
|
||||
k for k, v in CONDITION_CLASSES.items() if item["IconDay"] in v
|
||||
][0],
|
||||
ATTR_FORECAST_CONDITION: CONDITION_MAP.get(item["IconDay"]),
|
||||
}
|
||||
for item in self.coordinator.data[ATTR_FORECAST]
|
||||
]
|
||||
|
|
Loading…
Add table
Reference in a new issue