From f4854a126053ec7f77c22ba8c8620a1adcfed8d1 Mon Sep 17 00:00:00 2001 From: Willem-Jan van Rootselaar Date: Sat, 26 Feb 2022 12:06:17 +0100 Subject: [PATCH] revert remove hvac mode hvac is needed. converted preset to hvac. Makes it more complicated. --- src/bsblan/bsblan.py | 20 +++++++--------- src/bsblan/constants.py | 24 +++++++++---------- src/bsblan/models.py | 20 ++++++++++++---- ...ostat_preset.json => thermostat_hvac.json} | 0 tests/test_state.py | 4 ++-- tests/test_thermostat.py | 8 +++---- 6 files changed, 42 insertions(+), 34 deletions(-) rename tests/fixtures/{thermostat_preset.json => thermostat_hvac.json} (100%) diff --git a/src/bsblan/bsblan.py b/src/bsblan/bsblan.py index 51a7927f..0eee0370 100644 --- a/src/bsblan/bsblan.py +++ b/src/bsblan/bsblan.py @@ -21,8 +21,8 @@ DEVICE_INFO_API_V2, HEATING_CIRCUIT1_API_V1, HEATING_CIRCUIT1_API_V2, - PRESET_MODE_DICT, - PRESET_MODE_DICT_REVERSE, + HVAC_MODE_DICT, + HVAC_MODE_DICT_REVERSE, ) from .exceptions import BSBLANConnectionError, BSBLANError from .models import Device, Info, State @@ -190,9 +190,7 @@ async def state(self) -> State: logger.debug("get state") data = await self._request(params={"Parameter": f"{self._heatingcircuit1}"}) data = dict(zip(self._heating_params, list(data.values()))) - data["preset_mode"]["value"] = PRESET_MODE_DICT[ - int(data["preset_mode"]["value"]) - ] + data["hvac_mode"]["value"] = HVAC_MODE_DICT[int(data["hvac_mode"]["value"])] return State.parse_obj(data) async def _get_dict_version(self) -> dict: @@ -261,13 +259,13 @@ async def _get_parameters(self, params: dict) -> dict: async def thermostat( self, target_temperature: str | None = None, - preset_mode: str | None = None, + hvac_mode: str | None = None, ) -> None: """Change the state of the thermostat through BSB-Lan. Args: target_temperature: Target temperature to set. - preset_mode: Preset mode to set. + hvac_mode: Preset mode to set. Raises: BSBLANError: The provided values are invalid. @@ -279,7 +277,7 @@ class ThermostatState( # lgtm [py/unused-local-variable] """Describe state dictionary that can be set on the thermostat.""" target_temperature: str - preset_mode: str + hvac_mode: str Parameter: str Value: str Type: str @@ -296,11 +294,11 @@ class ThermostatState( # lgtm [py/unused-local-variable] state["Value"] = target_temperature state["Type"] = "1" - if preset_mode is not None: - if preset_mode not in PRESET_MODE_DICT_REVERSE: + if hvac_mode is not None: + if hvac_mode not in HVAC_MODE_DICT_REVERSE: raise BSBLANError("Preset mode is not valid") state["Parameter"] = "700" - state["EnumValue"] = PRESET_MODE_DICT_REVERSE[preset_mode] + state["EnumValue"] = HVAC_MODE_DICT_REVERSE[hvac_mode] state["Type"] = "1" if not state: diff --git a/src/bsblan/constants.py b/src/bsblan/constants.py index 342ab8cf..a3d35824 100644 --- a/src/bsblan/constants.py +++ b/src/bsblan/constants.py @@ -13,26 +13,26 @@ # dict of parameter needed for climate device. # need to update values and request less? HEATING_CIRCUIT1_API_V1 = { - "700": "preset_mode", + "700": "hvac_mode", "710": "target_temperature", "711": "target_temperature_high", "712": "target_temperature_low", "714": "min_temp", "730": "max_temp", - "900": "preset_mode2", + "900": "hvac_mode2", "8000": "hvac_action", "8700": "outside_temperature", "8740": "current_temperature", "8749": "room1_thermostat_mode", } HEATING_CIRCUIT1_API_V2 = { - "700": "preset_mode", + "700": "hvac_mode", "710": "target_temperature", "711": "target_temperature_high", "712": "target_temperature_low", "714": "min_temp", "730": "max_temp", - "900": "preset_mode2", + "900": "hvac_mode2", "8000": "hvac_action", "8700": "outside_temperature", "8740": "current_temperature room1", @@ -50,15 +50,15 @@ "8770", ] # homeassistant values -PRESET_MODE_DICT = { - 0: "protection_mode", +HVAC_MODE_DICT = { + 0: "off", 1: "auto", - 2: "reduced", - 3: "comfort", + 2: "eco", # presetmode? + 3: "heat", } -PRESET_MODE_DICT_REVERSE = { - "protection_mode": 0, +HVAC_MODE_DICT_REVERSE = { + "off": 0, "auto": 1, - "reduced": 2, - "comfort": 3, + "eco": 2, + "heat": 3, } diff --git a/src/bsblan/models.py b/src/bsblan/models.py index 6397eaa3..20e48504 100644 --- a/src/bsblan/models.py +++ b/src/bsblan/models.py @@ -1,5 +1,4 @@ """Models for BSB-Lan.""" - from pydantic import BaseModel, Field @@ -14,16 +13,28 @@ class EntityInfo(BaseModel): """ name: str = Field(..., alias="name") - value: str = Field(..., alias="value") unit: str = Field(..., alias="unit") desc: str = Field(..., alias="desc") + value: str = Field(..., alias="value") + dataType: int = Field(..., alias="dataType") + + # "DataType" ( + # 0 = plain value (number), + # 1 = ENUM (value (8/16 Bit) followed by space followed by text), + # 2 = bit value (bit value (decimal) followed by bitmask followed by text/chosen option), + # 3 = weekday, + # 4 = hour:minute, + # 5 = date and time, + # 6 = day and month, + # 7 = string, + # 8 = PPS time (day of week, hour:minute)) class State(BaseModel): """This object holds info about object for state climate.""" - preset_mode: EntityInfo - preset_mode2: EntityInfo + hvac_mode: EntityInfo + hvac_mode2: EntityInfo target_temperature: EntityInfo target_temperature_high: EntityInfo target_temperature_low: EntityInfo @@ -42,7 +53,6 @@ class Device(BaseModel): name: Name of the device. version: Firmware version of the device. MAC: MAC address of the device. - """ name: str = Field(..., alias="name") diff --git a/tests/fixtures/thermostat_preset.json b/tests/fixtures/thermostat_hvac.json similarity index 100% rename from tests/fixtures/thermostat_preset.json rename to tests/fixtures/thermostat_hvac.json diff --git a/tests/test_state.py b/tests/test_state.py index fd5392e9..44460605 100644 --- a/tests/test_state.py +++ b/tests/test_state.py @@ -41,6 +41,6 @@ async def test_state(aresponses, mocker, monkeypatch): # await bsblan._scan(params) state: State = await bsblan.state() assert state - assert state.preset_mode.name == "Operating mode" - assert state.preset_mode.value == "comfort" + assert state.hvac_mode.name == "Operating mode" + assert state.hvac_mode.value == "heat" assert state.current_temperature.value == "18.2" diff --git a/tests/test_thermostat.py b/tests/test_thermostat.py index 037d80bd..1de66ad3 100644 --- a/tests/test_thermostat.py +++ b/tests/test_thermostat.py @@ -30,8 +30,8 @@ async def response_handler(request): @pytest.mark.asyncio -async def test_change_preset_mode(aresponses): - """Test changing BSBLAN preset mode.""" +async def test_change_hvac_mode(aresponses): + """Test changing BSBLAN hvac mode.""" async def response_handler(request): data = await request.json() @@ -40,11 +40,11 @@ async def response_handler(request): return aresponses.Response( status=200, headers={"Content-Type": "application/json"}, - text=load_fixture("thermostat_preset.json"), + text=load_fixture("thermostat_hvac.json"), ) aresponses.add("example.com", "/JS", "POST", response_handler) async with aiohttp.ClientSession() as session: bsblan = BSBLAN("example.com", session=session) - await bsblan.thermostat(preset_mode="comfort") + await bsblan.thermostat(hvac_mode="heat")