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
|
|
|
|
|
2022-08-19 14:10:45 +00:00
|
|
|
from typing import Any
|
|
|
|
|
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
|
2022-12-04 09:21:44 +00:00
|
|
|
from homeassistant.const import ATTR_TEMPERATURE, UnitOfTemperature
|
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
|
|
|
[
|
2022-12-04 09:21:44 +00:00
|
|
|
DemoWaterHeater(
|
|
|
|
"Demo Water Heater", 119, UnitOfTemperature.FAHRENHEIT, False, "eco"
|
|
|
|
),
|
|
|
|
DemoWaterHeater(
|
|
|
|
"Demo Water Heater Celsius", 45, UnitOfTemperature.CELSIUS, True, "eco"
|
|
|
|
),
|
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_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__(
|
2022-08-26 09:34:38 +00:00
|
|
|
self,
|
|
|
|
name: str,
|
|
|
|
target_temperature: int,
|
|
|
|
unit_of_measurement: str,
|
|
|
|
away: bool,
|
|
|
|
current_operation: str,
|
|
|
|
) -> None:
|
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:
|
2022-11-17 08:39:46 +00:00
|
|
|
self._attr_supported_features |= WaterHeaterEntityFeature.TARGET_TEMPERATURE
|
2018-10-08 08:38:07 +00:00
|
|
|
if away is not None:
|
2022-11-17 08:39:46 +00:00
|
|
|
self._attr_supported_features |= WaterHeaterEntityFeature.AWAY_MODE
|
2018-10-08 08:38:07 +00:00
|
|
|
if current_operation is not None:
|
2022-11-17 08:39:46 +00:00
|
|
|
self._attr_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
|
|
|
|
2022-08-19 14:10:45 +00:00
|
|
|
def set_temperature(self, **kwargs: Any) -> None:
|
2018-10-08 08:38:07 +00:00
|
|
|
"""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()
|
|
|
|
|
2022-08-19 14:10:45 +00:00
|
|
|
def set_operation_mode(self, operation_mode: str) -> None:
|
2018-10-08 08:38:07 +00:00
|
|
|
"""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()
|
|
|
|
|
2022-08-19 14:10:45 +00:00
|
|
|
def turn_away_mode_on(self) -> None:
|
2018-10-08 08:38:07 +00:00
|
|
|
"""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()
|
|
|
|
|
2022-08-19 14:10:45 +00:00
|
|
|
def turn_away_mode_off(self) -> None:
|
2018-10-08 08:38:07 +00:00
|
|
|
"""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()
|