Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix hourly precipitation and add apparent temperature in weather entity #127

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,16 @@ Daily forecast attributes:

Hourly forecast attributes:

| Attribute | Notes |
| ------------------------- | ------------------------------------------------------------- |
| datetime | Times in UTC, frontend will convert this into your local time |
| condition | |
| temperature | |
| precipitation_probability | in millimeters |
| wind_bearing | |
| wind_speed | |
| wind_speed_bft | Not officially supported, but nice addition |
| solar_irradiance | Not officially supported, but nice addition |
| Attribute | Notes |
| ---------------- | ------------------------------------------------------------- |
| datetime | Times in UTC, frontend will convert this into your local time |
| condition | |
| temperature | |
| precipitation | in millimeters |
| wind_bearing | |
| wind_speed | |
| wind_speed_bft | Not officially supported, but nice addition |
| solar_irradiance | Not officially supported, but nice addition |

## Examples

Expand Down
8 changes: 7 additions & 1 deletion custom_components/knmi/weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
ATTR_CONDITION_SNOWY,
ATTR_CONDITION_SUNNY,
ATTR_FORECAST_CONDITION,
ATTR_FORECAST_PRECIPITATION,
ATTR_FORECAST_PRECIPITATION_PROBABILITY,
ATTR_FORECAST_TEMP,
ATTR_FORECAST_TEMP_LOW,
Expand Down Expand Up @@ -125,6 +126,11 @@ def native_temperature(self) -> float | None:
"""Return the temperature in native units."""
return self.coordinator.get_value(["liveweer", 0, "temp"])

@property
def native_apparent_temperature(self) -> float | None:
"""Return the apparent temperature in native units."""
return self.coordinator.get_value(["liveweer", 0, "gtemp"])

