Skip to content

Commit

Permalink
v2024.4.4 fix #52
Browse files Browse the repository at this point in the history
  • Loading branch information
jeroenterheerdt committed Jun 5, 2024
1 parent 84ef513 commit 73f060c
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 15 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion custom_components/daily/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
DOMAIN = "daily"
NAME = "Daily Sensor"
DOMAIN_DATA = f"{DOMAIN}_data"
VERSION = "2024.4.3"
VERSION = "2024.4.4"
COORDINATOR = "coordinator"
ISSUE_URL = "https://github.com/jeroenterheerdt/HADailySensor/issues"

Expand Down
2 changes: 1 addition & 1 deletion custom_components/daily/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
"homekit": {},
"dependencies": [],
"codeowners": ["@jeroenterheerdt"],
"version": "2024.4.3"
"version": "2024.4.4"
}
27 changes: 14 additions & 13 deletions custom_components/daily/sensor.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
"""Sensor platform for Daily Sensor."""

import asyncio
import logging
from statistics import median, stdev, variance, StatisticsError
from datetime import datetime

from homeassistant.const import STATE_UNAVAILABLE, STATE_UNKNOWN
from homeassistant.core import callback, Event

# from homeassistant.helpers import entity_registry as er
Expand Down Expand Up @@ -96,29 +98,20 @@ def _handle_update(self, event: Event):
input_state = self.hass.states.get(self.coordinator.input_sensor)
state_minmax_changed = False
try:
if input_state is not None:
if input_state.state is None:
the_val = self.convert_to_float(input_state)
else:
the_val = self.convert_to_float(input_state.state)
if input_state not in (None, STATE_UNKNOWN, STATE_UNAVAILABLE):
the_val = self.convert_to_float(input_state)
# apply the operation and update self._state
if self.coordinator.operation == CONF_SUM:
if self._state is None:
self._state = the_val
else:
self._state = self._state + the_val
elif self.coordinator.operation == CONF_MAX:
if self._state is None:
self._state = the_val
state_minmax_changed = True
elif the_val > self._state:
if self._state is None or the_val > self._state:
self._state = the_val
state_minmax_changed = True
elif self.coordinator.operation == CONF_MIN:
if self._state is None:
self._state = the_val
state_minmax_changed = True
elif the_val < self._state:
if self._state is None or the_val < self._state:
self._state = the_val
state_minmax_changed = True
elif self.coordinator.operation == CONF_MEAN:
Expand All @@ -141,6 +134,14 @@ def _handle_update(self, event: Event):
if state_minmax_changed:
self._occurrence = datetime.now()
self.hass.add_job(self.async_write_ha_state)
else:
# sensor is unknown at startup, state which comes after is considered as initial state
_LOGGER.debug(
"Initial state for {} is {}".format(
self.coordinator.input_sensor, input_state
)
)
return
except ValueError:
_LOGGER.error(
"unable to convert to float. Please check the source sensor ({}) is available.".format(
Expand Down

0 comments on commit 73f060c

Please sign in to comment.