Update name for Notification CC sensors and buttons (#93019)

* Update name for Notification CC sensors and buttons

* Add comment with reference to names
This commit is contained in:
Raman Gupta 2023-05-24 09:00:37 -04:00 committed by GitHub
parent 83f206a6fe
commit 3e93dd6a01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 41 additions and 9 deletions

View File

@ -122,7 +122,9 @@ class ZWaveNotificationIdleButton(ZWaveBaseEntity, ButtonEntity):
"""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"

View File

@ -126,7 +126,7 @@ class ZWaveBaseEntity(Entity):
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."""
@ -155,8 +155,11 @@ class ZWaveBaseEntity(Entity):
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

View File

@ -468,6 +468,28 @@ class ZWaveMeterSensor(ZWaveNumericSensor):
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."""

View File

@ -24,7 +24,7 @@ LOW_BATTERY_BINARY_SENSOR = "binary_sensor.multisensor_6_low_battery_level"
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 = (

View File

@ -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,
)

View File

@ -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()