Switch to new entity naming schema across zwave_js (#77434)
This commit is contained in:
parent
b56f54745a
commit
abebf3c067
9 changed files with 43 additions and 61 deletions
|
@ -376,9 +376,7 @@ class ZWaveNotificationBinarySensor(ZWaveBaseEntity, BinarySensorEntity):
|
||||||
|
|
||||||
# Entity class attributes
|
# Entity class attributes
|
||||||
self._attr_name = self.generate_name(
|
self._attr_name = self.generate_name(
|
||||||
include_value_name=True,
|
alternate_value_name=self.info.primary_value.metadata.states[self.state_key]
|
||||||
alternate_value_name=self.info.primary_value.property_name,
|
|
||||||
additional_info=[self.info.primary_value.metadata.states[self.state_key]],
|
|
||||||
)
|
)
|
||||||
self._attr_unique_id = f"{self._attr_unique_id}.{self.state_key}"
|
self._attr_unique_id = f"{self._attr_unique_id}.{self.state_key}"
|
||||||
|
|
||||||
|
|
|
@ -47,15 +47,14 @@ class ZWaveNodePingButton(ButtonEntity):
|
||||||
|
|
||||||
_attr_should_poll = False
|
_attr_should_poll = False
|
||||||
_attr_entity_category = EntityCategory.CONFIG
|
_attr_entity_category = EntityCategory.CONFIG
|
||||||
|
_attr_has_entity_name = True
|
||||||
|
|
||||||
def __init__(self, driver: Driver, node: ZwaveNode) -> None:
|
def __init__(self, driver: Driver, node: ZwaveNode) -> None:
|
||||||
"""Initialize a ping Z-Wave device button entity."""
|
"""Initialize a ping Z-Wave device button entity."""
|
||||||
self.node = node
|
self.node = node
|
||||||
name: str = (
|
|
||||||
node.name or node.device_config.description or f"Node {node.node_id}"
|
|
||||||
)
|
|
||||||
# Entity class attributes
|
# Entity class attributes
|
||||||
self._attr_name = f"{name}: Ping"
|
self._attr_name = "Ping"
|
||||||
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}.ping"
|
self._attr_unique_id = f"{self._base_unique_id}.ping"
|
||||||
# device may not be precreated in main handler yet
|
# device may not be precreated in main handler yet
|
||||||
|
|
|
@ -24,6 +24,7 @@ class ZWaveBaseEntity(Entity):
|
||||||
"""Generic Entity Class for a Z-Wave Device."""
|
"""Generic Entity Class for a Z-Wave Device."""
|
||||||
|
|
||||||
_attr_should_poll = False
|
_attr_should_poll = False
|
||||||
|
_attr_has_entity_name = True
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, config_entry: ConfigEntry, driver: Driver, info: ZwaveDiscoveryInfo
|
self, config_entry: ConfigEntry, driver: Driver, info: ZwaveDiscoveryInfo
|
||||||
|
@ -126,29 +127,32 @@ class ZWaveBaseEntity(Entity):
|
||||||
include_value_name: bool = False,
|
include_value_name: bool = False,
|
||||||
alternate_value_name: str | None = None,
|
alternate_value_name: str | None = None,
|
||||||
additional_info: list[str] | None = None,
|
additional_info: list[str] | None = None,
|
||||||
name_suffix: str | None = None,
|
name_prefix: str | None = None,
|
||||||
) -> str:
|
) -> str:
|
||||||
"""Generate entity name."""
|
"""Generate entity name."""
|
||||||
if additional_info is None:
|
name = ""
|
||||||
additional_info = []
|
if (
|
||||||
name: str = (
|
hasattr(self, "entity_description")
|
||||||
self.info.node.name
|
and self.entity_description
|
||||||
or self.info.node.device_config.description
|
and self.entity_description.name
|
||||||
or f"Node {self.info.node.node_id}"
|
):
|
||||||
)
|
name = self.entity_description.name
|
||||||
if name_suffix:
|
|
||||||
name = f"{name} {name_suffix}"
|
if name_prefix:
|
||||||
if include_value_name:
|
name = f"{name_prefix} {name}".strip()
|
||||||
|
|
||||||
|
value_name = ""
|
||||||
|
if alternate_value_name:
|
||||||
|
value_name = alternate_value_name
|
||||||
|
elif include_value_name:
|
||||||
value_name = (
|
value_name = (
|
||||||
alternate_value_name
|
self.info.primary_value.metadata.label
|
||||||
or self.info.primary_value.metadata.label
|
|
||||||
or self.info.primary_value.property_key_name
|
or self.info.primary_value.property_key_name
|
||||||
or self.info.primary_value.property_name
|
or self.info.primary_value.property_name
|
||||||
|
or ""
|
||||||
)
|
)
|
||||||
name = f"{name}: {value_name}"
|
name = f"{name} {value_name}".strip()
|
||||||
for item in additional_info:
|
name = f"{name} {' '.join(additional_info or [])}".strip()
|
||||||
if item:
|
|
||||||
name += f" - {item}"
|
|
||||||
# append endpoint if > 1
|
# append endpoint if > 1
|
||||||
if (
|
if (
|
||||||
self.info.primary_value.endpoint is not None
|
self.info.primary_value.endpoint is not None
|
||||||
|
|
|
@ -66,9 +66,7 @@ class ZwaveNumberEntity(ZWaveBaseEntity, NumberEntity):
|
||||||
self._target_value = self.get_zwave_value(TARGET_VALUE_PROPERTY)
|
self._target_value = self.get_zwave_value(TARGET_VALUE_PROPERTY)
|
||||||
|
|
||||||
# Entity class attributes
|
# Entity class attributes
|
||||||
self._attr_name = self.generate_name(
|
self._attr_name = self.generate_name(alternate_value_name=info.platform_hint)
|
||||||
include_value_name=True, alternate_value_name=info.platform_hint
|
|
||||||
)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def native_min_value(self) -> float:
|
def native_min_value(self) -> float:
|
||||||
|
|
|
@ -107,9 +107,7 @@ class ZwaveDefaultToneSelectEntity(ZWaveBaseEntity, SelectEntity):
|
||||||
)
|
)
|
||||||
|
|
||||||
# Entity class attributes
|
# Entity class attributes
|
||||||
self._attr_name = self.generate_name(
|
self._attr_name = self.generate_name(alternate_value_name=info.platform_hint)
|
||||||
include_value_name=True, alternate_value_name=info.platform_hint
|
|
||||||
)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def options(self) -> list[str]:
|
def options(self) -> list[str]:
|
||||||
|
|
|
@ -386,13 +386,8 @@ class ZWaveListSensor(ZwaveSensorBase):
|
||||||
config_entry, driver, info, entity_description, unit_of_measurement
|
config_entry, driver, info, entity_description, unit_of_measurement
|
||||||
)
|
)
|
||||||
|
|
||||||
property_key_name = self.info.primary_value.property_key_name
|
|
||||||
# Entity class attributes
|
# Entity class attributes
|
||||||
self._attr_name = self.generate_name(
|
self._attr_name = self.generate_name(include_value_name=True)
|
||||||
include_value_name=True,
|
|
||||||
alternate_value_name=self.info.primary_value.property_name,
|
|
||||||
additional_info=[property_key_name] if property_key_name else None,
|
|
||||||
)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def native_value(self) -> str | None:
|
def native_value(self) -> str | None:
|
||||||
|
@ -437,10 +432,9 @@ class ZWaveConfigParameterSensor(ZwaveSensorBase):
|
||||||
property_key_name = self.info.primary_value.property_key_name
|
property_key_name = self.info.primary_value.property_key_name
|
||||||
# Entity class attributes
|
# Entity class attributes
|
||||||
self._attr_name = self.generate_name(
|
self._attr_name = self.generate_name(
|
||||||
include_value_name=True,
|
|
||||||
alternate_value_name=self.info.primary_value.property_name,
|
alternate_value_name=self.info.primary_value.property_name,
|
||||||
additional_info=[property_key_name] if property_key_name else None,
|
additional_info=[property_key_name] if property_key_name else None,
|
||||||
name_suffix="Config Parameter",
|
name_prefix="Config parameter",
|
||||||
)
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -477,6 +471,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
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, config_entry: ConfigEntry, driver: Driver, node: ZwaveNode
|
self, config_entry: ConfigEntry, driver: Driver, node: ZwaveNode
|
||||||
|
@ -484,18 +479,13 @@ class ZWaveNodeStatusSensor(SensorEntity):
|
||||||
"""Initialize a generic Z-Wave device entity."""
|
"""Initialize a generic Z-Wave device entity."""
|
||||||
self.config_entry = config_entry
|
self.config_entry = config_entry
|
||||||
self.node = node
|
self.node = node
|
||||||
name: str = (
|
|
||||||
self.node.name
|
|
||||||
or self.node.device_config.description
|
|
||||||
or f"Node {self.node.node_id}"
|
|
||||||
)
|
|
||||||
# Entity class attributes
|
# Entity class attributes
|
||||||
self._attr_name = f"{name}: Node Status"
|
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
|
||||||
self._attr_device_info = get_device_info(driver, node)
|
self._attr_device_info = get_device_info(driver, node)
|
||||||
self._attr_native_value: str = node.status.name.lower()
|
|
||||||
|
|
||||||
async def async_poll_value(self, _: bool) -> None:
|
async def async_poll_value(self, _: bool) -> None:
|
||||||
"""Poll a value."""
|
"""Poll a value."""
|
||||||
|
@ -534,4 +524,5 @@ class ZWaveNodeStatusSensor(SensorEntity):
|
||||||
self.async_remove,
|
self.async_remove,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
self._attr_native_value: str = self.node.status.name.lower()
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
"""Provide common test tools for Z-Wave JS."""
|
"""Provide common test tools for Z-Wave JS."""
|
||||||
AIR_TEMPERATURE_SENSOR = "sensor.multisensor_6_air_temperature"
|
AIR_TEMPERATURE_SENSOR = "sensor.multisensor_6_air_temperature"
|
||||||
BATTERY_SENSOR = "sensor.multisensor_6_battery_level"
|
BATTERY_SENSOR = "sensor.multisensor_6_battery_level"
|
||||||
TAMPER_SENSOR = (
|
TAMPER_SENSOR = "binary_sensor.multisensor_6_tampering_product_cover_removed"
|
||||||
"binary_sensor.multisensor_6_home_security_tampering_product_cover_removed"
|
|
||||||
)
|
|
||||||
HUMIDITY_SENSOR = "sensor.multisensor_6_humidity"
|
HUMIDITY_SENSOR = "sensor.multisensor_6_humidity"
|
||||||
POWER_SENSOR = "sensor.smart_plug_with_two_usb_ports_value_electric_consumed"
|
POWER_SENSOR = "sensor.smart_plug_with_two_usb_ports_value_electric_consumed"
|
||||||
ENERGY_SENSOR = "sensor.smart_plug_with_two_usb_ports_value_electric_consumed_2"
|
ENERGY_SENSOR = "sensor.smart_plug_with_two_usb_ports_value_electric_consumed_2"
|
||||||
|
@ -13,10 +11,8 @@ SWITCH_ENTITY = "switch.smart_plug_with_two_usb_ports"
|
||||||
LOW_BATTERY_BINARY_SENSOR = "binary_sensor.multisensor_6_low_battery_level"
|
LOW_BATTERY_BINARY_SENSOR = "binary_sensor.multisensor_6_low_battery_level"
|
||||||
ENABLED_LEGACY_BINARY_SENSOR = "binary_sensor.z_wave_door_window_sensor_any"
|
ENABLED_LEGACY_BINARY_SENSOR = "binary_sensor.z_wave_door_window_sensor_any"
|
||||||
DISABLED_LEGACY_BINARY_SENSOR = "binary_sensor.multisensor_6_any"
|
DISABLED_LEGACY_BINARY_SENSOR = "binary_sensor.multisensor_6_any"
|
||||||
NOTIFICATION_MOTION_BINARY_SENSOR = (
|
NOTIFICATION_MOTION_BINARY_SENSOR = "binary_sensor.multisensor_6_motion_detection"
|
||||||
"binary_sensor.multisensor_6_home_security_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"
|
INDICATOR_SENSOR = "sensor.z_wave_thermostat_indicator_value"
|
||||||
BASIC_NUMBER_ENTITY = "number.livingroomlight_basic"
|
BASIC_NUMBER_ENTITY = "number.livingroomlight_basic"
|
||||||
PROPERTY_DOOR_STATUS_BINARY_SENSOR = (
|
PROPERTY_DOOR_STATUS_BINARY_SENSOR = (
|
||||||
|
|
|
@ -141,7 +141,7 @@ async def test_notification_off_state(
|
||||||
|
|
||||||
state = door_states[0]
|
state = door_states[0]
|
||||||
assert state
|
assert state
|
||||||
assert state.entity_id == "binary_sensor.node_62_access_control_window_door_is_open"
|
assert state.entity_id == "binary_sensor.node_62_window_door_is_open"
|
||||||
|
|
||||||
|
|
||||||
async def test_property_sensor_door_status(hass, lock_august_pro, integration):
|
async def test_property_sensor_door_status(hass, lock_august_pro, integration):
|
||||||
|
|
|
@ -347,10 +347,10 @@ async def test_existing_node_not_replaced_when_not_ready(
|
||||||
assert not device.area_id
|
assert not device.area_id
|
||||||
assert device == dev_reg.async_get_device(identifiers={(DOMAIN, device_id_ext)})
|
assert device == dev_reg.async_get_device(identifiers={(DOMAIN, device_id_ext)})
|
||||||
|
|
||||||
motion_entity = "binary_sensor.4_in_1_sensor_home_security_motion_detection"
|
motion_entity = "binary_sensor.4_in_1_sensor_motion_detection"
|
||||||
state = hass.states.get(motion_entity)
|
state = hass.states.get(motion_entity)
|
||||||
assert state
|
assert state
|
||||||
assert state.name == "4-in-1 Sensor: Home Security - Motion detection"
|
assert state.name == "4-in-1 Sensor Motion detection"
|
||||||
|
|
||||||
dev_reg.async_update_device(
|
dev_reg.async_update_device(
|
||||||
device.id, name_by_user="Custom Device Name", area_id=kitchen_area.id
|
device.id, name_by_user="Custom Device Name", area_id=kitchen_area.id
|
||||||
|
@ -1179,10 +1179,10 @@ async def test_node_model_change(hass, zp3111, client, integration):
|
||||||
|
|
||||||
dev_id = device.id
|
dev_id = device.id
|
||||||
|
|
||||||
motion_entity = "binary_sensor.4_in_1_sensor_home_security_motion_detection"
|
motion_entity = "binary_sensor.4_in_1_sensor_motion_detection"
|
||||||
state = hass.states.get(motion_entity)
|
state = hass.states.get(motion_entity)
|
||||||
assert state
|
assert state
|
||||||
assert state.name == "4-in-1 Sensor: Home Security - Motion detection"
|
assert state.name == "4-in-1 Sensor Motion detection"
|
||||||
|
|
||||||
# Customize device and entity names/ids
|
# Customize device and entity names/ids
|
||||||
dev_reg.async_update_device(device.id, name_by_user="Custom Device Name")
|
dev_reg.async_update_device(device.id, name_by_user="Custom Device Name")
|
||||||
|
@ -1267,7 +1267,7 @@ async def test_disabled_entity_on_value_removed(hass, zp3111, client, integratio
|
||||||
er_reg = er.async_get(hass)
|
er_reg = er.async_get(hass)
|
||||||
|
|
||||||
# re-enable this default-disabled entity
|
# re-enable this default-disabled entity
|
||||||
sensor_cover_entity = "sensor.4_in_1_sensor_home_security_cover_status"
|
sensor_cover_entity = "sensor.4_in_1_sensor_cover_status"
|
||||||
er_reg.async_update_entity(entity_id=sensor_cover_entity, disabled_by=None)
|
er_reg.async_update_entity(entity_id=sensor_cover_entity, disabled_by=None)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
@ -1285,9 +1285,7 @@ async def test_disabled_entity_on_value_removed(hass, zp3111, client, integratio
|
||||||
assert state.state != STATE_UNAVAILABLE
|
assert state.state != STATE_UNAVAILABLE
|
||||||
|
|
||||||
# check for expected entities
|
# check for expected entities
|
||||||
binary_cover_entity = (
|
binary_cover_entity = "binary_sensor.4_in_1_sensor_tampering_product_cover_removed"
|
||||||
"binary_sensor.4_in_1_sensor_home_security_tampering_product_cover_removed"
|
|
||||||
)
|
|
||||||
state = hass.states.get(binary_cover_entity)
|
state = hass.states.get(binary_cover_entity)
|
||||||
assert state
|
assert state
|
||||||
assert state.state != STATE_UNAVAILABLE
|
assert state.state != STATE_UNAVAILABLE
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue