From 5970277dce4d39c0f4a85348e678cbcaa054fe4b Mon Sep 17 00:00:00 2001 From: Andrey Khrolenok Date: Thu, 10 Oct 2024 22:14:57 +0300 Subject: [PATCH] Update status calculation formulae --- custom_components/snowtire/binary_sensor.py | 4 +++- custom_components/snowtire/const.py | 2 +- custom_components/snowtire/manifest.json | 2 +- tests/test_binary_sensor.py | 14 ++++++++++++++ 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/custom_components/snowtire/binary_sensor.py b/custom_components/snowtire/binary_sensor.py index 7606cd3..c1771d7 100644 --- a/custom_components/snowtire/binary_sensor.py +++ b/custom_components/snowtire/binary_sensor.py @@ -239,7 +239,9 @@ async def async_update(self) -> None: # noqa: PLR0912 temp = sum(temp) / len(temp) _LOGGER.debug("Average temperature: %.1f°C", temp) self._attr_is_on = temp < ( - TEMP_CHANGE + TEMP_ERROR + TEMP_CHANGE + if self._attr_is_on is None + else TEMP_CHANGE + TEMP_ERROR if self._attr_is_on is True else TEMP_CHANGE - TEMP_ERROR ) diff --git a/custom_components/snowtire/const.py b/custom_components/snowtire/const.py index 3726ff4..2b1b754 100644 --- a/custom_components/snowtire/const.py +++ b/custom_components/snowtire/const.py @@ -10,7 +10,7 @@ # Base component constants NAME: Final = "Snowtire Sensor" DOMAIN: Final = "snowtire" -VERSION: Final = "1.5.0" +VERSION: Final = "1.5.1-alpha" ISSUE_URL: Final = "https://github.com/Limych/ha-snowtire/issues" STARTUP_MESSAGE: Final = f""" diff --git a/custom_components/snowtire/manifest.json b/custom_components/snowtire/manifest.json index 80cce72..895f5cf 100644 --- a/custom_components/snowtire/manifest.json +++ b/custom_components/snowtire/manifest.json @@ -14,5 +14,5 @@ "requirements": [ "pip>=21.3.1" ], - "version": "1.5.0" + "version": "1.5.1-alpha" } \ No newline at end of file diff --git a/tests/test_binary_sensor.py b/tests/test_binary_sensor.py index 80be399..39fb777 100644 --- a/tests/test_binary_sensor.py +++ b/tests/test_binary_sensor.py @@ -266,6 +266,20 @@ async def test_async_update(hass: HomeAssistant, default_sensor): assert not default_sensor.is_on assert default_sensor.icon == ICON_SUMMER + hass.states.async_set( + MOCK_WEATHER_ENTITY, + "State", + attributes={ + ATTR_WEATHER_TEMPERATURE: 8, + ATTR_SUPPORTED_FEATURES: WeatherEntityFeature.FORECAST_DAILY, + }, + ) + + await default_sensor.async_update() + assert default_sensor.available + assert not default_sensor.is_on + assert default_sensor.icon == ICON_SUMMER + hass.states.async_set( MOCK_WEATHER_ENTITY, "State",