Skip to content

Commit 73f060c

Browse files
v2024.4.4 fix #52
1 parent 84ef513 commit 73f060c

10 files changed

+16
-15
lines changed
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.

custom_components/daily/const.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
DOMAIN = "daily"
44
NAME = "Daily Sensor"
55
DOMAIN_DATA = f"{DOMAIN}_data"
6-
VERSION = "2024.4.3"
6+
VERSION = "2024.4.4"
77
COORDINATOR = "coordinator"
88
ISSUE_URL = "https://github.com/jeroenterheerdt/HADailySensor/issues"
99

custom_components/daily/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010
"homekit": {},
1111
"dependencies": [],
1212
"codeowners": ["@jeroenterheerdt"],
13-
"version": "2024.4.3"
13+
"version": "2024.4.4"
1414
}

custom_components/daily/sensor.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
"""Sensor platform for Daily Sensor."""
2+
23
import asyncio
34
import logging
45
from statistics import median, stdev, variance, StatisticsError
56
from datetime import datetime
67

8+
from homeassistant.const import STATE_UNAVAILABLE, STATE_UNKNOWN
79
from homeassistant.core import callback, Event
810

911
# from homeassistant.helpers import entity_registry as er
@@ -96,29 +98,20 @@ def _handle_update(self, event: Event):
9698
input_state = self.hass.states.get(self.coordinator.input_sensor)
9799
state_minmax_changed = False
98100
try:
99-
if input_state is not None:
100-
if input_state.state is None:
101-
the_val = self.convert_to_float(input_state)
102-
else:
103-
the_val = self.convert_to_float(input_state.state)
101+
if input_state not in (None, STATE_UNKNOWN, STATE_UNAVAILABLE):
102+
the_val = self.convert_to_float(input_state)
104103
# apply the operation and update self._state
105104
if self.coordinator.operation == CONF_SUM:
106105
if self._state is None:
107106
self._state = the_val
108107
else:
109108
self._state = self._state + the_val
110109
elif self.coordinator.operation == CONF_MAX:
111-
if self._state is None:
112-
self._state = the_val
113-
state_minmax_changed = True
114-
elif the_val > self._state:
110+
if self._state is None or the_val > self._state:
115111
self._state = the_val
116112
state_minmax_changed = True
117113
elif self.coordinator.operation == CONF_MIN:
118-
if self._state is None:
119-
self._state = the_val
120-
state_minmax_changed = True
121-
elif the_val < self._state:
114+
if self._state is None or the_val < self._state:
122115
self._state = the_val
123116
state_minmax_changed = True
124117
elif self.coordinator.operation == CONF_MEAN:
@@ -141,6 +134,14 @@ def _handle_update(self, event: Event):
141134
if state_minmax_changed:
142135
self._occurrence = datetime.now()
143136
self.hass.add_job(self.async_write_ha_state)
137+
else:
138+
# sensor is unknown at startup, state which comes after is considered as initial state
139+
_LOGGER.debug(
140+
"Initial state for {} is {}".format(
141+
self.coordinator.input_sensor, input_state
142+
)
143+
)
144+
return
144145
except ValueError:
145146
_LOGGER.error(
146147
"unable to convert to float. Please check the source sensor ({}) is available.".format(

0 commit comments

Comments
 (0)