Migrate nest to new entity naming style (#74724)

This commit is contained in:
Allen Porter 2022-07-09 10:21:53 -07:00 committed by GitHub
parent 24ca656372
commit 1c4fee65c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 12 additions and 25 deletions

View File

@ -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."""

View File

@ -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."""

View File

@ -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:

View File

@ -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)

View File

@ -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)

View File

@ -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)