Use EntityFeature enums in nest (#69590)

This commit is contained in:
epenet 2022-04-07 16:52:18 +02:00 committed by GitHub
parent 4a7c978f69
commit 04dab04ee7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 27 deletions

View file

@ -17,7 +17,7 @@ from google_nest_sdm.camera_traits import (
from google_nest_sdm.device import Device
from google_nest_sdm.exceptions import ApiException
from homeassistant.components.camera import SUPPORT_STREAM, Camera
from homeassistant.components.camera import Camera, CameraEntityFeature
from homeassistant.components.camera.const import STREAM_TYPE_WEB_RTC
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
@ -110,7 +110,7 @@ class NestCamera(Camera):
"""Flag supported features."""
supported_features = 0
if CameraLiveStreamTrait.NAME in self._device.traits:
supported_features |= SUPPORT_STREAM
supported_features |= CameraEntityFeature.STREAM
return supported_features
@property
@ -134,7 +134,7 @@ class NestCamera(Camera):
async def stream_source(self) -> str | None:
"""Return the source of the stream."""
if not self.supported_features & SUPPORT_STREAM:
if not self.supported_features & CameraEntityFeature.STREAM:
return None
if CameraLiveStreamTrait.NAME not in self._device.traits:
return None

View file

@ -14,7 +14,7 @@ from google_nest_sdm.thermostat_traits import (
ThermostatTemperatureSetpointTrait,
)
from homeassistant.components.climate import ClimateEntity
from homeassistant.components.climate import ClimateEntity, ClimateEntityFeature
from homeassistant.components.climate.const import (
ATTR_HVAC_MODE,
ATTR_TARGET_TEMP_HIGH,
@ -33,10 +33,6 @@ from homeassistant.components.climate.const import (
HVAC_MODE_OFF,
PRESET_ECO,
PRESET_NONE,
SUPPORT_FAN_MODE,
SUPPORT_PRESET_MODE,
SUPPORT_TARGET_TEMPERATURE,
SUPPORT_TARGET_TEMPERATURE_RANGE,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS
@ -219,7 +215,7 @@ class ThermostatEntity(ClimateEntity):
for mode in self._get_device_hvac_modes:
if mode in THERMOSTAT_MODE_MAP:
supported_modes.append(THERMOSTAT_MODE_MAP[mode])
if self.supported_features & SUPPORT_FAN_MODE:
if self.supported_features & ClimateEntityFeature.FAN_MODE:
supported_modes.append(HVAC_MODE_FAN_ONLY)
return supported_modes
@ -286,16 +282,16 @@ class ThermostatEntity(ClimateEntity):
"""Compute the bitmap of supported features from the current state."""
features = 0
if HVAC_MODE_HEAT_COOL in self.hvac_modes:
features |= SUPPORT_TARGET_TEMPERATURE_RANGE
features |= ClimateEntityFeature.TARGET_TEMPERATURE_RANGE
if HVAC_MODE_HEAT in self.hvac_modes or HVAC_MODE_COOL in self.hvac_modes:
features |= SUPPORT_TARGET_TEMPERATURE
features |= ClimateEntityFeature.TARGET_TEMPERATURE
if ThermostatEcoTrait.NAME in self._device.traits:
features |= SUPPORT_PRESET_MODE
features |= ClimateEntityFeature.PRESET_MODE
if FanTrait.NAME in self._device.traits:
# Fan trait may be present without actually support fan mode
fan_trait = self._device.traits[FanTrait.NAME]
if fan_trait.timer_mode is not None:
features |= SUPPORT_FAN_MODE
features |= ClimateEntityFeature.FAN_MODE
return features
async def async_set_hvac_mode(self, hvac_mode: str) -> None:

View file

@ -8,7 +8,7 @@ import logging
import requests
from homeassistant.components.camera import PLATFORM_SCHEMA, SUPPORT_ON_OFF, Camera
from homeassistant.components.camera import PLATFORM_SCHEMA, Camera, CameraEntityFeature
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.util.dt import utcnow
@ -38,6 +38,8 @@ async def async_setup_legacy_entry(hass, entry, async_add_entities) -> None:
class NestCamera(Camera):
"""Representation of a Nest Camera."""
_attr_supported_features = CameraEntityFeature.ON_OFF
def __init__(self, structure, device):
"""Initialize a Nest Camera."""
super().__init__()
@ -88,11 +90,6 @@ class NestCamera(Camera):
"""Return the brand of the camera."""
return NEST_BRAND
@property
def supported_features(self):
"""Nest Cam support turn on and off."""
return SUPPORT_ON_OFF
@property
def is_on(self):
"""Return true if on."""

View file

@ -6,7 +6,11 @@ import logging
from nest.nest import APIError
import voluptuous as vol
from homeassistant.components.climate import PLATFORM_SCHEMA, ClimateEntity
from homeassistant.components.climate import (
PLATFORM_SCHEMA,
ClimateEntity,
ClimateEntityFeature,
)
from homeassistant.components.climate.const import (
ATTR_TARGET_TEMP_HIGH,
ATTR_TARGET_TEMP_LOW,
@ -22,10 +26,6 @@ from homeassistant.components.climate.const import (
PRESET_AWAY,
PRESET_ECO,
PRESET_NONE,
SUPPORT_FAN_MODE,
SUPPORT_PRESET_MODE,
SUPPORT_TARGET_TEMPERATURE,
SUPPORT_TARGET_TEMPERATURE_RANGE,
)
from homeassistant.const import (
ATTR_TEMPERATURE,
@ -102,14 +102,16 @@ class NestThermostat(ClimateEntity):
self._fan_modes = [FAN_ON, FAN_AUTO]
# Set the default supported features
self._support_flags = SUPPORT_TARGET_TEMPERATURE | SUPPORT_PRESET_MODE
self._support_flags = (
ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE
)
# Not all nest devices support cooling and heating remove unused
self._operation_list = []
if self.device.can_heat and self.device.can_cool:
self._operation_list.append(HVAC_MODE_AUTO)
self._support_flags |= SUPPORT_TARGET_TEMPERATURE_RANGE
self._support_flags |= ClimateEntityFeature.TARGET_TEMPERATURE_RANGE
# Add supported nest thermostat features
if self.device.can_heat:
@ -123,7 +125,7 @@ class NestThermostat(ClimateEntity):
# feature of device
self._has_fan = self.device.has_fan
if self._has_fan:
self._support_flags |= SUPPORT_FAN_MODE
self._support_flags |= ClimateEntityFeature.FAN_MODE
# data attributes
self._away = None