From 8dc5f737895c01c431445b3333dcdd5cf435a949 Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Tue, 18 Jul 2023 13:58:42 +0200 Subject: [PATCH] Migrate Yolink to has entity name (#96839) * Migrate Yolink to has entity name * Add sensor --- .../components/yolink/binary_sensor.py | 10 ---- homeassistant/components/yolink/climate.py | 3 +- homeassistant/components/yolink/cover.py | 3 +- homeassistant/components/yolink/entity.py | 2 + homeassistant/components/yolink/light.py | 1 - homeassistant/components/yolink/lock.py | 3 +- homeassistant/components/yolink/sensor.py | 16 ++---- homeassistant/components/yolink/siren.py | 6 +-- homeassistant/components/yolink/strings.json | 51 +++++++++++++++++++ homeassistant/components/yolink/switch.py | 19 +++---- 10 files changed, 73 insertions(+), 41 deletions(-) diff --git a/homeassistant/components/yolink/binary_sensor.py b/homeassistant/components/yolink/binary_sensor.py index 5b9dacb9db7..38ea7d46537 100644 --- a/homeassistant/components/yolink/binary_sensor.py +++ b/homeassistant/components/yolink/binary_sensor.py @@ -51,42 +51,35 @@ SENSOR_TYPES: tuple[YoLinkBinarySensorEntityDescription, ...] = ( key="door_state", icon="mdi:door", device_class=BinarySensorDeviceClass.DOOR, - name="State", value=lambda value: value == "open" if value is not None else None, exists_fn=lambda device: device.device_type == ATTR_DEVICE_DOOR_SENSOR, ), YoLinkBinarySensorEntityDescription( key="motion_state", device_class=BinarySensorDeviceClass.MOTION, - name="Motion", value=lambda value: value == "alert" if value is not None else None, exists_fn=lambda device: device.device_type == ATTR_DEVICE_MOTION_SENSOR, ), YoLinkBinarySensorEntityDescription( key="leak_state", - name="Leak", - icon="mdi:water", device_class=BinarySensorDeviceClass.MOISTURE, value=lambda value: value == "alert" if value is not None else None, exists_fn=lambda device: device.device_type == ATTR_DEVICE_LEAK_SENSOR, ), YoLinkBinarySensorEntityDescription( key="vibration_state", - name="Vibration", device_class=BinarySensorDeviceClass.VIBRATION, value=lambda value: value == "alert" if value is not None else None, exists_fn=lambda device: device.device_type == ATTR_DEVICE_VIBRATION_SENSOR, ), YoLinkBinarySensorEntityDescription( key="co_detected", - name="Co Detected", device_class=BinarySensorDeviceClass.CO, value=lambda state: state.get("gasAlarm"), exists_fn=lambda device: device.device_type == ATTR_DEVICE_CO_SMOKE_SENSOR, ), YoLinkBinarySensorEntityDescription( key="smoke_detected", - name="Smoke Detected", device_class=BinarySensorDeviceClass.SMOKE, value=lambda state: state.get("smokeAlarm"), exists_fn=lambda device: device.device_type == ATTR_DEVICE_CO_SMOKE_SENSOR, @@ -135,9 +128,6 @@ class YoLinkBinarySensorEntity(YoLinkEntity, BinarySensorEntity): self._attr_unique_id = ( f"{coordinator.device.device_id} {self.entity_description.key}" ) - self._attr_name = ( - f"{coordinator.device.device_name} ({self.entity_description.name})" - ) @callback def update_entity_state(self, state: dict[str, Any]) -> None: diff --git a/homeassistant/components/yolink/climate.py b/homeassistant/components/yolink/climate.py index e9d11fb77d0..6e4495ee0b9 100644 --- a/homeassistant/components/yolink/climate.py +++ b/homeassistant/components/yolink/climate.py @@ -61,6 +61,8 @@ async def async_setup_entry( class YoLinkClimateEntity(YoLinkEntity, ClimateEntity): """YoLink Climate Entity.""" + _attr_name = None + def __init__( self, config_entry: ConfigEntry, @@ -69,7 +71,6 @@ class YoLinkClimateEntity(YoLinkEntity, ClimateEntity): """Init YoLink Thermostat.""" super().__init__(config_entry, coordinator) self._attr_unique_id = f"{coordinator.device.device_id}_climate" - self._attr_name = f"{coordinator.device.device_name} (Thermostat)" self._attr_temperature_unit = UnitOfTemperature.CELSIUS self._attr_fan_modes = [FAN_ON, FAN_AUTO] self._attr_min_temp = -10 diff --git a/homeassistant/components/yolink/cover.py b/homeassistant/components/yolink/cover.py index 1b22f76f177..0d1f1e590b4 100644 --- a/homeassistant/components/yolink/cover.py +++ b/homeassistant/components/yolink/cover.py @@ -38,6 +38,8 @@ async def async_setup_entry( class YoLinkCoverEntity(YoLinkEntity, CoverEntity): """YoLink Cover Entity.""" + _attr_name = None + def __init__( self, config_entry: ConfigEntry, @@ -46,7 +48,6 @@ class YoLinkCoverEntity(YoLinkEntity, CoverEntity): """Init YoLink garage door entity.""" super().__init__(config_entry, coordinator) self._attr_unique_id = f"{coordinator.device.device_id}_door_state" - self._attr_name = f"{coordinator.device.device_name} (State)" self._attr_device_class = CoverDeviceClass.GARAGE self._attr_supported_features = ( CoverEntityFeature.OPEN | CoverEntityFeature.CLOSE diff --git a/homeassistant/components/yolink/entity.py b/homeassistant/components/yolink/entity.py index 76ef1ecd534..09da5545d57 100644 --- a/homeassistant/components/yolink/entity.py +++ b/homeassistant/components/yolink/entity.py @@ -19,6 +19,8 @@ from .coordinator import YoLinkCoordinator class YoLinkEntity(CoordinatorEntity[YoLinkCoordinator]): """YoLink Device Basic Entity.""" + _attr_has_entity_name = True + def __init__( self, config_entry: ConfigEntry, diff --git a/homeassistant/components/yolink/light.py b/homeassistant/components/yolink/light.py index a7f52e801b2..248a42df60c 100644 --- a/homeassistant/components/yolink/light.py +++ b/homeassistant/components/yolink/light.py @@ -35,7 +35,6 @@ class YoLinkDimmerEntity(YoLinkEntity, LightEntity): """YoLink Dimmer Entity.""" _attr_color_mode = ColorMode.BRIGHTNESS - _attr_has_entity_name = True _attr_name = None _attr_supported_color_modes: set[ColorMode] = {ColorMode.BRIGHTNESS} diff --git a/homeassistant/components/yolink/lock.py b/homeassistant/components/yolink/lock.py index 7565c66867a..3b0f68c175c 100644 --- a/homeassistant/components/yolink/lock.py +++ b/homeassistant/components/yolink/lock.py @@ -34,6 +34,8 @@ async def async_setup_entry( class YoLinkLockEntity(YoLinkEntity, LockEntity): """YoLink Lock Entity.""" + _attr_name = None + def __init__( self, config_entry: ConfigEntry, @@ -42,7 +44,6 @@ class YoLinkLockEntity(YoLinkEntity, LockEntity): """Init YoLink Lock.""" super().__init__(config_entry, coordinator) self._attr_unique_id = f"{coordinator.device.device_id}_lock_state" - self._attr_name = f"{coordinator.device.device_name}(LockState)" @callback def update_entity_state(self, state: dict[str, Any]) -> None: diff --git a/homeassistant/components/yolink/sensor.py b/homeassistant/components/yolink/sensor.py index 75c4949859c..149bdc0adf8 100644 --- a/homeassistant/components/yolink/sensor.py +++ b/homeassistant/components/yolink/sensor.py @@ -126,7 +126,6 @@ SENSOR_TYPES: tuple[YoLinkSensorEntityDescription, ...] = ( key="battery", device_class=SensorDeviceClass.BATTERY, native_unit_of_measurement=PERCENTAGE, - name="Battery", state_class=SensorStateClass.MEASUREMENT, value=cvt_battery, exists_fn=lambda device: device.device_type in BATTERY_POWER_SENSOR, @@ -135,7 +134,6 @@ SENSOR_TYPES: tuple[YoLinkSensorEntityDescription, ...] = ( key="humidity", device_class=SensorDeviceClass.HUMIDITY, native_unit_of_measurement=PERCENTAGE, - name="Humidity", state_class=SensorStateClass.MEASUREMENT, exists_fn=lambda device: device.device_type in [ATTR_DEVICE_TH_SENSOR], ), @@ -143,7 +141,6 @@ SENSOR_TYPES: tuple[YoLinkSensorEntityDescription, ...] = ( key="temperature", device_class=SensorDeviceClass.TEMPERATURE, native_unit_of_measurement=UnitOfTemperature.CELSIUS, - name="Temperature", state_class=SensorStateClass.MEASUREMENT, exists_fn=lambda device: device.device_type in [ATTR_DEVICE_TH_SENSOR], ), @@ -152,7 +149,6 @@ SENSOR_TYPES: tuple[YoLinkSensorEntityDescription, ...] = ( key="devTemperature", device_class=SensorDeviceClass.TEMPERATURE, native_unit_of_measurement=UnitOfTemperature.CELSIUS, - name="Temperature", state_class=SensorStateClass.MEASUREMENT, exists_fn=lambda device: device.device_type in MCU_DEV_TEMPERATURE_SENSOR, should_update_entity=lambda value: value is not None, @@ -161,7 +157,6 @@ SENSOR_TYPES: tuple[YoLinkSensorEntityDescription, ...] = ( key="loraInfo", device_class=SensorDeviceClass.SIGNAL_STRENGTH, native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS_MILLIWATT, - name="Signal", value=lambda value: value["signal"] if value is not None else None, state_class=SensorStateClass.MEASUREMENT, entity_category=EntityCategory.DIAGNOSTIC, @@ -170,16 +165,16 @@ SENSOR_TYPES: tuple[YoLinkSensorEntityDescription, ...] = ( ), YoLinkSensorEntityDescription( key="state", + translation_key="power_failure_alarm", device_class=SensorDeviceClass.ENUM, - name="Power failure alarm", icon="mdi:flash", options=["normal", "alert", "off"], exists_fn=lambda device: device.device_type in ATTR_DEVICE_POWER_FAILURE_ALARM, ), YoLinkSensorEntityDescription( key="mute", + translation_key="power_failure_alarm_mute", device_class=SensorDeviceClass.ENUM, - name="Power failure alarm mute", icon="mdi:volume-mute", options=["muted", "unmuted"], exists_fn=lambda device: device.device_type in ATTR_DEVICE_POWER_FAILURE_ALARM, @@ -187,8 +182,8 @@ SENSOR_TYPES: tuple[YoLinkSensorEntityDescription, ...] = ( ), YoLinkSensorEntityDescription( key="sound", + translation_key="power_failure_alarm_volume", device_class=SensorDeviceClass.ENUM, - name="Power failure alarm volume", icon="mdi:volume-high", options=["low", "medium", "high"], exists_fn=lambda device: device.device_type in ATTR_DEVICE_POWER_FAILURE_ALARM, @@ -196,8 +191,8 @@ SENSOR_TYPES: tuple[YoLinkSensorEntityDescription, ...] = ( ), YoLinkSensorEntityDescription( key="beep", + translation_key="power_failure_alarm_beep", device_class=SensorDeviceClass.ENUM, - name="Power failure alarm beep", icon="mdi:bullhorn", options=["enabled", "disabled"], exists_fn=lambda device: device.device_type in ATTR_DEVICE_POWER_FAILURE_ALARM, @@ -249,9 +244,6 @@ class YoLinkSensorEntity(YoLinkEntity, SensorEntity): self._attr_unique_id = ( f"{coordinator.device.device_id} {self.entity_description.key}" ) - self._attr_name = ( - f"{coordinator.device.device_name} ({self.entity_description.name})" - ) @callback def update_entity_state(self, state: dict) -> None: diff --git a/homeassistant/components/yolink/siren.py b/homeassistant/components/yolink/siren.py index ad51b912193..81c2b46a840 100644 --- a/homeassistant/components/yolink/siren.py +++ b/homeassistant/components/yolink/siren.py @@ -34,7 +34,6 @@ class YoLinkSirenEntityDescription(SirenEntityDescription): DEVICE_TYPES: tuple[YoLinkSirenEntityDescription, ...] = ( YoLinkSirenEntityDescription( key="state", - name="State", value=lambda value: value == "alert" if value is not None else None, exists_fn=lambda device: device.device_type in [ATTR_DEVICE_SIREN], ), @@ -70,6 +69,8 @@ async def async_setup_entry( class YoLinkSirenEntity(YoLinkEntity, SirenEntity): """YoLink Siren Entity.""" + _attr_name = None + entity_description: YoLinkSirenEntityDescription def __init__( @@ -84,9 +85,6 @@ class YoLinkSirenEntity(YoLinkEntity, SirenEntity): self._attr_unique_id = ( f"{coordinator.device.device_id} {self.entity_description.key}" ) - self._attr_name = ( - f"{coordinator.device.device_name} ({self.entity_description.name})" - ) self._attr_supported_features = ( SirenEntityFeature.TURN_ON | SirenEntityFeature.TURN_OFF ) diff --git a/homeassistant/components/yolink/strings.json b/homeassistant/components/yolink/strings.json index de16e1a6e39..b1cd8d87a75 100644 --- a/homeassistant/components/yolink/strings.json +++ b/homeassistant/components/yolink/strings.json @@ -33,5 +33,56 @@ "button_4_short_press": "Button_4 (short press)", "button_4_long_press": "Button_4 (long press)" } + }, + "entity": { + "switch": { + "usb_ports": { + "name": "USB ports" + }, + "plug_1": { + "name": "Plug 1" + }, + "plug_2": { + "name": "Plug 2" + }, + "plug_3": { + "name": "Plug 3" + }, + "plug_4": { + "name": "Plug 4" + } + }, + "sensor": { + "power_failure_alarm": { + "name": "Power failure alarm", + "state": { + "normal": "Normal", + "alert": "Alert", + "off": "[%key:common::state::off%]" + } + }, + "power_failure_alarm_mute": { + "name": "Power failure alarm mute", + "state": { + "muted": "Muted", + "unmuted": "Unmuted" + } + }, + "power_failure_alarm_volume": { + "name": "Power failure alarm volume", + "state": { + "low": "Low", + "medium": "Medium", + "high": "High" + } + }, + "power_failure_alarm_beep": { + "name": "Power failure alarm beep", + "state": { + "enabled": "[%key:common::state::enabled%]", + "disabled": "[%key:common::state::disabled%]" + } + } + } } } diff --git a/homeassistant/components/yolink/switch.py b/homeassistant/components/yolink/switch.py index 773477e6c3f..415c1e9584d 100644 --- a/homeassistant/components/yolink/switch.py +++ b/homeassistant/components/yolink/switch.py @@ -40,52 +40,52 @@ DEVICE_TYPES: tuple[YoLinkSwitchEntityDescription, ...] = ( YoLinkSwitchEntityDescription( key="outlet_state", device_class=SwitchDeviceClass.OUTLET, - name="State", + name=None, exists_fn=lambda device: device.device_type == ATTR_DEVICE_OUTLET, ), YoLinkSwitchEntityDescription( key="manipulator_state", - name="State", + name=None, icon="mdi:pipe", exists_fn=lambda device: device.device_type == ATTR_DEVICE_MANIPULATOR, ), YoLinkSwitchEntityDescription( key="switch_state", - name="State", + name=None, device_class=SwitchDeviceClass.SWITCH, exists_fn=lambda device: device.device_type == ATTR_DEVICE_SWITCH, ), YoLinkSwitchEntityDescription( key="multi_outlet_usb_ports", - name="UsbPorts", + translation_key="usb_ports", device_class=SwitchDeviceClass.OUTLET, exists_fn=lambda device: device.device_type == ATTR_DEVICE_MULTI_OUTLET, plug_index=0, ), YoLinkSwitchEntityDescription( key="multi_outlet_plug_1", - name="Plug1", + translation_key="plug_1", device_class=SwitchDeviceClass.OUTLET, exists_fn=lambda device: device.device_type == ATTR_DEVICE_MULTI_OUTLET, plug_index=1, ), YoLinkSwitchEntityDescription( key="multi_outlet_plug_2", - name="Plug2", + translation_key="plug_2", device_class=SwitchDeviceClass.OUTLET, exists_fn=lambda device: device.device_type == ATTR_DEVICE_MULTI_OUTLET, plug_index=2, ), YoLinkSwitchEntityDescription( key="multi_outlet_plug_3", - name="Plug3", + translation_key="plug_3", device_class=SwitchDeviceClass.OUTLET, exists_fn=lambda device: device.device_type == ATTR_DEVICE_MULTI_OUTLET, plug_index=3, ), YoLinkSwitchEntityDescription( key="multi_outlet_plug_4", - name="Plug4", + translation_key="plug_4", device_class=SwitchDeviceClass.OUTLET, exists_fn=lambda device: device.device_type == ATTR_DEVICE_MULTI_OUTLET, plug_index=4, @@ -141,9 +141,6 @@ class YoLinkSwitchEntity(YoLinkEntity, SwitchEntity): self._attr_unique_id = ( f"{coordinator.device.device_id} {self.entity_description.key}" ) - self._attr_name = ( - f"{coordinator.device.device_name} ({self.entity_description.name})" - ) def _get_state( self, state_value: str | list[str] | None, plug_index: int | None