mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 01:37:08 +00:00
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:
parent
83b1b3e92c
commit
4ce7166afd
@ -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.
|
||||
|
@ -20,6 +20,7 @@ from homeassistant.components.zwave_js.const import (
|
||||
from homeassistant.const import (
|
||||
ATTR_DEVICE_CLASS,
|
||||
ATTR_ENTITY_ID,
|
||||
ATTR_ICON,
|
||||
DEVICE_CLASS_CURRENT,
|
||||
DEVICE_CLASS_ENERGY,
|
||||
DEVICE_CLASS_HUMIDITY,
|
||||
@ -168,24 +169,30 @@ async def test_node_status_sensor(hass, client, lock_id_lock_as_id150, integrati
|
||||
)
|
||||
node.receive_event(event)
|
||||
assert hass.states.get(NODE_STATUS_ENTITY).state == "dead"
|
||||
assert hass.states.get(NODE_STATUS_ENTITY).attributes[ATTR_ICON] == "mdi:robot-dead"
|
||||
|
||||
event = Event(
|
||||
"wake up", data={"source": "node", "event": "wake up", "nodeId": node.node_id}
|
||||
)
|
||||
node.receive_event(event)
|
||||
assert hass.states.get(NODE_STATUS_ENTITY).state == "awake"
|
||||
assert hass.states.get(NODE_STATUS_ENTITY).attributes[ATTR_ICON] == "mdi:eye"
|
||||
|
||||
event = Event(
|
||||
"sleep", data={"source": "node", "event": "sleep", "nodeId": node.node_id}
|
||||
)
|
||||
node.receive_event(event)
|
||||
assert hass.states.get(NODE_STATUS_ENTITY).state == "asleep"
|
||||
assert hass.states.get(NODE_STATUS_ENTITY).attributes[ATTR_ICON] == "mdi:sleep"
|
||||
|
||||
event = Event(
|
||||
"alive", data={"source": "node", "event": "alive", "nodeId": node.node_id}
|
||||
)
|
||||
node.receive_event(event)
|
||||
assert hass.states.get(NODE_STATUS_ENTITY).state == "alive"
|
||||
assert (
|
||||
hass.states.get(NODE_STATUS_ENTITY).attributes[ATTR_ICON] == "mdi:heart-pulse"
|
||||
)
|
||||
|
||||
# Disconnect the client and make sure the entity is still available
|
||||
await client.disconnect()
|
||||
|
Loading…
x
Reference in New Issue
Block a user