Skip to content

Commit

Permalink
Fix condition calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
Limych committed May 17, 2024
1 parent 0d3f5cd commit eca4435
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions custom_components/gismeteo/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,8 @@ def condition(self, src=None, mode: str = FORECAST_MODE_HOURLY) -> str | None:
return None
if cld == 0:
if mode == FORECAST_MODE_DAILY or (
src.get(ATTR_FORECAST_TIME, dt_util.now())
< src.get(ATTR_SUNRISE)
src.get(ATTR_SUNRISE)
< src.get(ATTR_FORECAST_TIME, dt_util.now())
< src.get(ATTR_SUNSET)
):
cond = ATTR_CONDITION_SUNNY # Sunshine
Expand Down
10 changes: 10 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
ATTR_FORECAST_PHENOMENON,
ATTR_FORECAST_PRECIPITATION_INTENSITY,
ATTR_FORECAST_PRECIPITATION_TYPE,
ATTR_SUNRISE,
CONDITION_FOG_CLASSES,
FORECAST_MODE_DAILY,
)
Expand All @@ -34,6 +35,7 @@
ATTR_CONDITION_RAINY,
ATTR_CONDITION_SNOWY,
ATTR_CONDITION_SNOWY_RAINY,
ATTR_CONDITION_SUNNY,
ATTR_CONDITION_WINDY,
ATTR_CONDITION_WINDY_VARIANT,
ATTR_FORECAST_CLOUD_COVERAGE,
Expand Down Expand Up @@ -503,9 +505,17 @@ async def test_condition():

data[ATTR_FORECAST_CLOUD_COVERAGE] = 0

assert gismeteo.condition(data) == ATTR_CONDITION_SUNNY
assert gismeteo_d.condition(data) == ATTR_CONDITION_SUNNY

tmp = data[ATTR_SUNRISE]
data[ATTR_SUNRISE] = dt_util.now().replace(hour=23, minute=59, second=59)

assert gismeteo.condition(data) == ATTR_CONDITION_CLEAR_NIGHT
assert gismeteo_d.condition(data) == ATTR_CONDITION_CLEAR_NIGHT

data[ATTR_SUNRISE] = tmp

data[ATTR_FORECAST_CLOUD_COVERAGE] = 1

assert gismeteo.condition(data) == ATTR_CONDITION_PARTLYCLOUDY
Expand Down

0 comments on commit eca4435

Please sign in to comment.