Migrate Yolink to has entity name (#96839)
* Migrate Yolink to has entity name * Add sensor
This commit is contained in:
parent
8a9f117bdc
commit
8dc5f73789
10 changed files with 73 additions and 41 deletions
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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}
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
)
|
||||
|
|
|
@ -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%]"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue