|
| 1 | +"""Tests for the climate entity.""" |
| 2 | + |
| 3 | +from __future__ import annotations |
| 4 | + |
| 5 | +import sys |
| 6 | +from pathlib import Path |
| 7 | +from typing import Any |
| 8 | + |
| 9 | +import pytest |
| 10 | +from homeassistant.components.climate import HVACAction, HVACMode |
| 11 | + |
| 12 | +sys.path.insert(0, str(Path(__file__).resolve().parents[1])) |
| 13 | + |
| 14 | +from custom_components.truma_aventa.climate import TrumaClimate |
| 15 | +from custom_components.truma_aventa.truma_ble.const import ( |
| 16 | + MODE_COOLING, |
| 17 | + MODE_OFF, |
| 18 | + MODE_VENTILATING, |
| 19 | +) |
| 20 | +from custom_components.truma_aventa.truma_ble.models import TrumaState |
| 21 | + |
| 22 | + |
| 23 | +class _Device: |
| 24 | + address = "FC:DE:C5:F0:A6:35" |
| 25 | + name = "Truma iNetX-F0A635" |
| 26 | + |
| 27 | + |
| 28 | +class _Coordinator: |
| 29 | + """The little of a coordinator an entity touches before it is added.""" |
| 30 | + |
| 31 | + def __init__(self, state: TrumaState) -> None: |
| 32 | + self.data = state |
| 33 | + self.device = _Device() |
| 34 | + self.key = "Truma iNetX-F0A635" |
| 35 | + self.available = True |
| 36 | + self.last_update_success = True |
| 37 | + |
| 38 | + def async_add_listener(self, *_: Any) -> Any: |
| 39 | + return lambda: None |
| 40 | + |
| 41 | + |
| 42 | +def _climate(**state: Any) -> TrumaClimate: |
| 43 | + """A climate entity over the given state.""" |
| 44 | + return TrumaClimate(_Coordinator(TrumaState(**state))) |
| 45 | + |
| 46 | + |
| 47 | +def test_nothing_known_yet_reports_nothing() -> None: |
| 48 | + """Before the appliance has answered there is no action to report.""" |
| 49 | + assert _climate().hvac_action is None |
| 50 | + |
| 51 | + |
| 52 | +def test_switched_off_is_off() -> None: |
| 53 | + """Off is a state of its own, not idleness.""" |
| 54 | + assert _climate(mode=MODE_OFF).hvac_action is HVACAction.OFF |
| 55 | + |
| 56 | + |
| 57 | +def test_cooling_while_the_compressor_runs() -> None: |
| 58 | + """The mode says what was asked for; Active says what is happening.""" |
| 59 | + entity = _climate(mode=MODE_COOLING, cooling_active=1) |
| 60 | + assert entity.hvac_mode is HVACMode.COOL |
| 61 | + assert entity.hvac_action is HVACAction.COOLING |
| 62 | + |
| 63 | + |
| 64 | +def test_at_temperature_the_appliance_is_idle() -> None: |
| 65 | + """Cooling requested, compressor off: the target has been reached.""" |
| 66 | + entity = _climate(mode=MODE_COOLING, cooling_active=0) |
| 67 | + assert entity.hvac_mode is HVACMode.COOL |
| 68 | + assert entity.hvac_action is HVACAction.IDLE |
| 69 | + |
| 70 | + |
| 71 | +@pytest.mark.parametrize( |
| 72 | + ("running", "expected"), |
| 73 | + [ |
| 74 | + ("heating_active", HVACAction.HEATING), |
| 75 | + ("dehumid_active", HVACAction.DRYING), |
| 76 | + ("circulation_active", HVACAction.FAN), |
| 77 | + ], |
| 78 | +) |
| 79 | +def test_each_function_reports_its_own_action(running: str, expected: Any) -> None: |
| 80 | + """Every function says separately whether it is running.""" |
| 81 | + assert _climate(mode=MODE_VENTILATING, **{running: 1}).hvac_action is expected |
| 82 | + |
| 83 | + |
| 84 | +def test_temperatures_come_from_tenths() -> None: |
| 85 | + """The appliance counts in tenths of a degree.""" |
| 86 | + entity = _climate(current_temperature=251, target_temperature=220) |
| 87 | + assert entity.current_temperature == 25.1 |
| 88 | + assert entity.target_temperature == 22.0 |
0 commit comments