Fix display state to return None instead of STATE_UNKNOWN in NUT (#143297)

Fix return value to avoid STATE_UNKNOWN
This commit is contained in:
tdfountain 2025-04-19 16:53:29 -07:00 committed by GitHub
parent b4344a8de2
commit f5c0c207ec
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -13,7 +13,6 @@ from homeassistant.components.sensor import (
)
from homeassistant.const import (
PERCENTAGE,
STATE_UNKNOWN,
EntityCategory,
UnitOfApparentPower,
UnitOfElectricCurrent,
@ -1120,9 +1119,9 @@ class NUTSensor(NUTBaseEntity, SensorEntity):
return status.get(self.entity_description.key)
def _format_display_state(status: dict[str, str]) -> str:
def _format_display_state(status: dict[str, str]) -> str | None:
"""Return UPS display state."""
try:
return ", ".join(STATE_TYPES[state] for state in status[KEY_STATUS].split())
except KeyError:
return STATE_UNKNOWN
return None