Migrate Wilight to has entity name (#96825)

Migrate Wilight to has entity naming
This commit is contained in:
Joost Lekkerkerker 2023-07-18 11:07:26 +02:00 committed by GitHub
parent d361caf6c4
commit 772fb463b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 19 additions and 9 deletions

View File

@ -56,6 +56,7 @@ class WiLightDevice(Entity):
"""
_attr_should_poll = False
_attr_has_entity_name = True
def __init__(self, api_device: PyWiLightDevice, index: str, item_name: str) -> None:
"""Initialize the device."""
@ -65,7 +66,6 @@ class WiLightDevice(Entity):
self._index = index
self._status: dict[str, Any] = {}
self._attr_name = item_name
self._attr_unique_id = f"{self._device_id}_{index}"
self._attr_device_info = DeviceInfo(
name=item_name,

View File

@ -57,6 +57,8 @@ def hass_to_wilight_position(value: int) -> int:
class WiLightCover(WiLightDevice, CoverEntity):
"""Representation of a WiLights cover."""
_attr_name = None
@property
def current_cover_position(self) -> int | None:
"""Return current position of cover.

View File

@ -54,6 +54,7 @@ async def async_setup_entry(
class WiLightFan(WiLightDevice, FanEntity):
"""Representation of a WiLights fan."""
_attr_name = None
_attr_icon = "mdi:fan"
_attr_speed_count = len(ORDERED_NAMED_FAN_SPEEDS)
_attr_supported_features = FanEntityFeature.SET_SPEED | FanEntityFeature.DIRECTION

View File

@ -53,6 +53,7 @@ async def async_setup_entry(
class WiLightLightOnOff(WiLightDevice, LightEntity):
"""Representation of a WiLights light on-off."""
_attr_name = None
_attr_color_mode = ColorMode.ONOFF
_attr_supported_color_modes = {ColorMode.ONOFF}
@ -73,6 +74,7 @@ class WiLightLightOnOff(WiLightDevice, LightEntity):
class WiLightLightDimmer(WiLightDevice, LightEntity):
"""Representation of a WiLights light dimmer."""
_attr_name = None
_attr_color_mode = ColorMode.BRIGHTNESS
_attr_supported_color_modes = {ColorMode.BRIGHTNESS}
@ -124,6 +126,7 @@ def hass_to_wilight_saturation(value: float) -> int:
class WiLightLightColor(WiLightDevice, LightEntity):
"""Representation of a WiLights light rgb."""
_attr_name = None
_attr_color_mode = ColorMode.HS
_attr_supported_color_modes = {ColorMode.HS}

View File

@ -12,6 +12,16 @@
"not_wilight_device": "This Device is not WiLight"
}
},
"entity": {
"switch": {
"watering": {
"name": "Watering"
},
"pause": {
"name": "Pause"
}
}
},
"services": {
"set_watering_time": {
"name": "Set watering time",

View File

@ -148,10 +148,7 @@ def hass_to_wilight_pause_time(value: int) -> int:
class WiLightValveSwitch(WiLightDevice, SwitchEntity):
"""Representation of a WiLights Valve switch."""
@property
def name(self) -> str:
"""Return the name of the switch."""
return f"{self._attr_name} {DESC_WATERING}"
_attr_translation_key = "watering"
@property
def is_on(self) -> bool:
@ -272,10 +269,7 @@ class WiLightValveSwitch(WiLightDevice, SwitchEntity):
class WiLightValvePauseSwitch(WiLightDevice, SwitchEntity):
"""Representation of a WiLights Valve Pause switch."""
@property
def name(self) -> str:
"""Return the name of the switch."""
return f"{self._attr_name} {DESC_PAUSE}"
_attr_translation_key = "pause"
@property
def is_on(self) -> bool: