Skip to content

Commit

Permalink
Update name for Notification CC sensors and buttons (#93019)
Browse files Browse the repository at this point in the history
* Update name for Notification CC sensors and buttons

* Add comment with reference to names
  • Loading branch information
raman325 authored May 24, 2023
1 parent 83f206a commit 3e93dd6
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 9 deletions.
4 changes: 3 additions & 1 deletion homeassistant/components/zwave_js/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ def __init__(
"""Initialize a ZWaveNotificationIdleButton entity."""
super().__init__(config_entry, driver, info)
self._attr_name = self.generate_name(
include_value_name=True, name_prefix="Idle"
alternate_value_name=self.info.primary_value.property_name,
additional_info=[self.info.primary_value.property_key_name],
name_prefix="Idle",
)
self._attr_unique_id = f"{self._attr_unique_id}.notification_idle"

Expand Down
7 changes: 5 additions & 2 deletions homeassistant/components/zwave_js/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def generate_name(
self,
include_value_name: bool = False,
alternate_value_name: str | None = None,
additional_info: list[str] | None = None,
additional_info: list[str | None] | None = None,
name_prefix: str | None = None,
) -> str:
"""Generate entity name."""
Expand Down Expand Up @@ -155,8 +155,11 @@ def generate_name(
or self.info.primary_value.property_name
or ""
)

name = f"{name} {value_name}".strip()
name = f"{name} {' '.join(additional_info or [])}".strip()
# Only include non empty additional info
if additional_info := [item for item in (additional_info or []) if item]:
name = f"{name} {' '.join(additional_info)}"
# append endpoint if > 1
if (
self.info.primary_value.endpoint is not None
Expand Down
22 changes: 22 additions & 0 deletions homeassistant/components/zwave_js/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,28 @@ async def async_reset_meter(
class ZWaveListSensor(ZwaveSensor):
"""Representation of a Z-Wave Numeric sensor with multiple states."""

def __init__(
self,
config_entry: ConfigEntry,
driver: Driver,
info: ZwaveDiscoveryInfo,
entity_description: SensorEntityDescription,
unit_of_measurement: str | None = None,
) -> None:
"""Initialize a ZWaveListSensor entity."""
super().__init__(
config_entry, driver, info, entity_description, unit_of_measurement
)

# Entity class attributes
# Notification sensors have the following name mapping (variables are property
# keys, name is property)
# https://github.com/zwave-js/node-zwave-js/blob/master/packages/config/config/notifications.json
self._attr_name = self.generate_name(
alternate_value_name=self.info.primary_value.property_name,
additional_info=[self.info.primary_value.property_key_name],
)

@property
def device_class(self) -> SensorDeviceClass | None:
"""Return sensor device class."""
Expand Down
2 changes: 1 addition & 1 deletion tests/components/zwave_js/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
ENABLED_LEGACY_BINARY_SENSOR = "binary_sensor.z_wave_door_window_sensor_any"
DISABLED_LEGACY_BINARY_SENSOR = "binary_sensor.multisensor_6_any"
NOTIFICATION_MOTION_BINARY_SENSOR = "binary_sensor.multisensor_6_motion_detection"
NOTIFICATION_MOTION_SENSOR = "sensor.multisensor_6_motion_sensor_status"
NOTIFICATION_MOTION_SENSOR = "sensor.multisensor_6_home_security_motion_sensor_status"
INDICATOR_SENSOR = "sensor.z_wave_thermostat_indicator_value"
BASIC_NUMBER_ENTITY = "number.livingroomlight_basic"
PROPERTY_DOOR_STATUS_BINARY_SENSOR = (
Expand Down
9 changes: 6 additions & 3 deletions tests/components/zwave_js/test_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,20 @@ async def test_notification_idle_button(
) -> None:
"""Test Notification idle button."""
node = multisensor_6
state = hass.states.get("button.multisensor_6_idle_cover_status")
state = hass.states.get("button.multisensor_6_idle_home_security_cover_status")
assert state
assert state.state == "unknown"
assert state.attributes["friendly_name"] == "Multisensor 6 Idle Cover status"
assert (
state.attributes["friendly_name"]
== "Multisensor 6 Idle Home Security Cover status"
)

# Test successful idle call
await hass.services.async_call(
BUTTON_DOMAIN,
SERVICE_PRESS,
{
ATTR_ENTITY_ID: "button.multisensor_6_idle_cover_status",
ATTR_ENTITY_ID: "button.multisensor_6_idle_home_security_cover_status",
},
blocking=True,
)
Expand Down
6 changes: 4 additions & 2 deletions tests/components/zwave_js/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -1362,8 +1362,10 @@ async def test_disabled_entity_on_value_removed(
er_reg = er.async_get(hass)

# re-enable this default-disabled entity
sensor_cover_entity = "sensor.4_in_1_sensor_cover_status"
idle_cover_status_button_entity = "button.4_in_1_sensor_idle_cover_status"
sensor_cover_entity = "sensor.4_in_1_sensor_home_security_cover_status"
idle_cover_status_button_entity = (
"button.4_in_1_sensor_idle_home_security_cover_status"
)
er_reg.async_update_entity(entity_id=sensor_cover_entity, disabled_by=None)
await hass.async_block_till_done()

Expand Down

0 comments on commit 3e93dd6

Please sign in to comment.