async def set_room_target_temperature(self, entity, target_temp): """Set target temperature for a room. * If there is a quick mode that impact room running on or holiday mode, remove it. * If the room is in MANUAL mode, simply modify the target temperature. * if the room is not in MANUAL mode, create à quick veto. """ touch_system = await self._remove_quick_mode_or_holiday(entity) room = entity.component current_mode = self.system.get_active_mode_room(room).current if current_mode == OperatingModes.MANUAL: await self._manager.set_room_setpoint_temperature(room.id, target_temp) room.target_temperature = target_temp else: if current_mode == OperatingModes.QUICK_VETO: await self._manager.remove_room_quick_veto(room.id) qveto = QuickVeto(DEFAULT_QUICK_VETO_DURATION, target_temp) await self._manager.set_room_quick_veto(room.id, qveto) room.quick_veto = qveto self.system.set_room(room.id, room) await self._refresh(touch_system, entity)
async def set_zone_target_temperature(self, entity, target_temp): """Set target temperature for a zone. * If there is a quick mode related to zone running or holiday mode, remove it. * If quick veto running on, remove it and create a new one with the new target temp * If any other mode, create a quick veto """ touch_system = await self._remove_quick_mode_or_holiday(entity) zone = entity.component current_mode = self.system.get_active_mode_zone(zone).current if current_mode == OperatingModes.QUICK_VETO: await self._manager.remove_zone_quick_veto(zone.id) veto = QuickVeto(None, target_temp) await self._manager.set_zone_quick_veto(zone.id, veto) zone.quick_veto = veto self.system.set_zone(zone.id, zone) await self._refresh(touch_system, entity)
async def test_set_quick_veto_zone(manager: SystemManager, resp: aioresponses) -> None: url = urls.zone_quick_veto(id="Zone1", serial=SERIAL) quick_veto = QuickVeto(duration=100, target=25) resp.put(url, status=200) await manager.set_zone_quick_veto("Zone1", quick_veto) _assert_calls(1, manager, [url])
async def test_set_quick_veto_room(manager: SystemManager, resp: aioresponses) -> None: url = urls.room_quick_veto(serial=SERIAL, id="1") quick_veto = QuickVeto(100, 25) resp.put(url, status=200) await manager.set_room_quick_veto("1", quick_veto) _assert_calls(1, manager, [url])
async def test_quick_veto_temperature_zone_rounded(manager: SystemManager, resp: aioresponses) -> None: url = urls.zone_quick_veto(id="zone1", serial=SERIAL) payload = payloads.zone_quick_veto(22.5) resp.put(url, status=200) qveto = QuickVeto(duration=35, target=22.7) await manager.set_zone_quick_veto("zone1", qveto) _assert_calls(1, manager, [url], [payload])
async def test_quick_veto_temperature_room_rounded(manager: SystemManager, resp: aioresponses) -> None: url = urls.room_quick_veto(id="0", serial=SERIAL) payload = payloads.room_quick_veto(22.5, 180) resp.put(url, status=200) qveto = QuickVeto(180, 22.7) await manager.set_room_quick_veto("0", qveto) _assert_calls(1, manager, [url], [payload])
def test_get_active_mode_room_quick_veto(self) -> None: """Test mode room with quick veto.""" room = _room() quick_veto = QuickVeto(duration=0, target=22) room.quick_veto = quick_veto system = System(rooms=[room]) active_mode = system.get_active_mode_room(room) self.assertEqual(OperatingModes.QUICK_VETO, active_mode.current) self.assertEqual(quick_veto.target, active_mode.target)
def test_get_active_mode_zone_quick_mode_quick_veto(self) -> None: """Test get active mode for zone quick mode + quick veto.""" quick_veto = QuickVeto(target=15) zone = _zone() zone.quick_veto = quick_veto system = System(zones=[zone]) active_mode = system.get_active_mode_zone(zone) self.assertEqual(OperatingModes.QUICK_VETO, active_mode.current) self.assertEqual(zone.quick_veto.target, active_mode.target)
async def set_quick_veto(self, entity, temperature, duration=None): """Set quick veto for the given entity.""" comp = self.find_component(entity.component) q_duration = duration if duration else DEFAULT_QUICK_VETO_DURATION qveto = QuickVeto(q_duration, temperature) if isinstance(comp, Zone): if comp.quick_veto: await self._manager.remove_zone_quick_veto(comp.id) await self._manager.set_zone_quick_veto(comp.id, qveto) else: if comp.quick_veto: await self._manager.remove_room_quick_veto(comp.id) await self._manager.set_room_quick_veto(comp.id, qveto) comp.quick_veto = qveto await self._refresh(False, entity)
def test_quick_veto(self) -> None: """Test correct quick veto.""" quickveto = QuickVeto(duration=600, target=15) self.assertEqual(600, quickveto.duration) self.assertEqual(15, quickveto.target)