diff --git a/homeassistant/components/nest/camera_sdm.py b/homeassistant/components/nest/camera_sdm.py index 4e38338aee8..c26b216b21f 100644 --- a/homeassistant/components/nest/camera_sdm.py +++ b/homeassistant/components/nest/camera_sdm.py @@ -61,6 +61,8 @@ async def async_setup_sdm_entry( class NestCamera(Camera): """Devices that support cameras.""" + _attr_has_entity_name = True + def __init__(self, device: Device) -> None: """Initialize the camera.""" super().__init__() @@ -83,11 +85,6 @@ class NestCamera(Camera): # The API "name" field is a unique device identifier. return f"{self._device.name}-camera" - @property - def name(self) -> str | None: - """Return the name of the camera.""" - return self._device_info.device_name - @property def device_info(self) -> DeviceInfo: """Return device specific attributes.""" diff --git a/homeassistant/components/nest/climate_sdm.py b/homeassistant/components/nest/climate_sdm.py index 452c30073da..c13370776ad 100644 --- a/homeassistant/components/nest/climate_sdm.py +++ b/homeassistant/components/nest/climate_sdm.py @@ -97,6 +97,7 @@ class ThermostatEntity(ClimateEntity): _attr_min_temp = MIN_TEMP _attr_max_temp = MAX_TEMP + _attr_has_entity_name = True def __init__(self, device: Device) -> None: """Initialize ThermostatEntity.""" @@ -115,11 +116,6 @@ class ThermostatEntity(ClimateEntity): # The API "name" field is a unique device identifier. return self._device.name - @property - def name(self) -> str | None: - """Return the name of the entity.""" - return self._device_info.device_name - @property def device_info(self) -> DeviceInfo: """Return device specific attributes.""" diff --git a/homeassistant/components/nest/sensor_sdm.py b/homeassistant/components/nest/sensor_sdm.py index c6d1c8b2b30..11edc9f3506 100644 --- a/homeassistant/components/nest/sensor_sdm.py +++ b/homeassistant/components/nest/sensor_sdm.py @@ -53,6 +53,7 @@ class SensorBase(SensorEntity): _attr_should_poll = False _attr_state_class = SensorStateClass.MEASUREMENT + _attr_has_entity_name = True def __init__(self, device: Device) -> None: """Initialize the sensor.""" @@ -73,11 +74,7 @@ class TemperatureSensor(SensorBase): _attr_device_class = SensorDeviceClass.TEMPERATURE _attr_native_unit_of_measurement = TEMP_CELSIUS - - @property - def name(self) -> str: - """Return the name of the sensor.""" - return f"{self._device_info.device_name} Temperature" + _attr_name = "Temperature" @property def native_value(self) -> float: @@ -94,11 +91,7 @@ class HumiditySensor(SensorBase): _attr_device_class = SensorDeviceClass.HUMIDITY _attr_native_unit_of_measurement = PERCENTAGE - - @property - def name(self) -> str: - """Return the name of the sensor.""" - return f"{self._device_info.device_name} Humidity" + _attr_name = "Humidity" @property def native_value(self) -> int: diff --git a/tests/components/nest/test_camera_sdm.py b/tests/components/nest/test_camera_sdm.py index 5c4194f46f6..86f05c613ed 100644 --- a/tests/components/nest/test_camera_sdm.py +++ b/tests/components/nest/test_camera_sdm.py @@ -17,6 +17,7 @@ from homeassistant.components import camera from homeassistant.components.camera import STATE_IDLE, STATE_STREAMING, StreamType from homeassistant.components.nest.const import DOMAIN from homeassistant.components.websocket_api.const import TYPE_RESULT +from homeassistant.const import ATTR_FRIENDLY_NAME from homeassistant.core import HomeAssistant from homeassistant.helpers import device_registry as dr, entity_registry as er from homeassistant.setup import async_setup_component @@ -210,11 +211,11 @@ async def test_camera_device( camera = hass.states.get("camera.my_camera") assert camera is not None assert camera.state == STATE_STREAMING + assert camera.attributes.get(ATTR_FRIENDLY_NAME) == "My Camera" registry = er.async_get(hass) entry = registry.async_get("camera.my_camera") assert entry.unique_id == f"{DEVICE_ID}-camera" - assert entry.original_name == "My Camera" assert entry.domain == "camera" device_registry = dr.async_get(hass) diff --git a/tests/components/nest/test_events.py b/tests/components/nest/test_events.py index 83845586764..1fffcc9042b 100644 --- a/tests/components/nest/test_events.py +++ b/tests/components/nest/test_events.py @@ -160,7 +160,6 @@ async def test_event( entry = registry.async_get("camera.front") assert entry is not None assert entry.unique_id == "some-device-id-camera" - assert entry.original_name == "Front" assert entry.domain == "camera" device_registry = dr.async_get(hass) diff --git a/tests/components/nest/test_sensor_sdm.py b/tests/components/nest/test_sensor_sdm.py index bb49f13b3eb..0f98d0c05b4 100644 --- a/tests/components/nest/test_sensor_sdm.py +++ b/tests/components/nest/test_sensor_sdm.py @@ -13,6 +13,7 @@ import pytest from homeassistant.components.sensor import ATTR_STATE_CLASS, STATE_CLASS_MEASUREMENT from homeassistant.const import ( ATTR_DEVICE_CLASS, + ATTR_FRIENDLY_NAME, ATTR_UNIT_OF_MEASUREMENT, DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_TEMPERATURE, @@ -59,6 +60,7 @@ async def test_thermostat_device( assert temperature.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == TEMP_CELSIUS assert temperature.attributes.get(ATTR_DEVICE_CLASS) == DEVICE_CLASS_TEMPERATURE assert temperature.attributes.get(ATTR_STATE_CLASS) == STATE_CLASS_MEASUREMENT + assert temperature.attributes.get(ATTR_FRIENDLY_NAME) == "My Sensor Temperature" humidity = hass.states.get("sensor.my_sensor_humidity") assert humidity is not None @@ -66,16 +68,15 @@ async def test_thermostat_device( assert humidity.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == PERCENTAGE assert humidity.attributes.get(ATTR_DEVICE_CLASS) == DEVICE_CLASS_HUMIDITY assert humidity.attributes.get(ATTR_STATE_CLASS) == STATE_CLASS_MEASUREMENT + assert humidity.attributes.get(ATTR_FRIENDLY_NAME) == "My Sensor Humidity" registry = er.async_get(hass) entry = registry.async_get("sensor.my_sensor_temperature") assert entry.unique_id == f"{DEVICE_ID}-temperature" - assert entry.original_name == "My Sensor Temperature" assert entry.domain == "sensor" entry = registry.async_get("sensor.my_sensor_humidity") assert entry.unique_id == f"{DEVICE_ID}-humidity" - assert entry.original_name == "My Sensor Humidity" assert entry.domain == "sensor" device_registry = dr.async_get(hass) @@ -195,11 +196,11 @@ async def test_device_with_unknown_type( temperature = hass.states.get("sensor.my_sensor_temperature") assert temperature is not None assert temperature.state == "25.1" + assert temperature.attributes.get(ATTR_FRIENDLY_NAME) == "My Sensor Temperature" registry = er.async_get(hass) entry = registry.async_get("sensor.my_sensor_temperature") assert entry.unique_id == f"{DEVICE_ID}-temperature" - assert entry.original_name == "My Sensor Temperature" assert entry.domain == "sensor" device_registry = dr.async_get(hass)