Skip to content

Commit

Permalink
Merge pull request #351 from liudger/add-hvac_mode
Browse files Browse the repository at this point in the history
revert remove hvac mode
  • Loading branch information
liudger authored Feb 26, 2022
2 parents ba2610e + f4854a1 commit 6bd02e7
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 34 deletions.
20 changes: 9 additions & 11 deletions src/bsblan/bsblan.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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:
Expand Down
24 changes: 12 additions & 12 deletions src/bsblan/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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,
}
20 changes: 15 additions & 5 deletions src/bsblan/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Models for BSB-Lan."""

from pydantic import BaseModel, Field


Expand All @@ -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
Expand All @@ -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")
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions tests/test_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
8 changes: 4 additions & 4 deletions tests/test_thermostat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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")

0 comments on commit 6bd02e7

Please sign in to comment.