1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
"""Tests for retrieving information from the BSBLAN device."""
# pylint: disable=duplicate-code
# pylint: disable=protected-access
# file deepcode ignore W0212: this is a testfile
from __future__ import annotations
import json
from typing import Any
from unittest.mock import AsyncMock
import aiohttp
import pytest
from bsblan import BSBLAN, BSBLANConfig, State
from bsblan.constants import API_V3
from bsblan.utility import APIValidator
from . import load_fixture
@pytest.mark.asyncio
async def test_state(monkeypatch: Any) -> None:
"""Test getting BSBLAN state."""
async with aiohttp.ClientSession() as session:
config = BSBLANConfig(host="example.com")
bsblan = BSBLAN(config, session=session)
monkeypatch.setattr(bsblan, "_firmware_version", "1.0.38-20200730234859")
monkeypatch.setattr(bsblan, "_api_version", "v3")
monkeypatch.setattr(bsblan, "_api_data", API_V3)
api_validator = APIValidator(API_V3)
api_validator.validated_sections.add("state")
bsblan._api_validator = api_validator
request_mock: AsyncMock = AsyncMock(
return_value=json.loads(load_fixture("state.json")),
)
monkeypatch.setattr(bsblan, "_request", request_mock)
# Execute test
state: State = await bsblan.state()
# Basic type assertions
assert isinstance(state, State)
assert state is not None
# HVAC mode assertions
assert state.hvac_mode is not None
assert state.hvac_mode.value == "heat" # Converted from "3" to "heat"
assert state.hvac_mode.desc == "Comfort"
assert state.hvac_mode.unit == ""
# Target temperature assertions
assert state.target_temperature is not None
assert state.target_temperature.value == 18.0
assert state.target_temperature.desc == ""
assert state.target_temperature.unit == "°C"
# HVAC mode 2 assertions
assert state.hvac_mode2 is not None
assert state.hvac_mode2.value == 2
assert state.hvac_mode2.desc == "Reduced"
# HVAC action assertions
assert state.hvac_action is not None
assert state.hvac_action.value == 122
assert state.hvac_action.desc == "Room temperature limitation"
# Current temperature assertions
assert state.current_temperature is not None
assert state.current_temperature.value == 19.3
assert state.current_temperature.unit == "°C"
# Room thermostat mode assertions
assert state.room1_thermostat_mode is not None
assert state.room1_thermostat_mode.value == 0
assert state.room1_thermostat_mode.desc == "No demand"
# Room temperature setpoint boost assertions
assert state.room1_temp_setpoint_boost is not None
assert state.room1_temp_setpoint_boost.value == "---"
assert state.room1_temp_setpoint_boost.unit == "°C"
# Verify API call
request_mock.assert_called_once_with(
params={"Parameter": "700,710,900,8000,8740,8749,770"}
)
|