Skip to content

Commit

Permalink
Fixed reference to zone from AmbisenseClimate, added preset for quick…
Browse files Browse the repository at this point in the history
… veto, updated library in manifest and dev requirements
  • Loading branch information
signalkraft committed Mar 19, 2024
1 parent e97787b commit 0a35cf7
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 17 deletions.
40 changes: 27 additions & 13 deletions custom_components/mypyllant/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@
AmbisenseRoomOperationMode.MANUAL: HVACMode.HEAT_COOL,
}

AMBISENSE_ROOM_PRESETS = [PRESET_NONE, PRESET_BOOST]


async def async_setup_entry(
hass: HomeAssistant, config: ConfigEntry, async_add_entities: AddEntitiesCallback
Expand Down Expand Up @@ -542,10 +544,10 @@ def hvac_action(self) -> HVACAction | None:
circuit_state = self.zone.get_associated_circuit(self.system).circuit_state
return ZONE_HVAC_ACTION_MAP.get(circuit_state)

async def turn_on(self) -> None:
async def async_turn_on(self) -> None:
await self.async_set_hvac_mode(self.data["last_active_hvac_mode"])

async def turn_off(self) -> None:
async def async_turn_off(self) -> None:
await self.async_set_hvac_mode(HVACMode.OFF)

async def async_set_temperature(self, **kwargs: Any) -> None:
Expand Down Expand Up @@ -667,10 +669,14 @@ async def async_set_preset_mode(self, preset_mode):


class AmbisenseClimate(CoordinatorEntity, ClimateEntity):
"""Climate for a ambisense room."""
"""Climate for an ambisense room."""

coordinator: SystemCoordinator
_attr_temperature_unit = UnitOfTemperature.CELSIUS
_attr_hvac_modes = list(
set([v for v in AMBISENSE_ROOM_OPERATION_MODE_MAP.values()])
)
_attr_preset_modes = AMBISENSE_ROOM_PRESETS
_enable_turn_on_off_backwards_compatibility = False

def __init__(
Expand Down Expand Up @@ -703,10 +709,6 @@ async def async_update(self) -> None:
_LOGGER.debug("Saving last active HVAC mode %s", self.hvac_mode)
self.data["last_active_hvac_mode"] = self.hvac_mode

@property
def hvac_modes(self) -> list[HVACMode]:
return list(set([v for v in AMBISENSE_ROOM_OPERATION_MODE_MAP.values()]))

@property
def default_quick_veto_duration(self):
return self.config.options.get(
Expand Down Expand Up @@ -763,7 +765,7 @@ async def set_quick_veto(self, **kwargs):
await self.coordinator.async_request_refresh_delayed()

async def remove_quick_veto(self):
_LOGGER.debug("Removing quick veto on %s", self.zone.name)
_LOGGER.debug("Removing quick veto on %s", self.room.name)
await self.coordinator.api.cancel_quick_veto_ambisense_room(self.room)
await self.coordinator.async_request_refresh_delayed()

Expand Down Expand Up @@ -802,10 +804,24 @@ async def async_set_hvac_mode(self, hvac_mode: HVACMode):
await self.coordinator.api.set_ambisense_room_operation_mode(self.room, mode)
await self.coordinator.async_request_refresh_delayed()

async def turn_on(self) -> None:
@property
def preset_mode(self) -> str | None:
if self.room.room_configuration.quick_veto_end_time is not None:
return PRESET_BOOST
else:
return PRESET_NONE

async def async_set_preset_mode(self, preset_mode: str) -> None:
if preset_mode == PRESET_NONE:
await self.remove_quick_veto()
# Both preset none and boost exist, but going from none to boost makes no sense without a specific
# target temperature
self._valid_mode_or_raise("preset", preset_mode, [PRESET_NONE])

async def async_turn_on(self) -> None:
await self.async_set_hvac_mode(self.data["last_active_hvac_mode"])

async def turn_off(self) -> None:
async def async_turn_off(self) -> None:
await self.async_set_hvac_mode(HVACMode.OFF)

async def async_set_temperature(self, **kwargs: Any) -> None:
Expand All @@ -814,12 +830,10 @@ async def async_set_temperature(self, **kwargs: Any) -> None:
or it creates a quick veto
"""
_LOGGER.debug(
"Setting temperature on %s with params %s", self.zone.name, kwargs
"Setting temperature on %s with params %s", self.room.name, kwargs
)
temperature = kwargs.get(ATTR_TEMPERATURE)
if not temperature:
return

_LOGGER.debug("Setting quick veto on %s to %s", self.zone.name, temperature)
await self.set_quick_veto(temperature=temperature)
await self.coordinator.async_request_refresh_delayed()
1 change: 1 addition & 0 deletions custom_components/mypyllant/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
API_DOWN_PAUSE_INTERVAL = 15 * 60 # in seconds

SERVICE_SET_QUICK_VETO = "set_quick_veto"
SERVICE_SET_QUICK_VETO_AMBISENSE = "set_quick_veto_ambisense"
SERVICE_SET_MANUAL_MODE_SETPOINT = "set_manual_mode_setpoint"
SERVICE_CANCEL_QUICK_VETO = "cancel_quick_veto"
SERVICE_SET_HOLIDAY = "set_holiday"
Expand Down
2 changes: 1 addition & 1 deletion custom_components/mypyllant/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"iot_class": "cloud_polling",
"issue_tracker": "https://github.com/signalkraft/mypyllant-component/issues",
"requirements": [
"myPyllant==0.7.26"
"myPyllant==0.8.0"
],
"version": "v0.7.3"
}
2 changes: 1 addition & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ types-PyYAML~=6.0.12.12

# Need specific versions
pytest-homeassistant-custom-component==0.13.101
myPyllant==0.7.26
myPyllant==0.8.0

# Versions handled by pytest-homeassistant-custom-component
freezegun
Expand Down
11 changes: 9 additions & 2 deletions tests/test_climate.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from unittest import mock

import pytest as pytest
from homeassistant.components.climate import HVACMode
from homeassistant.components.climate.const import FAN_OFF, PRESET_ECO
from homeassistant.components.climate import HVACMode, PRESET_NONE
from homeassistant.components.climate.const import FAN_OFF, PRESET_ECO, PRESET_BOOST
from homeassistant.const import ATTR_TEMPERATURE
from homeassistant.exceptions import ServiceValidationError
from homeassistant.helpers.entity_registry import DATA_REGISTRY, EntityRegistry
from homeassistant.loader import DATA_COMPONENTS, DATA_INTEGRATIONS

Expand Down Expand Up @@ -153,6 +154,12 @@ async def test_ambisense_climate(
assert isinstance(ambisense.current_temperature, float)
assert isinstance(ambisense.target_temperature, float)

await ambisense.async_turn_on()
await ambisense.async_turn_off()
await ambisense.async_set_temperature(temperature=20.0)
await ambisense.async_set_hvac_mode(HVACMode.OFF)
await ambisense.async_set_preset_mode(PRESET_NONE)
with pytest.raises(ServiceValidationError):
await ambisense.async_set_preset_mode(PRESET_BOOST)
system_coordinator_mock._debounced_refresh.async_cancel()
await mocked_api.aiohttp_session.close()

0 comments on commit 0a35cf7

Please sign in to comment.