Use EntityFeature enum in components (t**) (#69457)
This commit is contained in:
parent
889e1f4442
commit
bbf19582bb
15 changed files with 102 additions and 127 deletions
|
@ -3,7 +3,7 @@ import logging
|
|||
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.climate import ClimateEntity
|
||||
from homeassistant.components.climate import ClimateEntity, ClimateEntityFeature
|
||||
from homeassistant.components.climate.const import (
|
||||
CURRENT_HVAC_OFF,
|
||||
FAN_AUTO,
|
||||
|
@ -11,10 +11,6 @@ from homeassistant.components.climate.const import (
|
|||
HVAC_MODE_OFF,
|
||||
PRESET_AWAY,
|
||||
PRESET_HOME,
|
||||
SUPPORT_FAN_MODE,
|
||||
SUPPORT_PRESET_MODE,
|
||||
SUPPORT_SWING_MODE,
|
||||
SUPPORT_TARGET_TEMPERATURE,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import ATTR_TEMPERATURE, PRECISION_TENTHS, TEMP_CELSIUS
|
||||
|
@ -128,7 +124,9 @@ def create_climate_entity(tado, name: str, zone_id: int, device_info: dict):
|
|||
_LOGGER.debug("Capabilities for zone %s: %s", zone_id, capabilities)
|
||||
|
||||
zone_type = capabilities["type"]
|
||||
support_flags = SUPPORT_PRESET_MODE | SUPPORT_TARGET_TEMPERATURE
|
||||
support_flags = (
|
||||
ClimateEntityFeature.PRESET_MODE | ClimateEntityFeature.TARGET_TEMPERATURE
|
||||
)
|
||||
supported_hvac_modes = [
|
||||
TADO_TO_HA_HVAC_MODE_MAP[CONST_MODE_OFF],
|
||||
TADO_TO_HA_HVAC_MODE_MAP[CONST_MODE_SMART_SCHEDULE],
|
||||
|
@ -145,12 +143,12 @@ def create_climate_entity(tado, name: str, zone_id: int, device_info: dict):
|
|||
|
||||
supported_hvac_modes.append(TADO_TO_HA_HVAC_MODE_MAP[mode])
|
||||
if capabilities[mode].get("swings"):
|
||||
support_flags |= SUPPORT_SWING_MODE
|
||||
support_flags |= ClimateEntityFeature.SWING_MODE
|
||||
|
||||
if not capabilities[mode].get("fanSpeeds"):
|
||||
continue
|
||||
|
||||
support_flags |= SUPPORT_FAN_MODE
|
||||
support_flags |= ClimateEntityFeature.FAN_MODE
|
||||
|
||||
if supported_fan_modes:
|
||||
continue
|
||||
|
@ -469,7 +467,7 @@ class TadoClimate(TadoZoneEntity, ClimateEntity):
|
|||
@property
|
||||
def swing_modes(self):
|
||||
"""Swing modes for the device."""
|
||||
if self._support_flags & SUPPORT_SWING_MODE:
|
||||
if self._support_flags & ClimateEntityFeature.SWING_MODE:
|
||||
return [TADO_SWING_ON, TADO_SWING_OFF]
|
||||
return None
|
||||
|
||||
|
@ -621,10 +619,10 @@ class TadoClimate(TadoZoneEntity, ClimateEntity):
|
|||
temperature_to_send = None
|
||||
|
||||
fan_speed = None
|
||||
if self._support_flags & SUPPORT_FAN_MODE:
|
||||
if self._support_flags & ClimateEntityFeature.FAN_MODE:
|
||||
fan_speed = self._current_tado_fan_speed
|
||||
swing = None
|
||||
if self._support_flags & SUPPORT_SWING_MODE:
|
||||
if self._support_flags & ClimateEntityFeature.SWING_MODE:
|
||||
swing = self._current_tado_swing_mode
|
||||
|
||||
self._tado.set_zone_overlay(
|
||||
|
|
|
@ -4,9 +4,8 @@ import logging
|
|||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.water_heater import (
|
||||
SUPPORT_OPERATION_MODE,
|
||||
SUPPORT_TARGET_TEMPERATURE,
|
||||
WaterHeaterEntity,
|
||||
WaterHeaterEntityFeature,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS
|
||||
|
@ -48,8 +47,6 @@ WATER_HEATER_MAP_TADO = {
|
|||
CONST_MODE_OFF: MODE_OFF,
|
||||
}
|
||||
|
||||
SUPPORT_FLAGS_HEATER = SUPPORT_OPERATION_MODE
|
||||
|
||||
SERVICE_WATER_HEATER_TIMER = "set_water_heater_timer"
|
||||
ATTR_TIME_PERIOD = "time_period"
|
||||
|
||||
|
@ -147,9 +144,9 @@ class TadoWaterHeater(TadoZoneEntity, WaterHeaterEntity):
|
|||
|
||||
self._target_temp = None
|
||||
|
||||
self._supported_features = SUPPORT_FLAGS_HEATER
|
||||
self._attr_supported_features = WaterHeaterEntityFeature.OPERATION_MODE
|
||||
if self._supports_temperature_control:
|
||||
self._supported_features |= SUPPORT_TARGET_TEMPERATURE
|
||||
self._attr_supported_features |= WaterHeaterEntityFeature.TARGET_TEMPERATURE
|
||||
|
||||
self._current_tado_hvac_mode = CONST_MODE_SMART_SCHEDULE
|
||||
self._overlay_mode = CONST_MODE_SMART_SCHEDULE
|
||||
|
@ -169,11 +166,6 @@ class TadoWaterHeater(TadoZoneEntity, WaterHeaterEntity):
|
|||
)
|
||||
self._async_update_data()
|
||||
|
||||
@property
|
||||
def supported_features(self):
|
||||
"""Return the list of supported features."""
|
||||
return self._supported_features
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the entity."""
|
||||
|
|
|
@ -7,8 +7,12 @@ from hatasmota import const as tasmota_const, shutter as tasmota_shutter
|
|||
from hatasmota.entity import TasmotaEntity as HATasmotaEntity
|
||||
from hatasmota.models import DiscoveryHashType
|
||||
|
||||
from homeassistant.components import cover
|
||||
from homeassistant.components.cover import CoverEntity
|
||||
from homeassistant.components.cover import (
|
||||
ATTR_POSITION,
|
||||
DOMAIN as COVER_DOMAIN,
|
||||
CoverEntity,
|
||||
CoverEntityFeature,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
|
@ -36,10 +40,10 @@ async def async_setup_entry(
|
|||
)
|
||||
|
||||
hass.data[
|
||||
DATA_REMOVE_DISCOVER_COMPONENT.format(cover.DOMAIN)
|
||||
DATA_REMOVE_DISCOVER_COMPONENT.format(COVER_DOMAIN)
|
||||
] = async_dispatcher_connect(
|
||||
hass,
|
||||
TASMOTA_DISCOVERY_ENTITY_NEW.format(cover.DOMAIN),
|
||||
TASMOTA_DISCOVERY_ENTITY_NEW.format(COVER_DOMAIN),
|
||||
async_discover,
|
||||
)
|
||||
|
||||
|
@ -51,6 +55,12 @@ class TasmotaCover(
|
|||
):
|
||||
"""Representation of a Tasmota cover."""
|
||||
|
||||
_attr_supported_features = (
|
||||
CoverEntityFeature.OPEN
|
||||
| CoverEntityFeature.CLOSE
|
||||
| CoverEntityFeature.STOP
|
||||
| CoverEntityFeature.SET_POSITION
|
||||
)
|
||||
_tasmota_entity: tasmota_shutter.TasmotaShutter
|
||||
|
||||
def __init__(self, **kwds: Any) -> None:
|
||||
|
@ -82,16 +92,6 @@ class TasmotaCover(
|
|||
"""
|
||||
return self._position
|
||||
|
||||
@property
|
||||
def supported_features(self) -> int:
|
||||
"""Flag supported features."""
|
||||
return (
|
||||
cover.SUPPORT_OPEN
|
||||
| cover.SUPPORT_CLOSE
|
||||
| cover.SUPPORT_STOP
|
||||
| cover.SUPPORT_SET_POSITION
|
||||
)
|
||||
|
||||
@property
|
||||
def is_opening(self) -> bool:
|
||||
"""Return if the cover is opening or not."""
|
||||
|
@ -119,7 +119,7 @@ class TasmotaCover(
|
|||
|
||||
async def async_set_cover_position(self, **kwargs: Any) -> None:
|
||||
"""Move the cover to a specific position."""
|
||||
position = kwargs[cover.ATTR_POSITION]
|
||||
position = kwargs[ATTR_POSITION]
|
||||
await self._tasmota_entity.set_position(position)
|
||||
|
||||
async def async_stop_cover(self, **kwargs: Any) -> None:
|
||||
|
|
|
@ -7,8 +7,11 @@ from hatasmota import const as tasmota_const, fan as tasmota_fan
|
|||
from hatasmota.entity import TasmotaEntity as HATasmotaEntity
|
||||
from hatasmota.models import DiscoveryHashType
|
||||
|
||||
from homeassistant.components import fan
|
||||
from homeassistant.components.fan import FanEntity
|
||||
from homeassistant.components.fan import (
|
||||
DOMAIN as FAN_DOMAIN,
|
||||
FanEntity,
|
||||
FanEntityFeature,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
|
@ -46,10 +49,10 @@ async def async_setup_entry(
|
|||
)
|
||||
|
||||
hass.data[
|
||||
DATA_REMOVE_DISCOVER_COMPONENT.format(fan.DOMAIN)
|
||||
DATA_REMOVE_DISCOVER_COMPONENT.format(FAN_DOMAIN)
|
||||
] = async_dispatcher_connect(
|
||||
hass,
|
||||
TASMOTA_DISCOVERY_ENTITY_NEW.format(fan.DOMAIN),
|
||||
TASMOTA_DISCOVERY_ENTITY_NEW.format(FAN_DOMAIN),
|
||||
async_discover,
|
||||
)
|
||||
|
||||
|
@ -61,6 +64,7 @@ class TasmotaFan(
|
|||
):
|
||||
"""Representation of a Tasmota fan."""
|
||||
|
||||
_attr_supported_features = FanEntityFeature.SET_SPEED
|
||||
_tasmota_entity: tasmota_fan.TasmotaFan
|
||||
|
||||
def __init__(self, **kwds: Any) -> None:
|
||||
|
@ -96,11 +100,6 @@ class TasmotaFan(
|
|||
return 0
|
||||
return ordered_list_item_to_percentage(ORDERED_NAMED_FAN_SPEEDS, self._state)
|
||||
|
||||
@property
|
||||
def supported_features(self) -> int:
|
||||
"""Flag supported features."""
|
||||
return fan.SUPPORT_SET_SPEED
|
||||
|
||||
async def async_set_percentage(self, percentage: int) -> None:
|
||||
"""Set the speed of the fan."""
|
||||
if percentage == 0:
|
||||
|
|
|
@ -8,7 +8,11 @@ import logging
|
|||
from pytfiac import Tfiac
|
||||
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 (
|
||||
FAN_AUTO,
|
||||
FAN_HIGH,
|
||||
|
@ -20,9 +24,6 @@ from homeassistant.components.climate.const import (
|
|||
HVAC_MODE_FAN_ONLY,
|
||||
HVAC_MODE_HEAT,
|
||||
HVAC_MODE_OFF,
|
||||
SUPPORT_FAN_MODE,
|
||||
SUPPORT_SWING_MODE,
|
||||
SUPPORT_TARGET_TEMPERATURE,
|
||||
SWING_BOTH,
|
||||
SWING_HORIZONTAL,
|
||||
SWING_OFF,
|
||||
|
@ -57,8 +58,6 @@ HVAC_MAP_REV = {v: k for k, v in HVAC_MAP.items()}
|
|||
SUPPORT_FAN = [FAN_AUTO, FAN_HIGH, FAN_MEDIUM, FAN_LOW]
|
||||
SUPPORT_SWING = [SWING_OFF, SWING_HORIZONTAL, SWING_VERTICAL, SWING_BOTH]
|
||||
|
||||
SUPPORT_FLAGS = SUPPORT_FAN_MODE | SUPPORT_SWING_MODE | SUPPORT_TARGET_TEMPERATURE
|
||||
|
||||
CURR_TEMP = "current_temp"
|
||||
TARGET_TEMP = "target_temp"
|
||||
OPERATION_MODE = "operation"
|
||||
|
@ -86,6 +85,12 @@ async def async_setup_platform(
|
|||
class TfiacClimate(ClimateEntity):
|
||||
"""TFIAC class."""
|
||||
|
||||
_attr_supported_features = (
|
||||
ClimateEntityFeature.FAN_MODE
|
||||
| ClimateEntityFeature.SWING_MODE
|
||||
| ClimateEntityFeature.TARGET_TEMPERATURE
|
||||
)
|
||||
|
||||
def __init__(self, hass, client):
|
||||
"""Init class."""
|
||||
self._client = client
|
||||
|
@ -104,11 +109,6 @@ class TfiacClimate(ClimateEntity):
|
|||
except futures.TimeoutError:
|
||||
self._available = False
|
||||
|
||||
@property
|
||||
def supported_features(self):
|
||||
"""Return the list of supported features."""
|
||||
return SUPPORT_FLAGS
|
||||
|
||||
@property
|
||||
def min_temp(self):
|
||||
"""Return the minimum temperature."""
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
"""TOLO Sauna climate controls (main sauna control)."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
@ -10,6 +9,7 @@ from homeassistant.components.climate import (
|
|||
HVAC_MODE_HEAT,
|
||||
HVAC_MODE_OFF,
|
||||
ClimateEntity,
|
||||
ClimateEntityFeature,
|
||||
)
|
||||
from homeassistant.components.climate.const import (
|
||||
CURRENT_HVAC_DRY,
|
||||
|
@ -19,9 +19,6 @@ from homeassistant.components.climate.const import (
|
|||
FAN_OFF,
|
||||
FAN_ON,
|
||||
HVAC_MODE_DRY,
|
||||
SUPPORT_FAN_MODE,
|
||||
SUPPORT_TARGET_HUMIDITY,
|
||||
SUPPORT_TARGET_TEMPERATURE,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import ATTR_TEMPERATURE, PRECISION_WHOLE, TEMP_CELSIUS
|
||||
|
@ -60,7 +57,9 @@ class SaunaClimate(ToloSaunaCoordinatorEntity, ClimateEntity):
|
|||
_attr_name = "Sauna Climate"
|
||||
_attr_precision = PRECISION_WHOLE
|
||||
_attr_supported_features = (
|
||||
SUPPORT_TARGET_TEMPERATURE | SUPPORT_TARGET_HUMIDITY | SUPPORT_FAN_MODE
|
||||
ClimateEntityFeature.TARGET_TEMPERATURE
|
||||
| ClimateEntityFeature.TARGET_HUMIDITY
|
||||
| ClimateEntityFeature.FAN_MODE
|
||||
)
|
||||
_attr_target_temperature_step = 1
|
||||
_attr_temperature_unit = TEMP_CELSIUS
|
||||
|
|
|
@ -10,7 +10,7 @@ from toonapi import (
|
|||
ACTIVE_STATE_SLEEP,
|
||||
)
|
||||
|
||||
from homeassistant.components.climate import ClimateEntity
|
||||
from homeassistant.components.climate import ClimateEntity, ClimateEntityFeature
|
||||
from homeassistant.components.climate.const import (
|
||||
CURRENT_HVAC_HEAT,
|
||||
CURRENT_HVAC_IDLE,
|
||||
|
@ -19,8 +19,6 @@ from homeassistant.components.climate.const import (
|
|||
PRESET_COMFORT,
|
||||
PRESET_HOME,
|
||||
PRESET_SLEEP,
|
||||
SUPPORT_PRESET_MODE,
|
||||
SUPPORT_TARGET_TEMPERATURE,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS
|
||||
|
@ -49,7 +47,9 @@ class ToonThermostatDevice(ToonDisplayDeviceEntity, ClimateEntity):
|
|||
_attr_max_temp = DEFAULT_MAX_TEMP
|
||||
_attr_min_temp = DEFAULT_MIN_TEMP
|
||||
_attr_name = "Thermostat"
|
||||
_attr_supported_features = SUPPORT_TARGET_TEMPERATURE | SUPPORT_PRESET_MODE
|
||||
_attr_supported_features = (
|
||||
ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE
|
||||
)
|
||||
_attr_temperature_unit = TEMP_CELSIUS
|
||||
|
||||
def __init__(
|
||||
|
|
|
@ -3,11 +3,7 @@ from total_connect_client import ArmingHelper
|
|||
from total_connect_client.exceptions import BadResultCodeError, UsercodeInvalid
|
||||
|
||||
import homeassistant.components.alarm_control_panel as alarm
|
||||
from homeassistant.components.alarm_control_panel.const import (
|
||||
SUPPORT_ALARM_ARM_AWAY,
|
||||
SUPPORT_ALARM_ARM_HOME,
|
||||
SUPPORT_ALARM_ARM_NIGHT,
|
||||
)
|
||||
from homeassistant.components.alarm_control_panel import AlarmControlPanelEntityFeature
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
STATE_ALARM_ARMED_AWAY,
|
||||
|
@ -72,6 +68,12 @@ async def async_setup_entry(
|
|||
class TotalConnectAlarm(CoordinatorEntity, alarm.AlarmControlPanelEntity):
|
||||
"""Represent an TotalConnect status."""
|
||||
|
||||
_attr_supported_features = (
|
||||
AlarmControlPanelEntityFeature.ARM_HOME
|
||||
| AlarmControlPanelEntityFeature.ARM_AWAY
|
||||
| AlarmControlPanelEntityFeature.ARM_NIGHT
|
||||
)
|
||||
|
||||
def __init__(self, coordinator, name, location_id, partition_id):
|
||||
"""Initialize the TotalConnect status."""
|
||||
super().__init__(coordinator)
|
||||
|
@ -156,11 +158,6 @@ class TotalConnectAlarm(CoordinatorEntity, alarm.AlarmControlPanelEntity):
|
|||
|
||||
return self._state
|
||||
|
||||
@property
|
||||
def supported_features(self) -> int:
|
||||
"""Return the list of supported features."""
|
||||
return SUPPORT_ALARM_ARM_HOME | SUPPORT_ALARM_ARM_AWAY | SUPPORT_ALARM_ARM_NIGHT
|
||||
|
||||
@property
|
||||
def extra_state_attributes(self):
|
||||
"""Return the state attributes of the device."""
|
||||
|
|
|
@ -6,12 +6,12 @@ from typing import NamedTuple
|
|||
from pytouchline import PyTouchline
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.climate import PLATFORM_SCHEMA, ClimateEntity
|
||||
from homeassistant.components.climate.const import (
|
||||
HVAC_MODE_HEAT,
|
||||
SUPPORT_PRESET_MODE,
|
||||
SUPPORT_TARGET_TEMPERATURE,
|
||||
from homeassistant.components.climate import (
|
||||
PLATFORM_SCHEMA,
|
||||
ClimateEntity,
|
||||
ClimateEntityFeature,
|
||||
)
|
||||
from homeassistant.components.climate.const import HVAC_MODE_HEAT
|
||||
from homeassistant.const import ATTR_TEMPERATURE, CONF_HOST, TEMP_CELSIUS
|
||||
from homeassistant.core import HomeAssistant
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
@ -40,8 +40,6 @@ TOUCHLINE_HA_PRESETS = {
|
|||
for preset, settings in PRESET_MODES.items()
|
||||
}
|
||||
|
||||
SUPPORT_FLAGS = SUPPORT_TARGET_TEMPERATURE | SUPPORT_PRESET_MODE
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({vol.Required(CONF_HOST): cv.string})
|
||||
|
||||
|
||||
|
@ -65,6 +63,10 @@ def setup_platform(
|
|||
class Touchline(ClimateEntity):
|
||||
"""Representation of a Touchline device."""
|
||||
|
||||
_attr_supported_features = (
|
||||
ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE
|
||||
)
|
||||
|
||||
def __init__(self, touchline_thermostat):
|
||||
"""Initialize the Touchline device."""
|
||||
self.unit = touchline_thermostat
|
||||
|
@ -74,11 +76,6 @@ class Touchline(ClimateEntity):
|
|||
self._current_operation_mode = None
|
||||
self._preset_mode = None
|
||||
|
||||
@property
|
||||
def supported_features(self):
|
||||
"""Return the list of supported features."""
|
||||
return SUPPORT_FLAGS
|
||||
|
||||
def update(self):
|
||||
"""Update thermostat attributes."""
|
||||
self.unit.update()
|
||||
|
|
|
@ -5,11 +5,9 @@ from tuya_iot import TuyaDevice, TuyaDeviceManager
|
|||
|
||||
from homeassistant.backports.enum import StrEnum
|
||||
from homeassistant.components.alarm_control_panel import (
|
||||
SUPPORT_ALARM_ARM_AWAY,
|
||||
SUPPORT_ALARM_ARM_HOME,
|
||||
SUPPORT_ALARM_TRIGGER,
|
||||
AlarmControlPanelEntity,
|
||||
AlarmControlPanelEntityDescription,
|
||||
AlarmControlPanelEntityFeature,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
|
@ -109,13 +107,13 @@ class TuyaAlarmEntity(TuyaEntity, AlarmControlPanelEntity):
|
|||
description.key, dptype=DPType.ENUM, prefer_function=True
|
||||
):
|
||||
if Mode.HOME in supported_modes.range:
|
||||
self._attr_supported_features |= SUPPORT_ALARM_ARM_HOME
|
||||
self._attr_supported_features |= AlarmControlPanelEntityFeature.ARM_HOME
|
||||
|
||||
if Mode.ARM in supported_modes.range:
|
||||
self._attr_supported_features |= SUPPORT_ALARM_ARM_AWAY
|
||||
self._attr_supported_features |= AlarmControlPanelEntityFeature.ARM_AWAY
|
||||
|
||||
if Mode.SOS in supported_modes.range:
|
||||
self._attr_supported_features |= SUPPORT_ALARM_TRIGGER
|
||||
self._attr_supported_features |= AlarmControlPanelEntityFeature.TRIGGER
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
|
|
|
@ -4,7 +4,7 @@ from __future__ import annotations
|
|||
from tuya_iot import TuyaDevice, TuyaDeviceManager
|
||||
|
||||
from homeassistant.components import ffmpeg
|
||||
from homeassistant.components.camera import SUPPORT_STREAM, Camera as CameraEntity
|
||||
from homeassistant.components.camera import Camera as CameraEntity, CameraEntityFeature
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
|
@ -50,7 +50,7 @@ async def async_setup_entry(
|
|||
class TuyaCameraEntity(TuyaEntity, CameraEntity):
|
||||
"""Tuya Camera Entity."""
|
||||
|
||||
_attr_supported_features = SUPPORT_STREAM
|
||||
_attr_supported_features = CameraEntityFeature.STREAM
|
||||
_attr_brand = "Tuya"
|
||||
|
||||
def __init__(
|
||||
|
|
|
@ -6,7 +6,11 @@ from typing import Any
|
|||
|
||||
from tuya_iot import TuyaDevice, TuyaDeviceManager
|
||||
|
||||
from homeassistant.components.climate import ClimateEntity, ClimateEntityDescription
|
||||
from homeassistant.components.climate import (
|
||||
ClimateEntity,
|
||||
ClimateEntityDescription,
|
||||
ClimateEntityFeature,
|
||||
)
|
||||
from homeassistant.components.climate.const import (
|
||||
HVAC_MODE_COOL,
|
||||
HVAC_MODE_DRY,
|
||||
|
@ -14,10 +18,6 @@ from homeassistant.components.climate.const import (
|
|||
HVAC_MODE_HEAT,
|
||||
HVAC_MODE_HEAT_COOL,
|
||||
HVAC_MODE_OFF,
|
||||
SUPPORT_FAN_MODE,
|
||||
SUPPORT_SWING_MODE,
|
||||
SUPPORT_TARGET_HUMIDITY,
|
||||
SUPPORT_TARGET_TEMPERATURE,
|
||||
SWING_BOTH,
|
||||
SWING_HORIZONTAL,
|
||||
SWING_OFF,
|
||||
|
@ -201,7 +201,7 @@ class TuyaClimateEntity(TuyaEntity, ClimateEntity):
|
|||
# Get integer type data for the dpcode to set temperature, use
|
||||
# it to define min, max & step temperatures
|
||||
if self._set_temperature:
|
||||
self._attr_supported_features |= SUPPORT_TARGET_TEMPERATURE
|
||||
self._attr_supported_features |= ClimateEntityFeature.TARGET_TEMPERATURE
|
||||
self._attr_max_temp = self._set_temperature.max_scaled
|
||||
self._attr_min_temp = self._set_temperature.min_scaled
|
||||
self._attr_target_temperature_step = self._set_temperature.step_scaled
|
||||
|
@ -227,7 +227,7 @@ class TuyaClimateEntity(TuyaEntity, ClimateEntity):
|
|||
if int_type := self.find_dpcode(
|
||||
DPCode.HUMIDITY_SET, dptype=DPType.INTEGER, prefer_function=True
|
||||
):
|
||||
self._attr_supported_features |= SUPPORT_TARGET_HUMIDITY
|
||||
self._attr_supported_features |= ClimateEntityFeature.TARGET_HUMIDITY
|
||||
self._set_humidity = int_type
|
||||
self._attr_min_humidity = int(int_type.min_scaled)
|
||||
self._attr_max_humidity = int(int_type.max_scaled)
|
||||
|
@ -243,7 +243,7 @@ class TuyaClimateEntity(TuyaEntity, ClimateEntity):
|
|||
dptype=DPType.ENUM,
|
||||
prefer_function=True,
|
||||
):
|
||||
self._attr_supported_features |= SUPPORT_FAN_MODE
|
||||
self._attr_supported_features |= ClimateEntityFeature.FAN_MODE
|
||||
self._attr_fan_modes = enum_type.range
|
||||
|
||||
# Determine swing modes
|
||||
|
@ -256,7 +256,7 @@ class TuyaClimateEntity(TuyaEntity, ClimateEntity):
|
|||
),
|
||||
prefer_function=True,
|
||||
):
|
||||
self._attr_supported_features |= SUPPORT_SWING_MODE
|
||||
self._attr_supported_features |= ClimateEntityFeature.SWING_MODE
|
||||
self._attr_swing_modes = [SWING_OFF]
|
||||
if self.find_dpcode((DPCode.SHAKE, DPCode.SWING), prefer_function=True):
|
||||
self._attr_swing_modes.append(SWING_ON)
|
||||
|
|
|
@ -9,14 +9,10 @@ from tuya_iot import TuyaDevice, TuyaDeviceManager
|
|||
from homeassistant.components.cover import (
|
||||
ATTR_POSITION,
|
||||
ATTR_TILT_POSITION,
|
||||
SUPPORT_CLOSE,
|
||||
SUPPORT_OPEN,
|
||||
SUPPORT_SET_POSITION,
|
||||
SUPPORT_SET_TILT_POSITION,
|
||||
SUPPORT_STOP,
|
||||
CoverDeviceClass,
|
||||
CoverEntity,
|
||||
CoverEntityDescription,
|
||||
CoverEntityFeature,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
|
@ -200,22 +196,24 @@ class TuyaCoverEntity(TuyaEntity, CoverEntity):
|
|||
# Check if this cover is based on a switch or has controls
|
||||
if self.find_dpcode(description.key, prefer_function=True):
|
||||
if device.function[description.key].type == "Boolean":
|
||||
self._attr_supported_features |= SUPPORT_OPEN | SUPPORT_CLOSE
|
||||
self._attr_supported_features |= (
|
||||
CoverEntityFeature.OPEN | CoverEntityFeature.CLOSE
|
||||
)
|
||||
elif enum_type := self.find_dpcode(
|
||||
description.key, dptype=DPType.ENUM, prefer_function=True
|
||||
):
|
||||
if description.open_instruction_value in enum_type.range:
|
||||
self._attr_supported_features |= SUPPORT_OPEN
|
||||
self._attr_supported_features |= CoverEntityFeature.OPEN
|
||||
if description.close_instruction_value in enum_type.range:
|
||||
self._attr_supported_features |= SUPPORT_CLOSE
|
||||
self._attr_supported_features |= CoverEntityFeature.CLOSE
|
||||
if description.stop_instruction_value in enum_type.range:
|
||||
self._attr_supported_features |= SUPPORT_STOP
|
||||
self._attr_supported_features |= CoverEntityFeature.STOP
|
||||
|
||||
# Determine type to use for setting the position
|
||||
if int_type := self.find_dpcode(
|
||||
description.set_position, dptype=DPType.INTEGER, prefer_function=True
|
||||
):
|
||||
self._attr_supported_features |= SUPPORT_SET_POSITION
|
||||
self._attr_supported_features |= CoverEntityFeature.SET_POSITION
|
||||
self._set_position = int_type
|
||||
# Set as default, unless overwritten below
|
||||
self._current_position = int_type
|
||||
|
@ -232,7 +230,7 @@ class TuyaCoverEntity(TuyaEntity, CoverEntity):
|
|||
dptype=DPType.INTEGER,
|
||||
prefer_function=True,
|
||||
):
|
||||
self._attr_supported_features |= SUPPORT_SET_TILT_POSITION
|
||||
self._attr_supported_features |= CoverEntityFeature.SET_TILT_POSITION
|
||||
self._tilt = int_type
|
||||
|
||||
@property
|
||||
|
|
|
@ -8,11 +8,8 @@ from tuya_iot import TuyaDevice, TuyaDeviceManager
|
|||
from homeassistant.components.fan import (
|
||||
DIRECTION_FORWARD,
|
||||
DIRECTION_REVERSE,
|
||||
SUPPORT_DIRECTION,
|
||||
SUPPORT_OSCILLATE,
|
||||
SUPPORT_PRESET_MODE,
|
||||
SUPPORT_SET_SPEED,
|
||||
FanEntity,
|
||||
FanEntityFeature,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
|
@ -85,7 +82,7 @@ class TuyaFanEntity(TuyaEntity, FanEntity):
|
|||
(DPCode.FAN_MODE, DPCode.MODE), dptype=DPType.ENUM, prefer_function=True
|
||||
):
|
||||
self._presets = enum_type
|
||||
self._attr_supported_features |= SUPPORT_PRESET_MODE
|
||||
self._attr_supported_features |= FanEntityFeature.PRESET_MODE
|
||||
self._attr_preset_modes = enum_type.range
|
||||
|
||||
# Find speed controls, can be either percentage or a set of speeds
|
||||
|
@ -98,25 +95,25 @@ class TuyaFanEntity(TuyaEntity, FanEntity):
|
|||
if int_type := self.find_dpcode(
|
||||
dpcodes, dptype=DPType.INTEGER, prefer_function=True
|
||||
):
|
||||
self._attr_supported_features |= SUPPORT_SET_SPEED
|
||||
self._attr_supported_features |= FanEntityFeature.SET_SPEED
|
||||
self._speed = int_type
|
||||
elif enum_type := self.find_dpcode(
|
||||
dpcodes, dptype=DPType.ENUM, prefer_function=True
|
||||
):
|
||||
self._attr_supported_features |= SUPPORT_SET_SPEED
|
||||
self._attr_supported_features |= FanEntityFeature.SET_SPEED
|
||||
self._speeds = enum_type
|
||||
|
||||
if dpcode := self.find_dpcode(
|
||||
(DPCode.SWITCH_HORIZONTAL, DPCode.SWITCH_VERTICAL), prefer_function=True
|
||||
):
|
||||
self._oscillate = dpcode
|
||||
self._attr_supported_features |= SUPPORT_OSCILLATE
|
||||
self._attr_supported_features |= FanEntityFeature.OSCILLATE
|
||||
|
||||
if enum_type := self.find_dpcode(
|
||||
DPCode.FAN_DIRECTION, dptype=DPType.ENUM, prefer_function=True
|
||||
):
|
||||
self._direction = enum_type
|
||||
self._attr_supported_features |= SUPPORT_DIRECTION
|
||||
self._attr_supported_features |= FanEntityFeature.DIRECTION
|
||||
|
||||
def set_preset_mode(self, preset_mode: str) -> None:
|
||||
"""Set the preset mode of the fan."""
|
||||
|
|
|
@ -6,10 +6,10 @@ from dataclasses import dataclass
|
|||
from tuya_iot import TuyaDevice, TuyaDeviceManager
|
||||
|
||||
from homeassistant.components.humidifier import (
|
||||
SUPPORT_MODES,
|
||||
HumidifierDeviceClass,
|
||||
HumidifierEntity,
|
||||
HumidifierEntityDescription,
|
||||
HumidifierEntityFeature,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
|
@ -112,7 +112,7 @@ class TuyaHumidifierEntity(TuyaEntity, HumidifierEntity):
|
|||
if enum_type := self.find_dpcode(
|
||||
DPCode.MODE, dptype=DPType.ENUM, prefer_function=True
|
||||
):
|
||||
self._attr_supported_features |= SUPPORT_MODES
|
||||
self._attr_supported_features |= HumidifierEntityFeature.MODES
|
||||
self._attr_available_modes = enum_type.range
|
||||
|
||||
@property
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue