mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 16:57:10 +00:00
Add EntityFeature enum to Water Heater (#69123)
This commit is contained in:
parent
e06856f965
commit
cce19dc480
@ -2,10 +2,8 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from homeassistant.components.water_heater import (
|
from homeassistant.components.water_heater import (
|
||||||
SUPPORT_AWAY_MODE,
|
|
||||||
SUPPORT_OPERATION_MODE,
|
|
||||||
SUPPORT_TARGET_TEMPERATURE,
|
|
||||||
WaterHeaterEntity,
|
WaterHeaterEntity,
|
||||||
|
WaterHeaterEntityFeature,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS, TEMP_FAHRENHEIT
|
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS, TEMP_FAHRENHEIT
|
||||||
@ -14,7 +12,9 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|||||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||||
|
|
||||||
SUPPORT_FLAGS_HEATER = (
|
SUPPORT_FLAGS_HEATER = (
|
||||||
SUPPORT_TARGET_TEMPERATURE | SUPPORT_OPERATION_MODE | SUPPORT_AWAY_MODE
|
WaterHeaterEntityFeature.TARGET_TEMPERATURE
|
||||||
|
| WaterHeaterEntityFeature.OPERATION_MODE
|
||||||
|
| WaterHeaterEntityFeature.AWAY_MODE
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -55,13 +55,15 @@ class DemoWaterHeater(WaterHeaterEntity):
|
|||||||
self._attr_name = name
|
self._attr_name = name
|
||||||
if target_temperature is not None:
|
if target_temperature is not None:
|
||||||
self._attr_supported_features = (
|
self._attr_supported_features = (
|
||||||
self.supported_features | SUPPORT_TARGET_TEMPERATURE
|
self.supported_features | WaterHeaterEntityFeature.TARGET_TEMPERATURE
|
||||||
)
|
)
|
||||||
if away is not None:
|
if away is not None:
|
||||||
self._attr_supported_features = self.supported_features | SUPPORT_AWAY_MODE
|
self._attr_supported_features = (
|
||||||
|
self.supported_features | WaterHeaterEntityFeature.AWAY_MODE
|
||||||
|
)
|
||||||
if current_operation is not None:
|
if current_operation is not None:
|
||||||
self._attr_supported_features = (
|
self._attr_supported_features = (
|
||||||
self.supported_features | SUPPORT_OPERATION_MODE
|
self.supported_features | WaterHeaterEntityFeature.OPERATION_MODE
|
||||||
)
|
)
|
||||||
self._attr_target_temperature = target_temperature
|
self._attr_target_temperature = target_temperature
|
||||||
self._attr_temperature_unit = unit_of_measurement
|
self._attr_temperature_unit = unit_of_measurement
|
||||||
|
@ -3,6 +3,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
from enum import IntEnum
|
||||||
import functools as ft
|
import functools as ft
|
||||||
import logging
|
import logging
|
||||||
from typing import final
|
from typing import final
|
||||||
@ -55,6 +56,17 @@ STATE_HIGH_DEMAND = "high_demand"
|
|||||||
STATE_HEAT_PUMP = "heat_pump"
|
STATE_HEAT_PUMP = "heat_pump"
|
||||||
STATE_GAS = "gas"
|
STATE_GAS = "gas"
|
||||||
|
|
||||||
|
|
||||||
|
class WaterHeaterEntityFeature(IntEnum):
|
||||||
|
"""Supported features of the fan entity."""
|
||||||
|
|
||||||
|
TARGET_TEMPERATURE = 1
|
||||||
|
OPERATION_MODE = 2
|
||||||
|
AWAY_MODE = 4
|
||||||
|
|
||||||
|
|
||||||
|
# These SUPPORT_* constants are deprecated as of Home Assistant 2022.5.
|
||||||
|
# Please use the WaterHeaterEntityFeature enum instead.
|
||||||
SUPPORT_TARGET_TEMPERATURE = 1
|
SUPPORT_TARGET_TEMPERATURE = 1
|
||||||
SUPPORT_OPERATION_MODE = 2
|
SUPPORT_OPERATION_MODE = 2
|
||||||
SUPPORT_AWAY_MODE = 4
|
SUPPORT_AWAY_MODE = 4
|
||||||
@ -189,7 +201,7 @@ class WaterHeaterEntity(Entity):
|
|||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
if supported_features & SUPPORT_OPERATION_MODE:
|
if supported_features & WaterHeaterEntityFeature.OPERATION_MODE:
|
||||||
data[ATTR_OPERATION_LIST] = self.operation_list
|
data[ATTR_OPERATION_LIST] = self.operation_list
|
||||||
|
|
||||||
return data
|
return data
|
||||||
@ -227,10 +239,10 @@ class WaterHeaterEntity(Entity):
|
|||||||
|
|
||||||
supported_features = self.supported_features
|
supported_features = self.supported_features
|
||||||
|
|
||||||
if supported_features & SUPPORT_OPERATION_MODE:
|
if supported_features & WaterHeaterEntityFeature.OPERATION_MODE:
|
||||||
data[ATTR_OPERATION_MODE] = self.current_operation
|
data[ATTR_OPERATION_MODE] = self.current_operation
|
||||||
|
|
||||||
if supported_features & SUPPORT_AWAY_MODE:
|
if supported_features & WaterHeaterEntityFeature.AWAY_MODE:
|
||||||
is_away = self.is_away_mode_on
|
is_away = self.is_away_mode_on
|
||||||
data[ATTR_AWAY_MODE] = STATE_ON if is_away else STATE_OFF
|
data[ATTR_AWAY_MODE] = STATE_ON if is_away else STATE_OFF
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user