From a4d27678507eee3e01989c08a4646b867ec53edd Mon Sep 17 00:00:00 2001 From: Sander Date: Thu, 29 Feb 2024 09:56:25 +0000 Subject: [PATCH 1/3] Fix hourly precipitation and add apparent temperature in weather entity --- README.md | 20 ++++++++++---------- custom_components/knmi/weather.py | 8 +++++++- tests/test_weather.py | 19 ++++++++++++------- 3 files changed, 29 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index b57e964..b7a5dfd 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/custom_components/knmi/weather.py b/custom_components/knmi/weather.py index 9ac763e..c9665ac 100644 --- a/custom_components/knmi/weather.py +++ b/custom_components/knmi/weather.py @@ -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, @@ -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.""" @@ -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( ["uur_verw", i, "neersl"] # Millimeter. ), ATTR_FORECAST_WIND_BEARING: self.coordinator.get_value( diff --git a/tests/test_weather.py b/tests/test_weather.py index 17daa8e..3ee6351 100644 --- a/tests/test_weather.py +++ b/tests/test_weather.py @@ -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, @@ -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() @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 From 22f92c82e26ea894ffccb852a7ba2e668a6db92e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 11 Mar 2024 18:29:12 +0000 Subject: [PATCH 2/3] Bump softprops/action-gh-release from 1 to 2 Bumps [softprops/action-gh-release](https://github.com/softprops/action-gh-release) from 1 to 2. - [Release notes](https://github.com/softprops/action-gh-release/releases) - [Changelog](https://github.com/softprops/action-gh-release/blob/master/CHANGELOG.md) - [Commits](https://github.com/softprops/action-gh-release/compare/v1...v2) --- updated-dependencies: - dependency-name: softprops/action-gh-release dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/release.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index d675f1a..c5a1f35 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -12,7 +12,7 @@ jobs: - name: Checkout uses: actions/checkout@v4 - name: Release - uses: softprops/action-gh-release@v1 + uses: softprops/action-gh-release@v2 with: body: | If you like this integration, please star this repo to show your appreciation - it makes me very happy! From 1c1e3d2751fbb758534aed0f9783c1026aaba1fc Mon Sep 17 00:00:00 2001 From: Sander Date: Sun, 17 Mar 2024 13:43:21 +0000 Subject: [PATCH 3/3] Update a config entry with `async_update_entry` --- custom_components/knmi/__init__.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/custom_components/knmi/__init__.py b/custom_components/knmi/__init__.py index 7093ecc..ba7ef1e 100644 --- a/custom_components/knmi/__init__.py +++ b/custom_components/knmi/__init__.py @@ -96,10 +96,7 @@ async def async_migrate_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> _LOGGER.debug("Migrating from version %s", config_entry.version) if config_entry.version == 1: - # Replace with the following line after 2024.3. - # hass.config_entries.async_update_entry(config_entry, version=2) - # See https://developers.home-assistant.io/blog/2024/02/12/async_update_entry/ - config_entry.version = 2 + hass.config_entries.async_update_entry(config_entry, version=2) entity_registry = er.async_get(hass) existing_entries = er.async_entries_for_config_entry(