Use EntityFeature enums in nest (#69590)
This commit is contained in:
parent
4a7c978f69
commit
04dab04ee7
4 changed files with 22 additions and 27 deletions
|
@ -17,7 +17,7 @@ from google_nest_sdm.camera_traits import (
|
||||||
from google_nest_sdm.device import Device
|
from google_nest_sdm.device import Device
|
||||||
from google_nest_sdm.exceptions import ApiException
|
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.components.camera.const import STREAM_TYPE_WEB_RTC
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
@ -110,7 +110,7 @@ class NestCamera(Camera):
|
||||||
"""Flag supported features."""
|
"""Flag supported features."""
|
||||||
supported_features = 0
|
supported_features = 0
|
||||||
if CameraLiveStreamTrait.NAME in self._device.traits:
|
if CameraLiveStreamTrait.NAME in self._device.traits:
|
||||||
supported_features |= SUPPORT_STREAM
|
supported_features |= CameraEntityFeature.STREAM
|
||||||
return supported_features
|
return supported_features
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -134,7 +134,7 @@ class NestCamera(Camera):
|
||||||
|
|
||||||
async def stream_source(self) -> str | None:
|
async def stream_source(self) -> str | None:
|
||||||
"""Return the source of the stream."""
|
"""Return the source of the stream."""
|
||||||
if not self.supported_features & SUPPORT_STREAM:
|
if not self.supported_features & CameraEntityFeature.STREAM:
|
||||||
return None
|
return None
|
||||||
if CameraLiveStreamTrait.NAME not in self._device.traits:
|
if CameraLiveStreamTrait.NAME not in self._device.traits:
|
||||||
return None
|
return None
|
||||||
|
|
|
@ -14,7 +14,7 @@ from google_nest_sdm.thermostat_traits import (
|
||||||
ThermostatTemperatureSetpointTrait,
|
ThermostatTemperatureSetpointTrait,
|
||||||
)
|
)
|
||||||
|
|
||||||
from homeassistant.components.climate import ClimateEntity
|
from homeassistant.components.climate import ClimateEntity, ClimateEntityFeature
|
||||||
from homeassistant.components.climate.const import (
|
from homeassistant.components.climate.const import (
|
||||||
ATTR_HVAC_MODE,
|
ATTR_HVAC_MODE,
|
||||||
ATTR_TARGET_TEMP_HIGH,
|
ATTR_TARGET_TEMP_HIGH,
|
||||||
|
@ -33,10 +33,6 @@ from homeassistant.components.climate.const import (
|
||||||
HVAC_MODE_OFF,
|
HVAC_MODE_OFF,
|
||||||
PRESET_ECO,
|
PRESET_ECO,
|
||||||
PRESET_NONE,
|
PRESET_NONE,
|
||||||
SUPPORT_FAN_MODE,
|
|
||||||
SUPPORT_PRESET_MODE,
|
|
||||||
SUPPORT_TARGET_TEMPERATURE,
|
|
||||||
SUPPORT_TARGET_TEMPERATURE_RANGE,
|
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS
|
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS
|
||||||
|
@ -219,7 +215,7 @@ class ThermostatEntity(ClimateEntity):
|
||||||
for mode in self._get_device_hvac_modes:
|
for mode in self._get_device_hvac_modes:
|
||||||
if mode in THERMOSTAT_MODE_MAP:
|
if mode in THERMOSTAT_MODE_MAP:
|
||||||
supported_modes.append(THERMOSTAT_MODE_MAP[mode])
|
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)
|
supported_modes.append(HVAC_MODE_FAN_ONLY)
|
||||||
return supported_modes
|
return supported_modes
|
||||||
|
|
||||||
|
@ -286,16 +282,16 @@ class ThermostatEntity(ClimateEntity):
|
||||||
"""Compute the bitmap of supported features from the current state."""
|
"""Compute the bitmap of supported features from the current state."""
|
||||||
features = 0
|
features = 0
|
||||||
if HVAC_MODE_HEAT_COOL in self.hvac_modes:
|
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:
|
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:
|
if ThermostatEcoTrait.NAME in self._device.traits:
|
||||||
features |= SUPPORT_PRESET_MODE
|
features |= ClimateEntityFeature.PRESET_MODE
|
||||||
if FanTrait.NAME in self._device.traits:
|
if FanTrait.NAME in self._device.traits:
|
||||||
# Fan trait may be present without actually support fan mode
|
# Fan trait may be present without actually support fan mode
|
||||||
fan_trait = self._device.traits[FanTrait.NAME]
|
fan_trait = self._device.traits[FanTrait.NAME]
|
||||||
if fan_trait.timer_mode is not None:
|
if fan_trait.timer_mode is not None:
|
||||||
features |= SUPPORT_FAN_MODE
|
features |= ClimateEntityFeature.FAN_MODE
|
||||||
return features
|
return features
|
||||||
|
|
||||||
async def async_set_hvac_mode(self, hvac_mode: str) -> None:
|
async def async_set_hvac_mode(self, hvac_mode: str) -> None:
|
||||||
|
|
|
@ -8,7 +8,7 @@ import logging
|
||||||
|
|
||||||
import requests
|
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.helpers.entity import DeviceInfo
|
||||||
from homeassistant.util.dt import utcnow
|
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):
|
class NestCamera(Camera):
|
||||||
"""Representation of a Nest Camera."""
|
"""Representation of a Nest Camera."""
|
||||||
|
|
||||||
|
_attr_supported_features = CameraEntityFeature.ON_OFF
|
||||||
|
|
||||||
def __init__(self, structure, device):
|
def __init__(self, structure, device):
|
||||||
"""Initialize a Nest Camera."""
|
"""Initialize a Nest Camera."""
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
@ -88,11 +90,6 @@ class NestCamera(Camera):
|
||||||
"""Return the brand of the camera."""
|
"""Return the brand of the camera."""
|
||||||
return NEST_BRAND
|
return NEST_BRAND
|
||||||
|
|
||||||
@property
|
|
||||||
def supported_features(self):
|
|
||||||
"""Nest Cam support turn on and off."""
|
|
||||||
return SUPPORT_ON_OFF
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self):
|
def is_on(self):
|
||||||
"""Return true if on."""
|
"""Return true if on."""
|
||||||
|
|
|
@ -6,7 +6,11 @@ import logging
|
||||||
from nest.nest import APIError
|
from nest.nest import APIError
|
||||||
import voluptuous as vol
|
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 (
|
from homeassistant.components.climate.const import (
|
||||||
ATTR_TARGET_TEMP_HIGH,
|
ATTR_TARGET_TEMP_HIGH,
|
||||||
ATTR_TARGET_TEMP_LOW,
|
ATTR_TARGET_TEMP_LOW,
|
||||||
|
@ -22,10 +26,6 @@ from homeassistant.components.climate.const import (
|
||||||
PRESET_AWAY,
|
PRESET_AWAY,
|
||||||
PRESET_ECO,
|
PRESET_ECO,
|
||||||
PRESET_NONE,
|
PRESET_NONE,
|
||||||
SUPPORT_FAN_MODE,
|
|
||||||
SUPPORT_PRESET_MODE,
|
|
||||||
SUPPORT_TARGET_TEMPERATURE,
|
|
||||||
SUPPORT_TARGET_TEMPERATURE_RANGE,
|
|
||||||
)
|
)
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_TEMPERATURE,
|
ATTR_TEMPERATURE,
|
||||||
|
@ -102,14 +102,16 @@ class NestThermostat(ClimateEntity):
|
||||||
self._fan_modes = [FAN_ON, FAN_AUTO]
|
self._fan_modes = [FAN_ON, FAN_AUTO]
|
||||||
|
|
||||||
# Set the default supported features
|
# 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
|
# Not all nest devices support cooling and heating remove unused
|
||||||
self._operation_list = []
|
self._operation_list = []
|
||||||
|
|
||||||
if self.device.can_heat and self.device.can_cool:
|
if self.device.can_heat and self.device.can_cool:
|
||||||
self._operation_list.append(HVAC_MODE_AUTO)
|
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
|
# Add supported nest thermostat features
|
||||||
if self.device.can_heat:
|
if self.device.can_heat:
|
||||||
|
@ -123,7 +125,7 @@ class NestThermostat(ClimateEntity):
|
||||||
# feature of device
|
# feature of device
|
||||||
self._has_fan = self.device.has_fan
|
self._has_fan = self.device.has_fan
|
||||||
if self._has_fan:
|
if self._has_fan:
|
||||||
self._support_flags |= SUPPORT_FAN_MODE
|
self._support_flags |= ClimateEntityFeature.FAN_MODE
|
||||||
|
|
||||||
# data attributes
|
# data attributes
|
||||||
self._away = None
|
self._away = None
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue