From 7070302001744a1d3b179c69161fdb57aa5d7215 Mon Sep 17 00:00:00 2001 From: Allen Porter Date: Sun, 27 Aug 2023 04:05:17 -0700 Subject: [PATCH] Use climate entity built in attrs for nest climate (#99093) * Use climate entity built in attrs for nest climate * Update homeassistant/components/nest/climate.py Co-authored-by: Shay Levy --------- Co-authored-by: Shay Levy --- homeassistant/components/nest/climate.py | 45 ++++++------------------ 1 file changed, 11 insertions(+), 34 deletions(-) diff --git a/homeassistant/components/nest/climate.py b/homeassistant/components/nest/climate.py index 0dcdec1cac1..03fb79eb78e 100644 --- a/homeassistant/components/nest/climate.py +++ b/homeassistant/components/nest/climate.py @@ -32,7 +32,6 @@ from homeassistant.config_entries import ConfigEntry from homeassistant.const import ATTR_TEMPERATURE, UnitOfTemperature from homeassistant.core import HomeAssistant from homeassistant.exceptions import HomeAssistantError -from homeassistant.helpers.device_registry import DeviceInfo from homeassistant.helpers.entity_platform import AddEntitiesCallback from .const import DATA_DEVICE_MANAGER, DOMAIN @@ -106,17 +105,18 @@ class ThermostatEntity(ClimateEntity): """Initialize ThermostatEntity.""" self._device = device self._device_info = NestDeviceInfo(device) - - @property - def unique_id(self) -> str | None: - """Return a unique ID.""" # The API "name" field is a unique device identifier. - return self._device.name - - @property - def device_info(self) -> DeviceInfo: - """Return device specific attributes.""" - return self._device_info.device_info + self._attr_unique_id = device.name + self._attr_device_info = self._device_info.device_info + self._attr_temperature_unit = UnitOfTemperature.CELSIUS + if mode_trait := device.traits.get(ThermostatModeTrait.NAME): + self._attr_hvac_modes = [ + THERMOSTAT_MODE_MAP[mode] + for mode in mode_trait.available_modes + if mode in THERMOSTAT_MODE_MAP + ] + else: + self._attr_hvac_modes = [] @property def available(self) -> bool: @@ -130,11 +130,6 @@ class ThermostatEntity(ClimateEntity): self._device.add_update_listener(self.async_write_ha_state) ) - @property - def temperature_unit(self) -> str: - """Return the unit of temperature measurement for the system.""" - return UnitOfTemperature.CELSIUS - @property def current_temperature(self) -> float | None: """Return the current temperature.""" @@ -201,24 +196,6 @@ class ThermostatEntity(ClimateEntity): hvac_mode = THERMOSTAT_MODE_MAP[trait.mode] return hvac_mode - @property - def hvac_modes(self) -> list[HVACMode]: - """List of available operation modes.""" - supported_modes = [] - for mode in self._get_device_hvac_modes: - if mode in THERMOSTAT_MODE_MAP: - supported_modes.append(THERMOSTAT_MODE_MAP[mode]) - return supported_modes - - @property - def _get_device_hvac_modes(self) -> set[str]: - """Return the set of SDM API hvac modes supported by the device.""" - modes = [] - if ThermostatModeTrait.NAME in self._device.traits: - trait = self._device.traits[ThermostatModeTrait.NAME] - modes.extend(trait.available_modes) - return set(modes) - @property def hvac_action(self) -> HVACAction | None: """Return the current HVAC action (heating, cooling)."""