Use better names for zwave_js platforms that are self describing (#46083)

* use better names for platforms that are self describing

* add missing light change

* fix tests

* only use value_name in sensors and binary_sensors
This commit is contained in:
Raman Gupta 2021-02-06 05:08:25 -06:00 committed by GitHub
parent ee98ea89dd
commit af4e6f856f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 50 additions and 22 deletions

View file

@ -257,6 +257,16 @@ async def async_setup_entry(
class ZWaveBooleanBinarySensor(ZWaveBaseEntity, BinarySensorEntity): class ZWaveBooleanBinarySensor(ZWaveBaseEntity, BinarySensorEntity):
"""Representation of a Z-Wave binary_sensor.""" """Representation of a Z-Wave binary_sensor."""
def __init__(
self,
config_entry: ConfigEntry,
client: ZwaveClient,
info: ZwaveDiscoveryInfo,
) -> None:
"""Initialize a ZWaveBooleanBinarySensor entity."""
super().__init__(config_entry, client, info)
self._name = self.generate_name(include_value_name=True)
@property @property
def is_on(self) -> bool: def is_on(self) -> bool:
"""Return if the sensor is on or off.""" """Return if the sensor is on or off."""
@ -294,8 +304,9 @@ class ZWaveNotificationBinarySensor(ZWaveBaseEntity, BinarySensorEntity):
super().__init__(config_entry, client, info) super().__init__(config_entry, client, info)
self.state_key = state_key self.state_key = state_key
self._name = self.generate_name( self._name = self.generate_name(
self.info.primary_value.property_name, include_value_name=True,
[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]],
) )
# check if we have a custom mapping for this value # check if we have a custom mapping for this value
self._mapping_info = self._get_sensor_mapping() self._mapping_info = self._get_sensor_mapping()
@ -347,6 +358,7 @@ class ZWavePropertyBinarySensor(ZWaveBaseEntity, BinarySensorEntity):
super().__init__(config_entry, client, info) super().__init__(config_entry, client, info)
# check if we have a custom mapping for this value # check if we have a custom mapping for this value
self._mapping_info = self._get_sensor_mapping() self._mapping_info = self._get_sensor_mapping()
self._name = self.generate_name(include_value_name=True)
@property @property
def is_on(self) -> bool: def is_on(self) -> bool:

View file

@ -64,20 +64,22 @@ class ZWaveBaseEntity(Entity):
def generate_name( def generate_name(
self, self,
include_value_name: bool = False,
alternate_value_name: Optional[str] = None, alternate_value_name: Optional[str] = None,
additional_info: Optional[List[str]] = None, additional_info: Optional[List[str]] = None,
) -> str: ) -> str:
"""Generate entity name.""" """Generate entity name."""
if additional_info is None: if additional_info is None:
additional_info = [] additional_info = []
node_name = self.info.node.name or self.info.node.device_config.description name: str = self.info.node.name or self.info.node.device_config.description
value_name = ( if include_value_name:
alternate_value_name value_name = (
or self.info.primary_value.metadata.label alternate_value_name
or self.info.primary_value.property_key_name or self.info.primary_value.metadata.label
or self.info.primary_value.property_name or self.info.primary_value.property_key_name
) or self.info.primary_value.property_name
name = f"{node_name}: {value_name}" )
name = f"{name}: {value_name}"
for item in additional_info: for item in additional_info:
if item: if item:
name += f" - {item}" name += f" - {item}"

View file

@ -64,6 +64,16 @@ async def async_setup_entry(
class ZwaveSensorBase(ZWaveBaseEntity): class ZwaveSensorBase(ZWaveBaseEntity):
"""Basic Representation of a Z-Wave sensor.""" """Basic Representation of a Z-Wave sensor."""
def __init__(
self,
config_entry: ConfigEntry,
client: ZwaveClient,
info: ZwaveDiscoveryInfo,
) -> None:
"""Initialize a ZWaveSensorBase entity."""
super().__init__(config_entry, client, info)
self._name = self.generate_name(include_value_name=True)
@property @property
def device_class(self) -> Optional[str]: def device_class(self) -> Optional[str]:
"""Return the device class of the sensor.""" """Return the device class of the sensor."""
@ -132,7 +142,10 @@ class ZWaveNumericSensor(ZwaveSensorBase):
"""Initialize a ZWaveNumericSensor entity.""" """Initialize a ZWaveNumericSensor entity."""
super().__init__(config_entry, client, info) super().__init__(config_entry, client, info)
if self.info.primary_value.command_class == CommandClass.BASIC: if self.info.primary_value.command_class == CommandClass.BASIC:
self._name = self.generate_name(self.info.primary_value.command_class_name) self._name = self.generate_name(
include_value_name=True,
alternate_value_name=self.info.primary_value.command_class_name,
)
@property @property
def state(self) -> float: def state(self) -> float:
@ -166,8 +179,9 @@ class ZWaveListSensor(ZwaveSensorBase):
"""Initialize a ZWaveListSensor entity.""" """Initialize a ZWaveListSensor entity."""
super().__init__(config_entry, client, info) super().__init__(config_entry, client, info)
self._name = self.generate_name( self._name = self.generate_name(
self.info.primary_value.property_name, include_value_name=True,
[self.info.primary_value.property_key_name], alternate_value_name=self.info.primary_value.property_name,
additional_info=[self.info.primary_value.property_key_name],
) )
@property @property

View file

@ -2,7 +2,7 @@
AIR_TEMPERATURE_SENSOR = "sensor.multisensor_6_air_temperature" AIR_TEMPERATURE_SENSOR = "sensor.multisensor_6_air_temperature"
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"
POWER_SENSOR = "sensor.smart_plug_with_two_usb_ports_value_electric_consumed" POWER_SENSOR = "sensor.smart_plug_with_two_usb_ports_value_electric_consumed"
SWITCH_ENTITY = "switch.smart_plug_with_two_usb_ports_current_value" 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"

View file

@ -25,9 +25,9 @@ from homeassistant.components.climate.const import (
) )
from homeassistant.const import ATTR_ENTITY_ID, ATTR_TEMPERATURE from homeassistant.const import ATTR_ENTITY_ID, ATTR_TEMPERATURE
CLIMATE_RADIO_THERMOSTAT_ENTITY = "climate.z_wave_thermostat_thermostat_mode" CLIMATE_RADIO_THERMOSTAT_ENTITY = "climate.z_wave_thermostat"
CLIMATE_DANFOSS_LC13_ENTITY = "climate.living_connect_z_thermostat_heating" CLIMATE_DANFOSS_LC13_ENTITY = "climate.living_connect_z_thermostat"
CLIMATE_FLOOR_THERMOSTAT_ENTITY = "climate.floor_thermostat_thermostat_mode" CLIMATE_FLOOR_THERMOSTAT_ENTITY = "climate.floor_thermostat"
async def test_thermostat_v2( async def test_thermostat_v2(

View file

@ -3,7 +3,7 @@ from zwave_js_server.event import Event
from homeassistant.components.cover import ATTR_CURRENT_POSITION from homeassistant.components.cover import ATTR_CURRENT_POSITION
WINDOW_COVER_ENTITY = "cover.zws_12_current_value" WINDOW_COVER_ENTITY = "cover.zws_12"
async def test_cover(hass, client, chain_actuator_zws12, integration): async def test_cover(hass, client, chain_actuator_zws12, integration):

View file

@ -4,7 +4,7 @@ from zwave_js_server.event import Event
from homeassistant.components.fan import ATTR_SPEED, SPEED_MEDIUM from homeassistant.components.fan import ATTR_SPEED, SPEED_MEDIUM
FAN_ENTITY = "fan.in_wall_smart_fan_control_current_value" FAN_ENTITY = "fan.in_wall_smart_fan_control"
async def test_fan(hass, client, in_wall_smart_fan_control, integration): async def test_fan(hass, client, in_wall_smart_fan_control, integration):

View file

@ -12,8 +12,8 @@ from homeassistant.components.light import (
) )
from homeassistant.const import ATTR_SUPPORTED_FEATURES, STATE_OFF, STATE_ON from homeassistant.const import ATTR_SUPPORTED_FEATURES, STATE_OFF, STATE_ON
BULB_6_MULTI_COLOR_LIGHT_ENTITY = "light.bulb_6_multi_color_current_value" BULB_6_MULTI_COLOR_LIGHT_ENTITY = "light.bulb_6_multi_color"
EATON_RF9640_ENTITY = "light.allloaddimmer_current_value" EATON_RF9640_ENTITY = "light.allloaddimmer"
async def test_light(hass, client, bulb_6_multi_color, integration): async def test_light(hass, client, bulb_6_multi_color, integration):

View file

@ -14,7 +14,7 @@ from homeassistant.components.zwave_js.lock import (
) )
from homeassistant.const import ATTR_ENTITY_ID, STATE_LOCKED, STATE_UNLOCKED from homeassistant.const import ATTR_ENTITY_ID, STATE_LOCKED, STATE_UNLOCKED
SCHLAGE_BE469_LOCK_ENTITY = "lock.touchscreen_deadbolt_current_lock_mode" SCHLAGE_BE469_LOCK_ENTITY = "lock.touchscreen_deadbolt"
async def test_door_lock(hass, client, lock_schlage_be469, integration): async def test_door_lock(hass, client, lock_schlage_be469, integration):