Compare commits

...

3 Commits

Author SHA1 Message Date
Ville Skyttä
0bd8f41173 Fix state class info in warn_dip/negative docstrings 2025-11-27 22:26:56 +02:00
Ville Skyttä
74dec7d40f Use state class constants in dip/negative warning messages 2025-11-27 22:24:29 +02:00
Ville Skyttä
ecdc196119 Clarify previous state in dip warning 2025-11-27 22:20:16 +02:00

View File

@@ -394,7 +394,7 @@ def _suggest_report_issue(hass: HomeAssistant, entity_id: str) -> str:
def warn_dip(
hass: HomeAssistant, entity_id: str, state: State, previous_fstate: float
) -> None:
"""Log a warning once if a sensor with state_class_total has a decreasing value.
"""Log a warning once if a sensor with state class TOTAL_INCREASING has a decreasing value.
The log will be suppressed until two dips have been seen to prevent warning due to
rounding issues with databases storing the state as a single precision float, which
@@ -415,12 +415,13 @@ def warn_dip(
return
_LOGGER.warning(
(
"Entity %s %shas state class total_increasing, but its state is not"
" strictly increasing. Triggered by state %s (%s) with last_updated set"
" to %s. Please %s"
"Entity %s %shas state class %s, but its state is not"
" strictly increasing. Triggered by state %s (previous %s) with"
" last_updated set to %s. Please %s"
),
entity_id,
f"from integration {domain} " if domain else "",
SensorStateClass.TOTAL_INCREASING,
state.state,
previous_fstate,
state.last_updated.isoformat(),
@@ -429,7 +430,7 @@ def warn_dip(
def warn_negative(hass: HomeAssistant, entity_id: str, state: State) -> None:
"""Log a warning once if a sensor with state_class_total has a negative value."""
"""Log a warning once if a sensor with state class TOTAL_INCREASING has a negative value."""
if WARN_NEGATIVE not in hass.data:
hass.data[WARN_NEGATIVE] = set()
if entity_id not in hass.data[WARN_NEGATIVE]:
@@ -438,11 +439,12 @@ def warn_negative(hass: HomeAssistant, entity_id: str, state: State) -> None:
domain = entity_info["domain"] if entity_info else None
_LOGGER.warning(
(
"Entity %s %shas state class total_increasing, but its state is "
"Entity %s %shas state class %s, but its state is "
"negative. Triggered by state %s with last_updated set to %s. Please %s"
),
entity_id,
f"from integration {domain} " if domain else "",
SensorStateClass.TOTAL_INCREASING,
state.state,
state.last_updated.isoformat(),
_suggest_report_issue(hass, entity_id),