Initial commit
This commit is contained in:
+77
@@ -0,0 +1,77 @@
|
||||
"""
|
||||
Place this code in custom_components/heat_pump_monitor/climate.py
|
||||
"""
|
||||
import logging
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
from homeassistant.components.climate import (
|
||||
ClimateEntity,
|
||||
ClimateEntityFeature,
|
||||
HVACMode,
|
||||
HVACAction,
|
||||
)
|
||||
from homeassistant.const import (
|
||||
ATTR_TEMPERATURE,
|
||||
UnitOfTemperature,
|
||||
)
|
||||
|
||||
from . import DOMAIN
|
||||
from .__init__ import HeatPumpEntity
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
HVAC_MODES = [HVACMode.HEAT]
|
||||
|
||||
async def async_setup_entry(hass, entry, async_add_entities):
|
||||
"""Set up the heat pump climate."""
|
||||
coordinator = hass.data[DOMAIN][entry.entry_id]
|
||||
async_add_entities([HeatPumpClimate(coordinator)])
|
||||
|
||||
class HeatPumpClimate(HeatPumpEntity, ClimateEntity):
|
||||
"""Heat pump climate entity."""
|
||||
|
||||
def __init__(self, coordinator):
|
||||
"""Initialize the heat pump climate entity."""
|
||||
super().__init__(coordinator)
|
||||
self._attr_name = "Heat Pump Water Temperature"
|
||||
self._attr_unique_id = f"{DOMAIN}_climate"
|
||||
self._attr_temperature_unit = UnitOfTemperature.CELSIUS
|
||||
self._attr_hvac_modes = HVAC_MODES
|
||||
self._attr_hvac_mode = HVACMode.HEAT
|
||||
self._attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE
|
||||
self._attr_min_temp = 35
|
||||
self._attr_max_temp = 60
|
||||
self._attr_target_temperature_step = 0.5
|
||||
|
||||
@property
|
||||
def current_temperature(self) -> Optional[float]:
|
||||
"""Return the current temperature."""
|
||||
return self.coordinator.data.get("current_temperature")
|
||||
|
||||
@property
|
||||
def target_temperature(self) -> Optional[float]:
|
||||
"""Return the target temperature."""
|
||||
return self.coordinator.data.get("watersetpoint")
|
||||
|
||||
@property
|
||||
def hvac_action(self) -> Optional[str]:
|
||||
"""Return the current HVAC action."""
|
||||
if self.coordinator.data.get("is_heating"):
|
||||
return HVACAction.HEATING
|
||||
if self.coordinator.data.get("is_operating"):
|
||||
return HVACAction.IDLE
|
||||
return HVACAction.OFF
|
||||
|
||||
async def async_set_temperature(self, **kwargs) -> None:
|
||||
"""Set new target temperature."""
|
||||
if ATTR_TEMPERATURE not in kwargs:
|
||||
return
|
||||
|
||||
temperature = kwargs[ATTR_TEMPERATURE]
|
||||
await self.coordinator.set_water_setpoint(temperature)
|
||||
self.async_write_ha_state()
|
||||
|
||||
async def async_set_hvac_mode(self, hvac_mode: str) -> None:
|
||||
"""Set HVAC mode."""
|
||||
# This integration only supports HEAT mode, so we don't need to implement any changes
|
||||
pass
|
||||
Reference in New Issue
Block a user