Improve debug log information (#18230)
Added debug log information for when records are purged and added entity_id to existing debug information to identify the entity the debug information is for.pull/18250/head
parent
abf147ed57
commit
46b5b6240f
|
@ -173,12 +173,20 @@ class StatisticsSensor(Entity):
|
||||||
"""Remove states which are older than self._max_age."""
|
"""Remove states which are older than self._max_age."""
|
||||||
now = dt_util.utcnow()
|
now = dt_util.utcnow()
|
||||||
|
|
||||||
|
_LOGGER.debug("%s: purging records older then %s(%s)",
|
||||||
|
self.entity_id, dt_util.as_local(now - self._max_age),
|
||||||
|
self._max_age)
|
||||||
|
|
||||||
while self.ages and (now - self.ages[0]) > self._max_age:
|
while self.ages and (now - self.ages[0]) > self._max_age:
|
||||||
|
_LOGGER.debug("%s: purging record with datetime %s(%s)",
|
||||||
|
self.entity_id, dt_util.as_local(self.ages[0]),
|
||||||
|
(now - self.ages[0]))
|
||||||
self.ages.popleft()
|
self.ages.popleft()
|
||||||
self.states.popleft()
|
self.states.popleft()
|
||||||
|
|
||||||
async def async_update(self):
|
async def async_update(self):
|
||||||
"""Get the latest data and updates the states."""
|
"""Get the latest data and updates the states."""
|
||||||
|
_LOGGER.debug("%s: updating statistics.", self.entity_id)
|
||||||
if self._max_age is not None:
|
if self._max_age is not None:
|
||||||
self._purge_old()
|
self._purge_old()
|
||||||
|
|
||||||
|
@ -191,7 +199,7 @@ class StatisticsSensor(Entity):
|
||||||
self.median = round(statistics.median(self.states),
|
self.median = round(statistics.median(self.states),
|
||||||
self._precision)
|
self._precision)
|
||||||
except statistics.StatisticsError as err:
|
except statistics.StatisticsError as err:
|
||||||
_LOGGER.debug(err)
|
_LOGGER.debug("%s: %s", self.entity_id, err)
|
||||||
self.mean = self.median = STATE_UNKNOWN
|
self.mean = self.median = STATE_UNKNOWN
|
||||||
|
|
||||||
try: # require at least two data points
|
try: # require at least two data points
|
||||||
|
@ -200,7 +208,7 @@ class StatisticsSensor(Entity):
|
||||||
self.variance = round(statistics.variance(self.states),
|
self.variance = round(statistics.variance(self.states),
|
||||||
self._precision)
|
self._precision)
|
||||||
except statistics.StatisticsError as err:
|
except statistics.StatisticsError as err:
|
||||||
_LOGGER.debug(err)
|
_LOGGER.debug("%s: %s", self.entity_id, err)
|
||||||
self.stdev = self.variance = STATE_UNKNOWN
|
self.stdev = self.variance = STATE_UNKNOWN
|
||||||
|
|
||||||
if self.states:
|
if self.states:
|
||||||
|
@ -241,7 +249,7 @@ class StatisticsSensor(Entity):
|
||||||
list so that we get it in the right order again.
|
list so that we get it in the right order again.
|
||||||
"""
|
"""
|
||||||
from homeassistant.components.recorder.models import States
|
from homeassistant.components.recorder.models import States
|
||||||
_LOGGER.debug("initializing values for %s from the database",
|
_LOGGER.debug("%s: initializing values from the database",
|
||||||
self.entity_id)
|
self.entity_id)
|
||||||
|
|
||||||
with session_scope(hass=self._hass) as session:
|
with session_scope(hass=self._hass) as session:
|
||||||
|
@ -254,4 +262,5 @@ class StatisticsSensor(Entity):
|
||||||
for state in reversed(states):
|
for state in reversed(states):
|
||||||
self._add_state_to_queue(state)
|
self._add_state_to_queue(state)
|
||||||
|
|
||||||
_LOGGER.debug("initializing from database completed")
|
_LOGGER.debug("%s: initializing from database completed",
|
||||||
|
self.entity_id)
|
||||||
|
|
Loading…
Reference in New Issue