diff --git a/homeassistant/components/waqi/sensor.py b/homeassistant/components/waqi/sensor.py index 62170b329f4..e0ecf5827d8 100644 --- a/homeassistant/components/waqi/sensor.py +++ b/homeassistant/components/waqi/sensor.py @@ -24,6 +24,7 @@ from homeassistant.core import HomeAssistant from homeassistant.exceptions import PlatformNotReady from homeassistant.helpers.aiohttp_client import async_get_clientsession import homeassistant.helpers.config_validation as cv +from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType @@ -154,12 +155,18 @@ class WaqiSensor(CoordinatorEntity[WAQIDataUpdateCoordinator], SensorEntity): _attr_icon = ATTR_ICON _attr_device_class = SensorDeviceClass.AQI _attr_state_class = SensorStateClass.MEASUREMENT + _attr_has_entity_name = True + _attr_name = None def __init__(self, coordinator: WAQIDataUpdateCoordinator) -> None: """Initialize the sensor.""" super().__init__(coordinator) - self._attr_name = f"WAQI {self.coordinator.data.city.name}" self._attr_unique_id = f"{coordinator.data.station_id}_air_quality" + self._attr_device_info = DeviceInfo( + identifiers={(DOMAIN, str(coordinator.data.station_id))}, + name=coordinator.data.city.name, + entry_type=DeviceEntryType.SERVICE, + ) @property def native_value(self) -> int | None: diff --git a/tests/components/waqi/test_sensor.py b/tests/components/waqi/test_sensor.py index 7feb37a1b09..46bd577c48f 100644 --- a/tests/components/waqi/test_sensor.py +++ b/tests/components/waqi/test_sensor.py @@ -72,7 +72,7 @@ async def test_legacy_migration_already_imported( assert await async_setup_component(hass, DOMAIN, {}) await hass.async_block_till_done() - state = hass.states.get("sensor.waqi_de_jongweg_utrecht") + state = hass.states.get("sensor.de_jongweg_utrecht") assert state.state == "29" hass.async_create_task( @@ -116,7 +116,7 @@ async def test_sensor_id_migration( ) assert len(entities) == 1 assert hass.states.get("sensor.waqi_4584") - assert hass.states.get("sensor.waqi_de_jongweg_utrecht") is None + assert hass.states.get("sensor.de_jongweg_utrecht") is None assert entities[0].unique_id == "4584_air_quality" @@ -132,7 +132,7 @@ async def test_sensor(hass: HomeAssistant, mock_config_entry: MockConfigEntry) - assert await async_setup_component(hass, DOMAIN, {}) await hass.async_block_till_done() - state = hass.states.get("sensor.waqi_de_jongweg_utrecht") + state = hass.states.get("sensor.de_jongweg_utrecht") assert state.state == "29"