Add node sensor status icons (#56137)

Co-authored-by: kpine <keith.pine@gmail.com>
Co-authored-by: Raman Gupta <7243222+raman325@users.noreply.github.com>
This commit is contained in:
Marius 2021-09-27 12:50:14 +02:00 committed by GitHub
parent 83b1b3e92c
commit 4ce7166afd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 1 deletions

View file

@ -8,7 +8,7 @@ from typing import cast
import voluptuous as vol
from zwave_js_server.client import Client as ZwaveClient
from zwave_js_server.const import CommandClass, ConfigurationValueType
from zwave_js_server.const import CommandClass, ConfigurationValueType, NodeStatus
from zwave_js_server.const.command_class.meter import (
RESET_METER_OPTION_TARGET_VALUE,
RESET_METER_OPTION_TYPE,
@ -80,6 +80,14 @@ from .helpers import get_device_id
LOGGER = logging.getLogger(__name__)
STATUS_ICON: dict[NodeStatus, str] = {
NodeStatus.ALIVE: "mdi:heart-pulse",
NodeStatus.ASLEEP: "mdi:sleep",
NodeStatus.AWAKE: "mdi:eye",
NodeStatus.DEAD: "mdi:robot-dead",
NodeStatus.UNKNOWN: "mdi:help-rhombus",
}
@dataclass
class ZwaveSensorEntityDescription(SensorEntityDescription):
@ -480,6 +488,11 @@ class ZWaveNodeStatusSensor(SensorEntity):
self._attr_native_value = self.node.status.name.lower()
self.async_write_ha_state()
@property
def icon(self) -> str | None:
"""Icon of the entity."""
return STATUS_ICON[self.node.status]
async def async_added_to_hass(self) -> None:
"""Call when entity is added."""
# Add value_changed callbacks.