Skip to content

Commit

Permalink
Enhance Hourly Forecast (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
GuyKh authored Mar 12, 2023
1 parent f66c3fb commit 73b621d
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 33 deletions.
36 changes: 18 additions & 18 deletions custom_components/ims/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,23 +91,23 @@

# Based on https://ims.gov.il/en/wind_directions
WIND_DIRECTIONS = {
"1": float(180),
"2": float(203),
"3": float(225),
"4": float(248),
"5": float(270),
"6": float(293),
"7": float(315),
"8": float(338),
"9": float(360),
"10": float(23),
"11": float(45),
"12": float(68),
"13": float(90),
"14": float(113),
"15": float(135),
"16": float(158),
"17": float(180),
1: float(180),
2: float(203),
3: float(225),
4: float(248),
5: float(270),
6: float(293),
7: float(315),
8: float(338),
9: float(360),
10: float(23),
11: float(45),
12: float(68),
13: float(90),
14: float(113),
15: float(135),
16: float(158),
17: float(180),
}

# Based on https://ims.gov.il/en/weather_codes
Expand All @@ -121,7 +121,7 @@
"1160": ATTR_CONDITION_FOG,
"1220": ATTR_CONDITION_PARTLYCLOUDY,
"1230": ATTR_CONDITION_CLOUDY,
"1250": ATTR_CONDITION_CLEAR_NIGHT,
"1250": ATTR_CONDITION_SUNNY,
"1260": ATTR_CONDITION_WINDY,
"1270": ATTR_CONDITION_SUNNY,
"1300": ATTR_CONDITION_HAIL,
Expand Down
4 changes: 2 additions & 2 deletions custom_components/ims/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
"documentation": "https://github.com/t0mer/ims-custom-component",
"iot_class": "cloud_polling",
"issue_tracker": "https://github.com/t0mer/ims-custom-component/issues",
"requirements": ["weatheril>=0.18.0"],
"version": "0.1.1"
"requirements": ["weatheril>=0.26.0"],
"version": "0.1.4"
}
21 changes: 9 additions & 12 deletions custom_components/ims/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,7 @@ def name(self):

@property
def state(self):
return WeatherIL.get_location_name_by_id(
SimpleNamespace(language=self._language), self._city
)
return self._weather_coordinator.data.current_weather.location

@property
def icon(self):
Expand All @@ -158,9 +156,7 @@ async def async_update(self):
await self._hass.async_add_executor_job(self.update)

def update(self):
self._state = WeatherIL.get_location_name_by_id(
SimpleNamespace(language=self._language), self._city
)
self._state = self._weather_coordinator.data.current_weather.location


class ImsTemprature(Entity):
Expand Down Expand Up @@ -296,15 +292,16 @@ def name(self):
def state(self):
try:
if self._language == "he":
if self._weather_coordinator.data.current_weather.rain == None:
return "לא יורד"
else:
return "יורד"
else:
if self._weather_coordinator.data.current_weather.rain == None:
if self._weather_coordinator.data.current_weather.rain:
return "Not Raining"
else:
return "לא יורד"
else:
if self._weather_coordinator.data.current_weather.rain:
return "Raining"
else:
return "Not Raining"

except:
pass

Expand Down
9 changes: 8 additions & 1 deletion custom_components/ims/weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
ATTR_FORECAST_NATIVE_TEMP,
ATTR_FORECAST_TIME,
ATTR_FORECAST_NATIVE_TEMP_LOW,
ATTR_FORECAST_NATIVE_WIND_SPEED,
ATTR_FORECAST_WIND_BEARING,
ATTR_FORECAST_NATIVE_PRECIPITATION,
WeatherEntity,
)

Expand Down Expand Up @@ -234,7 +237,7 @@ def native_wind_speed(self):
def wind_bearing(self):
"""Return the wind bearing."""
return WIND_DIRECTIONS[
self._weather_coordinator.data.current_weather.json["wind_direction_id"]
int(self._weather_coordinator.data.current_weather.json["wind_direction_id"])
]

@property
Expand Down Expand Up @@ -283,6 +286,10 @@ def forecast(self):
).isoformat(),
ATTR_FORECAST_NATIVE_TEMP: hour.temperature,
ATTR_FORECAST_CONDITION: WEATHER_CODE_TO_CONDITION[hour.weather_code],
ATTR_FORECAST_NATIVE_PRECIPITATION: hour.rain,
ATTR_FORECAST_WIND_BEARING: WIND_DIRECTIONS[hour.wind_direction_id],
ATTR_FORECAST_NATIVE_WIND_SPEED: hour.wind_speed

}
)
return data
Expand Down

0 comments on commit 73b621d

Please sign in to comment.