Migrate WLED to new entity naming style (#74860)

pull/74485/head^2
Franck Nijhof 2022-07-10 23:56:48 +02:00 committed by GitHub
parent 176e2754ec
commit f15d3fc5db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 28 additions and 33 deletions

View File

@ -34,6 +34,7 @@ class WLEDUpdateBinarySensor(WLEDEntity, BinarySensorEntity):
_attr_entity_category = EntityCategory.DIAGNOSTIC
_attr_device_class = BinarySensorDeviceClass.UPDATE
_attr_name = "Firmware"
# Disabled by default, as this entity is deprecated.
_attr_entity_registry_enabled_default = False
@ -41,7 +42,6 @@ class WLEDUpdateBinarySensor(WLEDEntity, BinarySensorEntity):
def __init__(self, coordinator: WLEDDataUpdateCoordinator) -> None:
"""Initialize the button entity."""
super().__init__(coordinator=coordinator)
self._attr_name = f"{coordinator.data.info.name} Firmware"
self._attr_unique_id = f"{coordinator.data.info.mac_address}_update"
@property

View File

@ -28,11 +28,11 @@ class WLEDRestartButton(WLEDEntity, ButtonEntity):
_attr_device_class = ButtonDeviceClass.RESTART
_attr_entity_category = EntityCategory.CONFIG
_attr_name = "Restart"
def __init__(self, coordinator: WLEDDataUpdateCoordinator) -> None:
"""Initialize the button entity."""
super().__init__(coordinator=coordinator)
self._attr_name = f"{coordinator.data.info.name} Restart"
self._attr_unique_id = f"{coordinator.data.info.mac_address}_restart"
@wled_exception_handler

View File

@ -52,13 +52,13 @@ class WLEDMasterLight(WLEDEntity, LightEntity):
_attr_color_mode = ColorMode.BRIGHTNESS
_attr_icon = "mdi:led-strip-variant"
_attr_name = "Master"
_attr_supported_features = LightEntityFeature.TRANSITION
_attr_supported_color_modes = {ColorMode.BRIGHTNESS}
def __init__(self, coordinator: WLEDDataUpdateCoordinator) -> None:
"""Initialize WLED master light."""
super().__init__(coordinator=coordinator)
self._attr_name = f"{coordinator.data.info.name} Master"
self._attr_unique_id = coordinator.data.info.mac_address
@property
@ -118,9 +118,8 @@ class WLEDSegmentLight(WLEDEntity, LightEntity):
# Segment 0 uses a simpler name, which is more natural for when using
# a single segment / using WLED with one big LED strip.
self._attr_name = f"{coordinator.data.info.name} Segment {segment}"
if segment == 0:
self._attr_name = coordinator.data.info.name
if segment != 0:
self._attr_name = f"Segment {segment}"
self._attr_unique_id = (
f"{self.coordinator.data.info.mac_address}_{self._segment}"

View File

@ -10,6 +10,8 @@ from .coordinator import WLEDDataUpdateCoordinator
class WLEDEntity(CoordinatorEntity[WLEDDataUpdateCoordinator]):
"""Defines a base WLED entity."""
_attr_has_entity_name = True
@property
def device_info(self) -> DeviceInfo:
"""Return device information about this WLED device."""

View File

@ -71,11 +71,8 @@ class WLEDNumber(WLEDEntity, NumberEntity):
# Segment 0 uses a simpler name, which is more natural for when using
# a single segment / using WLED with one big LED strip.
self._attr_name = (
f"{coordinator.data.info.name} Segment {segment} {description.name}"
)
if segment == 0:
self._attr_name = f"{coordinator.data.info.name} {description.name}"
if segment != 0:
self._attr_name = f"Segment {segment} {description.name}"
self._attr_unique_id = (
f"{coordinator.data.info.mac_address}_{description.key}_{segment}"

View File

@ -51,12 +51,12 @@ class WLEDLiveOverrideSelect(WLEDEntity, SelectEntity):
_attr_device_class = DEVICE_CLASS_WLED_LIVE_OVERRIDE
_attr_entity_category = EntityCategory.CONFIG
_attr_icon = "mdi:theater"
_attr_name = "Live override"
def __init__(self, coordinator: WLEDDataUpdateCoordinator) -> None:
"""Initialize WLED ."""
super().__init__(coordinator=coordinator)
self._attr_name = f"{coordinator.data.info.name} Live Override"
self._attr_unique_id = f"{coordinator.data.info.mac_address}_live_override"
self._attr_options = [str(live.value) for live in Live]
@ -75,12 +75,12 @@ class WLEDPresetSelect(WLEDEntity, SelectEntity):
"""Defined a WLED Preset select."""
_attr_icon = "mdi:playlist-play"
_attr_name = "Preset"
def __init__(self, coordinator: WLEDDataUpdateCoordinator) -> None:
"""Initialize WLED ."""
super().__init__(coordinator=coordinator)
self._attr_name = f"{coordinator.data.info.name} Preset"
self._attr_unique_id = f"{coordinator.data.info.mac_address}_preset"
self._attr_options = [preset.name for preset in self.coordinator.data.presets]
@ -106,12 +106,12 @@ class WLEDPlaylistSelect(WLEDEntity, SelectEntity):
"""Define a WLED Playlist select."""
_attr_icon = "mdi:play-speed"
_attr_name = "Playlist"
def __init__(self, coordinator: WLEDDataUpdateCoordinator) -> None:
"""Initialize WLED playlist."""
super().__init__(coordinator=coordinator)
self._attr_name = f"{coordinator.data.info.name} Playlist"
self._attr_unique_id = f"{coordinator.data.info.mac_address}_playlist"
self._attr_options = [
playlist.name for playlist in self.coordinator.data.playlists
@ -140,6 +140,7 @@ class WLEDPaletteSelect(WLEDEntity, SelectEntity):
_attr_entity_category = EntityCategory.CONFIG
_attr_icon = "mdi:palette-outline"
_attr_name = "Color palette"
_segment: int
def __init__(self, coordinator: WLEDDataUpdateCoordinator, segment: int) -> None:
@ -148,11 +149,8 @@ class WLEDPaletteSelect(WLEDEntity, SelectEntity):
# Segment 0 uses a simpler name, which is more natural for when using
# a single segment / using WLED with one big LED strip.
self._attr_name = (
f"{coordinator.data.info.name} Segment {segment} Color Palette"
)
if segment == 0:
self._attr_name = f"{coordinator.data.info.name} Color Palette"
if segment != 0:
self._attr_name = f"Segment {segment} color palette"
self._attr_unique_id = f"{coordinator.data.info.mac_address}_palette_{segment}"
self._attr_options = [

View File

@ -50,7 +50,7 @@ class WLEDSensorEntityDescription(
SENSORS: tuple[WLEDSensorEntityDescription, ...] = (
WLEDSensorEntityDescription(
key="estimated_current",
name="Estimated Current",
name="Estimated current",
native_unit_of_measurement=ELECTRIC_CURRENT_MILLIAMPERE,
device_class=SensorDeviceClass.CURRENT,
state_class=SensorStateClass.MEASUREMENT,
@ -60,13 +60,13 @@ SENSORS: tuple[WLEDSensorEntityDescription, ...] = (
),
WLEDSensorEntityDescription(
key="info_leds_count",
name="LED Count",
name="LED count",
entity_category=EntityCategory.DIAGNOSTIC,
value_fn=lambda device: device.info.leds.count,
),
WLEDSensorEntityDescription(
key="info_leds_max_power",
name="Max Current",
name="Max current",
native_unit_of_measurement=ELECTRIC_CURRENT_MILLIAMPERE,
entity_category=EntityCategory.DIAGNOSTIC,
device_class=SensorDeviceClass.CURRENT,
@ -83,7 +83,7 @@ SENSORS: tuple[WLEDSensorEntityDescription, ...] = (
),
WLEDSensorEntityDescription(
key="free_heap",
name="Free Memory",
name="Free memory",
icon="mdi:memory",
native_unit_of_measurement=DATA_BYTES,
state_class=SensorStateClass.MEASUREMENT,
@ -93,7 +93,7 @@ SENSORS: tuple[WLEDSensorEntityDescription, ...] = (
),
WLEDSensorEntityDescription(
key="wifi_signal",
name="Wi-Fi Signal",
name="Wi-Fi signal",
icon="mdi:wifi",
native_unit_of_measurement=PERCENTAGE,
entity_category=EntityCategory.DIAGNOSTIC,
@ -111,7 +111,7 @@ SENSORS: tuple[WLEDSensorEntityDescription, ...] = (
),
WLEDSensorEntityDescription(
key="wifi_channel",
name="Wi-Fi Channel",
name="Wi-Fi channel",
icon="mdi:wifi",
entity_category=EntityCategory.DIAGNOSTIC,
entity_registry_enabled_default=False,
@ -155,7 +155,6 @@ class WLEDSensorEntity(WLEDEntity, SensorEntity):
"""Initialize a WLED sensor entity."""
super().__init__(coordinator=coordinator)
self.entity_description = description
self._attr_name = f"{coordinator.data.info.name} {description.name}"
self._attr_unique_id = f"{coordinator.data.info.mac_address}_{description.key}"
@property

View File

@ -55,11 +55,11 @@ class WLEDNightlightSwitch(WLEDEntity, SwitchEntity):
_attr_icon = "mdi:weather-night"
_attr_entity_category = EntityCategory.CONFIG
_attr_name = "Nightlight"
def __init__(self, coordinator: WLEDDataUpdateCoordinator) -> None:
"""Initialize WLED nightlight switch."""
super().__init__(coordinator=coordinator)
self._attr_name = f"{coordinator.data.info.name} Nightlight"
self._attr_unique_id = f"{coordinator.data.info.mac_address}_nightlight"
@property
@ -92,11 +92,11 @@ class WLEDSyncSendSwitch(WLEDEntity, SwitchEntity):
_attr_icon = "mdi:upload-network-outline"
_attr_entity_category = EntityCategory.CONFIG
_attr_name = "Sync send"
def __init__(self, coordinator: WLEDDataUpdateCoordinator) -> None:
"""Initialize WLED sync send switch."""
super().__init__(coordinator=coordinator)
self._attr_name = f"{coordinator.data.info.name} Sync Send"
self._attr_unique_id = f"{coordinator.data.info.mac_address}_sync_send"
@property
@ -125,11 +125,11 @@ class WLEDSyncReceiveSwitch(WLEDEntity, SwitchEntity):
_attr_icon = "mdi:download-network-outline"
_attr_entity_category = EntityCategory.CONFIG
_attr_name = "Sync receive"
def __init__(self, coordinator: WLEDDataUpdateCoordinator) -> None:
"""Initialize WLED sync receive switch."""
super().__init__(coordinator=coordinator)
self._attr_name = f"{coordinator.data.info.name} Sync Receive"
self._attr_unique_id = f"{coordinator.data.info.mac_address}_sync_receive"
@property
@ -158,6 +158,7 @@ class WLEDReverseSwitch(WLEDEntity, SwitchEntity):
_attr_icon = "mdi:swap-horizontal-bold"
_attr_entity_category = EntityCategory.CONFIG
_attr_name = "Reverse"
_segment: int
def __init__(self, coordinator: WLEDDataUpdateCoordinator, segment: int) -> None:
@ -166,9 +167,8 @@ class WLEDReverseSwitch(WLEDEntity, SwitchEntity):
# Segment 0 uses a simpler name, which is more natural for when using
# a single segment / using WLED with one big LED strip.
self._attr_name = f"{coordinator.data.info.name} Segment {segment} Reverse"
if segment == 0:
self._attr_name = f"{coordinator.data.info.name} Reverse"
if segment != 0:
self._attr_name = f"Segment {segment} reverse"
self._attr_unique_id = f"{coordinator.data.info.mac_address}_reverse_{segment}"
self._segment = segment

View File

@ -36,11 +36,11 @@ class WLEDUpdateEntity(WLEDEntity, UpdateEntity):
UpdateEntityFeature.INSTALL | UpdateEntityFeature.SPECIFIC_VERSION
)
_attr_title = "WLED"
_attr_name = "Firmware"
def __init__(self, coordinator: WLEDDataUpdateCoordinator) -> None:
"""Initialize the update entity."""
super().__init__(coordinator=coordinator)
self._attr_name = f"{coordinator.data.info.name} Firmware"
self._attr_unique_id = coordinator.data.info.mac_address
@property