mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 02:07:09 +00:00
Add icon and state translations for zwave_js sensors (#109186)
This commit is contained in:
parent
ac8f555a70
commit
b8c9da4705
24
homeassistant/components/zwave_js/icons.json
Normal file
24
homeassistant/components/zwave_js/icons.json
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
{
|
||||||
|
"entity": {
|
||||||
|
"sensor": {
|
||||||
|
"controller_status": {
|
||||||
|
"default": "mdi:help-rhombus",
|
||||||
|
"state": {
|
||||||
|
"ready": "mdi:check",
|
||||||
|
"unresponsive": "mdi:bell-off",
|
||||||
|
"jammed": "mdi:lock"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_status": {
|
||||||
|
"default": "mdi:help-rhombus",
|
||||||
|
"state": {
|
||||||
|
"alive": "mdi:heart-pulse",
|
||||||
|
"asleep": "mdi:sleep",
|
||||||
|
"awake": "mdi:eye",
|
||||||
|
"dead": "mdi:robot-dead",
|
||||||
|
"unknown": "mdi:help-rhombus"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -6,7 +6,7 @@ from typing import cast
|
|||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
from zwave_js_server.client import Client as ZwaveClient
|
from zwave_js_server.client import Client as ZwaveClient
|
||||||
from zwave_js_server.const import CommandClass, ControllerStatus, NodeStatus
|
from zwave_js_server.const import CommandClass
|
||||||
from zwave_js_server.const.command_class.meter import (
|
from zwave_js_server.const.command_class.meter import (
|
||||||
RESET_METER_OPTION_TARGET_VALUE,
|
RESET_METER_OPTION_TARGET_VALUE,
|
||||||
RESET_METER_OPTION_TYPE,
|
RESET_METER_OPTION_TYPE,
|
||||||
@ -91,20 +91,6 @@ from .helpers import get_device_info, get_valueless_base_unique_id
|
|||||||
|
|
||||||
PARALLEL_UPDATES = 0
|
PARALLEL_UPDATES = 0
|
||||||
|
|
||||||
CONTROLLER_STATUS_ICON: dict[ControllerStatus, str] = {
|
|
||||||
ControllerStatus.READY: "mdi:check",
|
|
||||||
ControllerStatus.UNRESPONSIVE: "mdi:bell-off",
|
|
||||||
ControllerStatus.JAMMED: "mdi:lock",
|
|
||||||
}
|
|
||||||
|
|
||||||
NODE_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",
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# These descriptions should include device class.
|
# These descriptions should include device class.
|
||||||
ENTITY_DESCRIPTION_KEY_DEVICE_CLASS_MAP: dict[
|
ENTITY_DESCRIPTION_KEY_DEVICE_CLASS_MAP: dict[
|
||||||
@ -784,6 +770,7 @@ class ZWaveNodeStatusSensor(SensorEntity):
|
|||||||
_attr_should_poll = False
|
_attr_should_poll = False
|
||||||
_attr_entity_category = EntityCategory.DIAGNOSTIC
|
_attr_entity_category = EntityCategory.DIAGNOSTIC
|
||||||
_attr_has_entity_name = True
|
_attr_has_entity_name = True
|
||||||
|
_attr_translation_key = "node_status"
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, config_entry: ConfigEntry, driver: Driver, node: ZwaveNode
|
self, config_entry: ConfigEntry, driver: Driver, node: ZwaveNode
|
||||||
@ -793,7 +780,6 @@ class ZWaveNodeStatusSensor(SensorEntity):
|
|||||||
self.node = node
|
self.node = node
|
||||||
|
|
||||||
# Entity class attributes
|
# Entity class attributes
|
||||||
self._attr_name = "Node status"
|
|
||||||
self._base_unique_id = get_valueless_base_unique_id(driver, node)
|
self._base_unique_id = get_valueless_base_unique_id(driver, node)
|
||||||
self._attr_unique_id = f"{self._base_unique_id}.node_status"
|
self._attr_unique_id = f"{self._base_unique_id}.node_status"
|
||||||
# device may not be precreated in main handler yet
|
# device may not be precreated in main handler yet
|
||||||
@ -815,11 +801,6 @@ class ZWaveNodeStatusSensor(SensorEntity):
|
|||||||
self._attr_native_value = self.node.status.name.lower()
|
self._attr_native_value = self.node.status.name.lower()
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
|
|
||||||
@property
|
|
||||||
def icon(self) -> str | None:
|
|
||||||
"""Icon of the entity."""
|
|
||||||
return NODE_STATUS_ICON[self.node.status]
|
|
||||||
|
|
||||||
async def async_added_to_hass(self) -> None:
|
async def async_added_to_hass(self) -> None:
|
||||||
"""Call when entity is added."""
|
"""Call when entity is added."""
|
||||||
# Add value_changed callbacks.
|
# Add value_changed callbacks.
|
||||||
@ -852,6 +833,7 @@ class ZWaveControllerStatusSensor(SensorEntity):
|
|||||||
_attr_should_poll = False
|
_attr_should_poll = False
|
||||||
_attr_entity_category = EntityCategory.DIAGNOSTIC
|
_attr_entity_category = EntityCategory.DIAGNOSTIC
|
||||||
_attr_has_entity_name = True
|
_attr_has_entity_name = True
|
||||||
|
_attr_translation_key = "controller_status"
|
||||||
|
|
||||||
def __init__(self, config_entry: ConfigEntry, driver: Driver) -> None:
|
def __init__(self, config_entry: ConfigEntry, driver: Driver) -> None:
|
||||||
"""Initialize a generic Z-Wave device entity."""
|
"""Initialize a generic Z-Wave device entity."""
|
||||||
@ -861,7 +843,6 @@ class ZWaveControllerStatusSensor(SensorEntity):
|
|||||||
assert node
|
assert node
|
||||||
|
|
||||||
# Entity class attributes
|
# Entity class attributes
|
||||||
self._attr_name = "Status"
|
|
||||||
self._base_unique_id = get_valueless_base_unique_id(driver, node)
|
self._base_unique_id = get_valueless_base_unique_id(driver, node)
|
||||||
self._attr_unique_id = f"{self._base_unique_id}.controller_status"
|
self._attr_unique_id = f"{self._base_unique_id}.controller_status"
|
||||||
# device may not be precreated in main handler yet
|
# device may not be precreated in main handler yet
|
||||||
@ -883,11 +864,6 @@ class ZWaveControllerStatusSensor(SensorEntity):
|
|||||||
self._attr_native_value = self.controller.status.name.lower()
|
self._attr_native_value = self.controller.status.name.lower()
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
|
|
||||||
@property
|
|
||||||
def icon(self) -> str | None:
|
|
||||||
"""Icon of the entity."""
|
|
||||||
return CONTROLLER_STATUS_ICON[self.controller.status]
|
|
||||||
|
|
||||||
async def async_added_to_hass(self) -> None:
|
async def async_added_to_hass(self) -> None:
|
||||||
"""Call when entity is added."""
|
"""Call when entity is added."""
|
||||||
# Add value_changed callbacks.
|
# Add value_changed callbacks.
|
||||||
|
@ -1,4 +1,26 @@
|
|||||||
{
|
{
|
||||||
|
"entity": {
|
||||||
|
"sensor": {
|
||||||
|
"node_status": {
|
||||||
|
"name": "Node status",
|
||||||
|
"state": {
|
||||||
|
"alive": "Alive",
|
||||||
|
"asleep": "Asleep",
|
||||||
|
"awake": "Awake",
|
||||||
|
"dead": "Dead",
|
||||||
|
"unknown": "Unknown"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"controller_status": {
|
||||||
|
"name": "Status",
|
||||||
|
"state": {
|
||||||
|
"ready": "Ready",
|
||||||
|
"unresponsive": "Unresponsive",
|
||||||
|
"jammed": "Jammed"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"config": {
|
"config": {
|
||||||
"flow_title": "{name}",
|
"flow_title": "{name}",
|
||||||
"step": {
|
"step": {
|
||||||
|
@ -25,7 +25,6 @@ from homeassistant.components.zwave_js.helpers import get_valueless_base_unique_
|
|||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_DEVICE_CLASS,
|
ATTR_DEVICE_CLASS,
|
||||||
ATTR_ENTITY_ID,
|
ATTR_ENTITY_ID,
|
||||||
ATTR_ICON,
|
|
||||||
ATTR_UNIT_OF_MEASUREMENT,
|
ATTR_UNIT_OF_MEASUREMENT,
|
||||||
PERCENTAGE,
|
PERCENTAGE,
|
||||||
STATE_UNAVAILABLE,
|
STATE_UNAVAILABLE,
|
||||||
@ -318,7 +317,6 @@ async def test_controller_status_sensor(
|
|||||||
state = hass.states.get(entity_id)
|
state = hass.states.get(entity_id)
|
||||||
assert state
|
assert state
|
||||||
assert state.state == "ready"
|
assert state.state == "ready"
|
||||||
assert state.attributes[ATTR_ICON] == "mdi:check"
|
|
||||||
|
|
||||||
event = Event(
|
event = Event(
|
||||||
"status changed",
|
"status changed",
|
||||||
@ -328,7 +326,6 @@ async def test_controller_status_sensor(
|
|||||||
state = hass.states.get(entity_id)
|
state = hass.states.get(entity_id)
|
||||||
assert state
|
assert state
|
||||||
assert state.state == "unresponsive"
|
assert state.state == "unresponsive"
|
||||||
assert state.attributes[ATTR_ICON] == "mdi:bell-off"
|
|
||||||
|
|
||||||
# Test transitions work
|
# Test transitions work
|
||||||
event = Event(
|
event = Event(
|
||||||
@ -339,7 +336,6 @@ async def test_controller_status_sensor(
|
|||||||
state = hass.states.get(entity_id)
|
state = hass.states.get(entity_id)
|
||||||
assert state
|
assert state
|
||||||
assert state.state == "jammed"
|
assert state.state == "jammed"
|
||||||
assert state.attributes[ATTR_ICON] == "mdi:lock"
|
|
||||||
|
|
||||||
# Disconnect the client and make sure the entity is still available
|
# Disconnect the client and make sure the entity is still available
|
||||||
await client.disconnect()
|
await client.disconnect()
|
||||||
@ -365,33 +361,24 @@ async def test_node_status_sensor(
|
|||||||
)
|
)
|
||||||
node.receive_event(event)
|
node.receive_event(event)
|
||||||
assert hass.states.get(node_status_entity_id).state == "dead"
|
assert hass.states.get(node_status_entity_id).state == "dead"
|
||||||
assert (
|
|
||||||
hass.states.get(node_status_entity_id).attributes[ATTR_ICON] == "mdi:robot-dead"
|
|
||||||
)
|
|
||||||
|
|
||||||
event = Event(
|
event = Event(
|
||||||
"wake up", data={"source": "node", "event": "wake up", "nodeId": node.node_id}
|
"wake up", data={"source": "node", "event": "wake up", "nodeId": node.node_id}
|
||||||
)
|
)
|
||||||
node.receive_event(event)
|
node.receive_event(event)
|
||||||
assert hass.states.get(node_status_entity_id).state == "awake"
|
assert hass.states.get(node_status_entity_id).state == "awake"
|
||||||
assert hass.states.get(node_status_entity_id).attributes[ATTR_ICON] == "mdi:eye"
|
|
||||||
|
|
||||||
event = Event(
|
event = Event(
|
||||||
"sleep", data={"source": "node", "event": "sleep", "nodeId": node.node_id}
|
"sleep", data={"source": "node", "event": "sleep", "nodeId": node.node_id}
|
||||||
)
|
)
|
||||||
node.receive_event(event)
|
node.receive_event(event)
|
||||||
assert hass.states.get(node_status_entity_id).state == "asleep"
|
assert hass.states.get(node_status_entity_id).state == "asleep"
|
||||||
assert hass.states.get(node_status_entity_id).attributes[ATTR_ICON] == "mdi:sleep"
|
|
||||||
|
|
||||||
event = Event(
|
event = Event(
|
||||||
"alive", data={"source": "node", "event": "alive", "nodeId": node.node_id}
|
"alive", data={"source": "node", "event": "alive", "nodeId": node.node_id}
|
||||||
)
|
)
|
||||||
node.receive_event(event)
|
node.receive_event(event)
|
||||||
assert hass.states.get(node_status_entity_id).state == "alive"
|
assert hass.states.get(node_status_entity_id).state == "alive"
|
||||||
assert (
|
|
||||||
hass.states.get(node_status_entity_id).attributes[ATTR_ICON]
|
|
||||||
== "mdi:heart-pulse"
|
|
||||||
)
|
|
||||||
|
|
||||||
# Disconnect the client and make sure the entity is still available
|
# Disconnect the client and make sure the entity is still available
|
||||||
await client.disconnect()
|
await client.disconnect()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user