mirror of
https://github.com/home-assistant/core.git
synced 2025-04-22 16:27:56 +00:00
Migrate Tradfri to has entity name (#96248)
This commit is contained in:
parent
1ceb536dfb
commit
8675bc6554
@ -37,6 +37,8 @@ def handle_error(
|
||||
class TradfriBaseEntity(CoordinatorEntity[TradfriDeviceDataUpdateCoordinator]):
|
||||
"""Base Tradfri device."""
|
||||
|
||||
_attr_has_entity_name = True
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
device_coordinator: TradfriDeviceDataUpdateCoordinator,
|
||||
@ -52,7 +54,6 @@ class TradfriBaseEntity(CoordinatorEntity[TradfriDeviceDataUpdateCoordinator]):
|
||||
|
||||
self._device_id = self._device.id
|
||||
self._api = handle_error(api)
|
||||
self._attr_name = self._device.name
|
||||
|
||||
self._attr_unique_id = f"{self._gateway_id}-{self._device.id}"
|
||||
|
||||
|
@ -40,6 +40,8 @@ async def async_setup_entry(
|
||||
class TradfriCover(TradfriBaseEntity, CoverEntity):
|
||||
"""The platform class required by Home Assistant."""
|
||||
|
||||
_attr_name = None
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
device_coordinator: TradfriDeviceDataUpdateCoordinator,
|
||||
|
@ -54,6 +54,7 @@ async def async_setup_entry(
|
||||
class TradfriAirPurifierFan(TradfriBaseEntity, FanEntity):
|
||||
"""The platform class required by Home Assistant."""
|
||||
|
||||
_attr_name = None
|
||||
_attr_supported_features = FanEntityFeature.PRESET_MODE | FanEntityFeature.SET_SPEED
|
||||
|
||||
def __init__(
|
||||
|
@ -49,6 +49,7 @@ async def async_setup_entry(
|
||||
class TradfriLight(TradfriBaseEntity, LightEntity):
|
||||
"""The platform class required by Home Assistant."""
|
||||
|
||||
_attr_name = None
|
||||
_attr_supported_features = LightEntityFeature.TRANSITION
|
||||
|
||||
def __init__(
|
||||
|
@ -24,7 +24,6 @@ from homeassistant.const import (
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import UNDEFINED
|
||||
|
||||
from .base_class import TradfriBaseEntity
|
||||
from .const import (
|
||||
@ -89,7 +88,7 @@ SENSOR_DESCRIPTIONS_BATTERY: tuple[TradfriSensorEntityDescription, ...] = (
|
||||
SENSOR_DESCRIPTIONS_FAN: tuple[TradfriSensorEntityDescription, ...] = (
|
||||
TradfriSensorEntityDescription(
|
||||
key="aqi",
|
||||
name="air quality",
|
||||
translation_key="aqi",
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||
icon="mdi:air-filter",
|
||||
@ -97,7 +96,7 @@ SENSOR_DESCRIPTIONS_FAN: tuple[TradfriSensorEntityDescription, ...] = (
|
||||
),
|
||||
TradfriSensorEntityDescription(
|
||||
key="filter_life_remaining",
|
||||
name="filter time left",
|
||||
translation_key="filter_life_remaining",
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
native_unit_of_measurement=UnitOfTime.HOURS,
|
||||
icon="mdi:clock-outline",
|
||||
@ -203,9 +202,6 @@ class TradfriSensor(TradfriBaseEntity, SensorEntity):
|
||||
|
||||
self._attr_unique_id = f"{self._attr_unique_id}-{description.key}"
|
||||
|
||||
if description.name is not UNDEFINED:
|
||||
self._attr_name = f"{self._attr_name}: {description.name}"
|
||||
|
||||
self._refresh() # Set initial state
|
||||
|
||||
def _refresh(self) -> None:
|
||||
|
@ -20,5 +20,15 @@
|
||||
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]",
|
||||
"already_in_progress": "[%key:common::config_flow::abort::already_in_progress%]"
|
||||
}
|
||||
},
|
||||
"entity": {
|
||||
"sensor": {
|
||||
"aqi": {
|
||||
"name": "Air quality"
|
||||
},
|
||||
"filter_life_remaining": {
|
||||
"name": "Filter time left"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -40,6 +40,8 @@ async def async_setup_entry(
|
||||
class TradfriSwitch(TradfriBaseEntity, SwitchEntity):
|
||||
"""The platform class required by Home Assistant."""
|
||||
|
||||
_attr_name = None
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
device_coordinator: TradfriDeviceDataUpdateCoordinator,
|
||||
|
@ -61,7 +61,7 @@ async def test_battery_sensor(
|
||||
remote_control: Device,
|
||||
) -> None:
|
||||
"""Test that a battery sensor is correctly added."""
|
||||
entity_id = "sensor.test"
|
||||
entity_id = "sensor.test_battery"
|
||||
device = remote_control
|
||||
mock_gateway.mock_devices.append(device)
|
||||
await setup_integration(hass)
|
||||
@ -92,7 +92,7 @@ async def test_cover_battery_sensor(
|
||||
blind: Blind,
|
||||
) -> None:
|
||||
"""Test that a battery sensor is correctly added for a cover (blind)."""
|
||||
entity_id = "sensor.test"
|
||||
entity_id = "sensor.test_battery"
|
||||
device = blind.device
|
||||
mock_gateway.mock_devices.append(device)
|
||||
await setup_integration(hass)
|
||||
|
Loading…
x
Reference in New Issue
Block a user