Skip to content

Commit

Permalink
Set delay number for derog mode
Browse files Browse the repository at this point in the history
  • Loading branch information
cyr-ius committed Dec 3, 2024
1 parent 18384b0 commit 1016f21
Showing 1 changed file with 25 additions and 17 deletions.
42 changes: 25 additions & 17 deletions custom_components/heatzy/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@

from __future__ import annotations

import logging
from collections.abc import Callable
from dataclasses import dataclass
import logging
from typing import Any, Final

from heatzypy.exception import HeatzyException
import voluptuous as vol

from heatzypy.exception import HeatzyException
from homeassistant.components.climate import (
ATTR_TARGET_TEMP_HIGH,
ATTR_TARGET_TEMP_LOW,
Expand All @@ -26,7 +25,8 @@
)
from homeassistant.const import CONF_DELAY, UnitOfTemperature
from homeassistant.core import HomeAssistant
from homeassistant.helpers import config_validation as cv, entity_platform
from homeassistant.helpers import config_validation as cv
from homeassistant.helpers import entity_platform
from homeassistant.helpers.entity_platform import AddEntitiesCallback

from . import HeatzyConfigEntry, HeatzyDataUpdateCoordinator
Expand Down Expand Up @@ -449,9 +449,11 @@ async def async_turn_auto(self) -> None:
async def async_set_preset_mode(self, preset_mode: str) -> None:
"""Set new preset mode."""
if preset_mode == PRESET_BOOST:
return await self.async_boost_mode(60) # minutes
minutes = self.coordinator.data[self.did].get(f"boost_{self.did}", 60)
return await self.async_boost_mode(minutes)
if preset_mode == PRESET_VACATION:
return await self.async_vacation_mode(60) # days
days = self.coordinator.data[self.did].get(f"vacation_{self.did}", 30)
return await self.async_vacation_mode(days)

try:
await self.coordinator.api.async_control_device(
Expand Down Expand Up @@ -560,9 +562,11 @@ async def async_turn_auto(self) -> None:
async def async_set_preset_mode(self, preset_mode: str) -> None:
"""Set new preset mode."""
if preset_mode == PRESET_BOOST:
return await self.async_boost_mode(60) # minutes
minutes = self.coordinator.data[self.did].get(f"boost_{self.did}", 60)
return await self.async_boost_mode(minutes)
if preset_mode == PRESET_VACATION:
return await self.async_vacation_mode(60) # days
days = self.coordinator.data[self.did].get(f"vacation_{self.did}", 30)
return await self.async_vacation_mode(days)

config: dict[str, Any] = {
CONF_ATTRS: {
Expand Down Expand Up @@ -750,9 +754,11 @@ async def async_set_temperature(self, **kwargs: Any) -> None:
async def async_set_preset_mode(self, preset_mode: str) -> None:
"""Set new preset mode."""
if preset_mode == PRESET_BOOST:
return await self.async_boost_mode(60) # minutes
minutes = self.coordinator.data[self.did].get(f"boost_{self.did}", 60)
return await self.async_boost_mode(minutes)
if preset_mode == PRESET_VACATION:
return await self.async_vacation_mode(60) # days
days = self.coordinator.data[self.did].get(f"vacation_{self.did}", 30)
return await self.async_vacation_mode(days)

config = {
CONF_ATTRS: {
Expand Down Expand Up @@ -894,11 +900,13 @@ def hvac_action(self) -> HVACAction:
async def async_set_preset_mode(self, preset_mode: str) -> None:
"""Set new preset mode."""
if preset_mode == PRESET_BOOST:
return await self.async_boost_mode(60) # minutes
minutes = self.coordinator.data[self.did].get(f"boost_{self.did}", 60)
return await self.async_boost_mode(minutes)
if preset_mode == PRESET_VACATION:
return await self.async_vacation_mode(60) # days
days = self.coordinator.data[self.did].get(f"vacation_{self.did}", 30)
return await self.async_vacation_mode(days)
if preset_mode == PRESET_PRESENCE_DETECT:
return await self.async_presence_detection() # days
return await self.async_presence_detection()

config: dict[str, Any] = {
CONF_ATTRS: {
Expand All @@ -915,10 +923,6 @@ async def async_set_preset_mode(self, preset_mode: str) -> None:
except HeatzyException as error:
_LOGGER.error("Error to set preset mode: %s (%s)", preset_mode, error)

async def async_presence_detection(self) -> None:
"""Service Window Detection Mode."""
await self.async_derog_mode(3)

async def async_set_temperature(self, **kwargs: Any) -> None:
"""Set new target temperature."""
if (temp_eco := kwargs.get(ATTR_TARGET_TEMP_LOW)) and (
Expand All @@ -939,3 +943,7 @@ async def async_set_temperature(self, **kwargs: Any) -> None:
)
except HeatzyException as error:
_LOGGER.error("Error to set temperature (%s)", error)

async def async_presence_detection(self) -> None:
"""Presence detection derog."""
return await self.async_derog_mode(3)

0 comments on commit 1016f21

Please sign in to comment.