@property
def native_dew_point(self) -> float | None:
"""Return the dew point temperature in native units."""
Expand Down Expand Up @@ -205,7 +211,7 @@ async def async_forecast_hourly(self) -> list[Forecast] | None:
self.coordinator.get_value(["uur_verw", i, "image"])
),
ATTR_FORECAST_TEMP: self.coordinator.get_value(["uur_verw", i, "temp"]),
ATTR_FORECAST_PRECIPITATION_PROBABILITY: self.coordinator.get_value(
ATTR_FORECAST_PRECIPITATION: self.coordinator.get_value(
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actual fix for #126

["uur_verw", i, "neersl"] # Millimeter.
),
ATTR_FORECAST_WIND_BEARING: self.coordinator.get_value(
Expand Down
19 changes: 12 additions & 7 deletions tests/test_weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
ATTR_CONDITION_SNOWY,
ATTR_CONDITION_SUNNY,
ATTR_FORECAST_CONDITION,
ATTR_FORECAST_PRECIPITATION,
ATTR_FORECAST_PRECIPITATION_PROBABILITY,
ATTR_FORECAST_TEMP,
ATTR_FORECAST_TEMP_LOW,
ATTR_FORECAST_TIME,
ATTR_FORECAST_WIND_BEARING,
ATTR_FORECAST_WIND_SPEED,
ATTR_WEATHER_APPARENT_TEMPERATURE,
ATTR_WEATHER_DEW_POINT,
ATTR_WEATHER_HUMIDITY,
ATTR_WEATHER_PRESSURE,
Expand Down Expand Up @@ -97,6 +99,9 @@ async def test_state(hass: HomeAssistant, mocked_data):
assert Decimal(state.attributes.get(ATTR_WEATHER_WIND_BEARING)) == 226
assert Decimal(state.attributes.get(ATTR_WEATHER_WIND_SPEED)) == Decimal(29.1)
assert Decimal(state.attributes.get(ATTR_WEATHER_DEW_POINT)) == Decimal(10.1)
assert Decimal(state.attributes.get(ATTR_WEATHER_APPARENT_TEMPERATURE)) == Decimal(
6.8
)

assert await config_entry.async_unload(hass)
await hass.async_block_till_done()
Expand Down Expand Up @@ -179,7 +184,7 @@ async def test_async_forecast_hourly(hass: HomeAssistant, mocked_data):
assert str(forecast[0][ATTR_FORECAST_TIME]) == "2024-02-14 23:00:00+01:00"
assert forecast[0][ATTR_FORECAST_CONDITION] == "cloudy"
assert forecast[0][ATTR_FORECAST_TEMP] == 10
assert forecast[0][ATTR_FORECAST_PRECIPITATION_PROBABILITY] == 0
assert forecast[0][ATTR_FORECAST_PRECIPITATION] == 0
assert forecast[0][ATTR_FORECAST_WIND_BEARING] == 231
assert forecast[0][ATTR_FORECAST_WIND_SPEED] == 21
assert forecast[0]["wind_speed_bft"] == 4
Expand All @@ -188,7 +193,7 @@ async def test_async_forecast_hourly(hass: HomeAssistant, mocked_data):
assert str(forecast[3][ATTR_FORECAST_TIME]) == "2024-02-15 02:00:00+01:00"
assert forecast[3][ATTR_FORECAST_CONDITION] == "cloudy"
assert forecast[3][ATTR_FORECAST_TEMP] == 10
assert forecast[3][ATTR_FORECAST_PRECIPITATION_PROBABILITY] == 0
assert forecast[3][ATTR_FORECAST_PRECIPITATION] == 0
assert forecast[3][ATTR_FORECAST_WIND_BEARING] == 226
assert forecast[3][ATTR_FORECAST_WIND_SPEED] == 18
assert forecast[3]["wind_speed_bft"] == 3
Expand All @@ -197,7 +202,7 @@ async def test_async_forecast_hourly(hass: HomeAssistant, mocked_data):
assert str(forecast[5][ATTR_FORECAST_TIME]) == "2024-02-15 04:00:00+01:00"
assert forecast[5][ATTR_FORECAST_CONDITION] == "cloudy"
assert forecast[5][ATTR_FORECAST_TEMP] == 10
assert forecast[5][ATTR_FORECAST_PRECIPITATION_PROBABILITY] == 0
assert forecast[5][ATTR_FORECAST_PRECIPITATION] == 0
assert forecast[5][ATTR_FORECAST_WIND_BEARING] == 219
assert forecast[5][ATTR_FORECAST_WIND_SPEED] == 18
assert forecast[5]["wind_speed_bft"] == 3
Expand All @@ -206,7 +211,7 @@ async def test_async_forecast_hourly(hass: HomeAssistant, mocked_data):
assert str(forecast[8][ATTR_FORECAST_TIME]) == "2024-02-15 07:00:00+01:00"
assert forecast[8][ATTR_FORECAST_CONDITION] == "pouring"
assert forecast[8][ATTR_FORECAST_TEMP] == 10
assert Decimal(forecast[8][ATTR_FORECAST_PRECIPITATION_PROBABILITY]) == Decimal(0.9)
assert Decimal(forecast[8][ATTR_FORECAST_PRECIPITATION]) == Decimal(0.9)
assert forecast[8][ATTR_FORECAST_WIND_BEARING] == 196
assert forecast[8][ATTR_FORECAST_WIND_SPEED] == 14
assert forecast[8]["wind_speed_bft"] == 3
Expand All @@ -215,7 +220,7 @@ async def test_async_forecast_hourly(hass: HomeAssistant, mocked_data):
assert str(forecast[13][ATTR_FORECAST_TIME]) == "2024-02-15 12:00:00+01:00"
assert forecast[13][ATTR_FORECAST_CONDITION] == "cloudy"
assert forecast[13][ATTR_FORECAST_TEMP] == 12
assert forecast[13][ATTR_FORECAST_PRECIPITATION_PROBABILITY] == 0
assert forecast[13][ATTR_FORECAST_PRECIPITATION] == 0
assert forecast[13][ATTR_FORECAST_WIND_BEARING] == 206
assert forecast[13][ATTR_FORECAST_WIND_SPEED] == 14
assert forecast[13]["wind_speed_bft"] == 3
Expand All @@ -224,7 +229,7 @@ async def test_async_forecast_hourly(hass: HomeAssistant, mocked_data):
assert str(forecast[18][ATTR_FORECAST_TIME]) == "2024-02-15 17:00:00+01:00"
assert forecast[18][ATTR_FORECAST_CONDITION] == "cloudy"
assert forecast[18][ATTR_FORECAST_TEMP] == 14
assert forecast[18][ATTR_FORECAST_PRECIPITATION_PROBABILITY] == 0
assert forecast[18][ATTR_FORECAST_PRECIPITATION] == 0
assert forecast[18][ATTR_FORECAST_WIND_BEARING] == 168
assert forecast[18][ATTR_FORECAST_WIND_SPEED] == 14
assert forecast[18]["wind_speed_bft"] == 3
Expand All @@ -233,7 +238,7 @@ async def test_async_forecast_hourly(hass: HomeAssistant, mocked_data):
assert str(forecast[23][ATTR_FORECAST_TIME]) == "2024-02-15 22:00:00+01:00"
assert forecast[23][ATTR_FORECAST_CONDITION] == "cloudy"
assert forecast[23][ATTR_FORECAST_TEMP] == 12
assert forecast[23][ATTR_FORECAST_PRECIPITATION_PROBABILITY] == 0
assert forecast[23][ATTR_FORECAST_PRECIPITATION] == 0
assert forecast[23][ATTR_FORECAST_WIND_BEARING] == 162
assert forecast[23][ATTR_FORECAST_WIND_SPEED] == 18
assert forecast[23]["wind_speed_bft"] == 3
Expand Down