Skip to content

Commit

Permalink
Update status calculation formulae
Browse files Browse the repository at this point in the history
  • Loading branch information
Limych committed Oct 10, 2024
1 parent 90f83c4 commit 5970277
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
4 changes: 3 additions & 1 deletion custom_components/snowtire/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
2 changes: 1 addition & 1 deletion custom_components/snowtire/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down
2 changes: 1 addition & 1 deletion custom_components/snowtire/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
"requirements": [
"pip>=21.3.1"
],
"version": "1.5.0"
"version": "1.5.1-alpha"
}
14 changes: 14 additions & 0 deletions tests/test_binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 5970277

Please sign in to comment.