2019-02-14 15:42:03 +00:00
|
|
|
"""Demo platform that offers a fake water heater device."""
|
2022-01-03 15:24:09 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2019-03-24 03:22:35 +00:00
|
|
|
from homeassistant.components.water_heater import (
|
2020-05-01 14:29:14 +00:00
|
|
|
WaterHeaterEntity,
|
2022-04-03 03:55:17 +00:00
|
|
|
WaterHeaterEntityFeature,
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2022-01-03 15:24:09 +00:00
|
|
|
from homeassistant.config_entries import ConfigEntry
|
2019-12-08 16:59:27 +00:00
|
|
|
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS, TEMP_FAHRENHEIT
|
2022-01-03 15:24:09 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|
|
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
2018-10-08 08:38:07 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
SUPPORT_FLAGS_HEATER = (
|
2022-04-03 03:55:17 +00:00
|
|
|
WaterHeaterEntityFeature.TARGET_TEMPERATURE
|
|
|
|
| WaterHeaterEntityFeature.OPERATION_MODE
|
|
|
|
| WaterHeaterEntityFeature.AWAY_MODE
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2018-10-08 08:38:07 +00:00
|
|
|
|
|
|
|
|
2022-01-03 15:24:09 +00:00
|
|
|
async def async_setup_platform(
|
|
|
|
hass: HomeAssistant,
|
|
|
|
config: ConfigType,
|
|
|
|
async_add_entities: AddEntitiesCallback,
|
|
|
|
discovery_info: DiscoveryInfoType | None = None,
|
|
|
|
) -> None:
|
2018-10-08 08:38:07 +00:00
|
|
|
"""Set up the Demo water_heater devices."""
|
2019-11-13 15:37:31 +00:00
|
|
|
async_add_entities(
|
2019-07-31 19:25:30 +00:00
|
|
|
[
|
|
|
|
DemoWaterHeater("Demo Water Heater", 119, TEMP_FAHRENHEIT, False, "eco"),
|
|
|
|
DemoWaterHeater("Demo Water Heater Celsius", 45, TEMP_CELSIUS, True, "eco"),
|
|
|
|
]
|
|
|
|
)
|
2018-10-08 08:38:07 +00:00
|
|
|
|
|
|
|
|
2022-01-03 15:24:09 +00:00
|
|
|
async def async_setup_entry(
|
|
|
|
hass: HomeAssistant,
|
|
|
|
config_entry: ConfigEntry,
|
|
|
|
async_add_entities: AddEntitiesCallback,
|
|
|
|
) -> None:
|
2019-11-13 15:37:31 +00:00
|
|
|
"""Set up the Demo config entry."""
|
|
|
|
await async_setup_platform(hass, {}, async_add_entities)
|
|
|
|
|
|
|
|
|
2020-05-01 14:29:14 +00:00
|
|
|
class DemoWaterHeater(WaterHeaterEntity):
|
2018-10-08 08:38:07 +00:00
|
|
|
"""Representation of a demo water_heater device."""
|
|
|
|
|
2021-06-17 08:19:29 +00:00
|
|
|
_attr_should_poll = False
|
|
|
|
_attr_supported_features = SUPPORT_FLAGS_HEATER
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
def __init__(
|
|
|
|
self, name, target_temperature, unit_of_measurement, away, current_operation
|
|
|
|
):
|
2018-10-08 08:38:07 +00:00
|
|
|
"""Initialize the water_heater device."""
|
2021-06-17 08:19:29 +00:00
|
|
|
self._attr_name = name
|
2018-10-08 08:38:07 +00:00
|
|
|
if target_temperature is not None:
|
2021-06-17 08:19:29 +00:00
|
|
|
self._attr_supported_features = (
|
2022-04-03 03:55:17 +00:00
|
|
|
self.supported_features | WaterHeaterEntityFeature.TARGET_TEMPERATURE
|
2021-06-17 08:19:29 +00:00
|
|
|
)
|
2018-10-08 08:38:07 +00:00
|
|
|
if away is not None:
|
2022-04-03 03:55:17 +00:00
|
|
|
self._attr_supported_features = (
|
|
|
|
self.supported_features | WaterHeaterEntityFeature.AWAY_MODE
|
|
|
|
)
|
2018-10-08 08:38:07 +00:00
|
|
|
if current_operation is not None:
|
2021-06-17 08:19:29 +00:00
|
|
|
self._attr_supported_features = (
|
2022-04-03 03:55:17 +00:00
|
|
|
self.supported_features | WaterHeaterEntityFeature.OPERATION_MODE
|
2021-06-17 08:19:29 +00:00
|
|
|
)
|
|
|
|
self._attr_target_temperature = target_temperature
|
|
|
|
self._attr_temperature_unit = unit_of_measurement
|
|
|
|
self._attr_is_away_mode_on = away
|
|
|
|
self._attr_current_operation = current_operation
|
|
|
|
self._attr_operation_list = [
|
2019-07-31 19:25:30 +00:00
|
|
|
"eco",
|
|
|
|
"electric",
|
|
|
|
"performance",
|
|
|
|
"high_demand",
|
|
|
|
"heat_pump",
|
|
|
|
"gas",
|
|
|
|
"off",
|
|
|
|
]
|
2018-10-08 08:38:07 +00:00
|
|
|
|
|
|
|
def set_temperature(self, **kwargs):
|
|
|
|
"""Set new target temperatures."""
|
2021-06-17 08:19:29 +00:00
|
|
|
self._attr_target_temperature = kwargs.get(ATTR_TEMPERATURE)
|
2018-10-08 08:38:07 +00:00
|
|
|
self.schedule_update_ha_state()
|
|
|
|
|
|
|
|
def set_operation_mode(self, operation_mode):
|
|
|
|
"""Set new operation mode."""
|
2021-06-17 08:19:29 +00:00
|
|
|
self._attr_current_operation = operation_mode
|
2018-10-08 08:38:07 +00:00
|
|
|
self.schedule_update_ha_state()
|
|
|
|
|
|
|
|
def turn_away_mode_on(self):
|
|
|
|
"""Turn away mode on."""
|
2021-06-17 08:19:29 +00:00
|
|
|
self._attr_is_away_mode_on = True
|
2018-10-08 08:38:07 +00:00
|
|
|
self.schedule_update_ha_state()
|
|
|
|
|
|
|
|
def turn_away_mode_off(self):
|
|
|
|
"""Turn away mode off."""
|
2021-06-17 08:19:29 +00:00
|
|
|
self._attr_is_away_mode_on = False
|
2018-10-08 08:38:07 +00:00
|
|
|
self.schedule_update_ha_state()
|