Skip to content

Commit 180053f

Browse files
authored
Bump python-bsblan to v3.1.3 (home-assistant#157626)
1 parent 280c25c commit 180053f

File tree

9 files changed

+135
-110
lines changed

9 files changed

+135
-110
lines changed

homeassistant/components/bsblan/climate.py

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from __future__ import annotations
44

5-
from typing import Any
5+
from typing import Any, Final
66

77
from bsblan import BSBLANError
88

@@ -17,7 +17,7 @@
1717
)
1818
from homeassistant.const import ATTR_TEMPERATURE
1919
from homeassistant.core import HomeAssistant
20-
from homeassistant.exceptions import HomeAssistantError, ServiceValidationError
20+
from homeassistant.exceptions import HomeAssistantError
2121
from homeassistant.helpers.device_registry import format_mac
2222
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
2323
from homeassistant.util.enum import try_parse_enum
@@ -39,6 +39,22 @@
3939
PRESET_NONE,
4040
]
4141

42+
# Mapping from Home Assistant HVACMode to BSB-Lan integer values
43+
# BSB-Lan uses: 0=off, 1=auto, 2=eco/reduced, 3=heat/comfort
44+
HA_TO_BSBLAN_HVAC_MODE: Final[dict[HVACMode, int]] = {
45+
HVACMode.OFF: 0,
46+
HVACMode.AUTO: 1,
47+
HVACMode.HEAT: 3,
48+
}
49+
50+
# Mapping from BSB-Lan integer values to Home Assistant HVACMode
51+
BSBLAN_TO_HA_HVAC_MODE: Final[dict[int, HVACMode]] = {
52+
0: HVACMode.OFF,
53+
1: HVACMode.AUTO,
54+
2: HVACMode.AUTO, # eco/reduced maps to AUTO with preset
55+
3: HVACMode.HEAT,
56+
}
57+
4258

4359
async def async_setup_entry(
4460
hass: HomeAssistant,
@@ -98,17 +114,20 @@ def target_temperature(self) -> float | None:
98114
@property
99115
def hvac_mode(self) -> HVACMode | None:
100116
"""Return hvac operation ie. heat, cool mode."""
101-
if self.coordinator.data.state.hvac_mode.value == PRESET_ECO:
102-
return HVACMode.AUTO
103-
return try_parse_enum(HVACMode, self.coordinator.data.state.hvac_mode.value)
117+
hvac_mode_value = self.coordinator.data.state.hvac_mode.value
118+
if hvac_mode_value is None:
119+
return None
120+
# BSB-Lan returns integer values: 0=off, 1=auto, 2=eco, 3=heat
121+
if isinstance(hvac_mode_value, int):
122+
return BSBLAN_TO_HA_HVAC_MODE.get(hvac_mode_value)
123+
return try_parse_enum(HVACMode, hvac_mode_value)
104124

105125
@property
106126
def preset_mode(self) -> str | None:
107127
"""Return the current preset mode."""
108-
if (
109-
self.hvac_mode == HVACMode.AUTO
110-
and self.coordinator.data.state.hvac_mode.value == PRESET_ECO
111-
):
128+
hvac_mode_value = self.coordinator.data.state.hvac_mode.value
129+
# BSB-Lan mode 2 is eco/reduced mode
130+
if hvac_mode_value == 2:
112131
return PRESET_ECO
113132
return PRESET_NONE
114133

@@ -118,13 +137,6 @@ async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
118137

119138
async def async_set_preset_mode(self, preset_mode: str) -> None:
120139
"""Set preset mode."""
121-
if self.hvac_mode != HVACMode.AUTO and preset_mode != PRESET_NONE:
122-
raise ServiceValidationError(
123-
"Preset mode can only be set when HVAC mode is set to 'auto'",
124-
translation_domain=DOMAIN,
125-
translation_key="set_preset_mode_error",
126-
translation_placeholders={"preset_mode": preset_mode},
127-
)
128140
await self.async_set_data(preset_mode=preset_mode)
129141

130142
async def async_set_temperature(self, **kwargs: Any) -> None:
@@ -133,16 +145,17 @@ async def async_set_temperature(self, **kwargs: Any) -> None:
133145

134146
async def async_set_data(self, **kwargs: Any) -> None:
135147
"""Set device settings using BSBLAN."""
136-
data = {}
148+
data: dict[str, Any] = {}
137149
if ATTR_TEMPERATURE in kwargs:
138150
data[ATTR_TARGET_TEMPERATURE] = kwargs[ATTR_TEMPERATURE]
139151
if ATTR_HVAC_MODE in kwargs:
140-
data[ATTR_HVAC_MODE] = kwargs[ATTR_HVAC_MODE]
152+
data[ATTR_HVAC_MODE] = HA_TO_BSBLAN_HVAC_MODE[kwargs[ATTR_HVAC_MODE]]
141153
if ATTR_PRESET_MODE in kwargs:
154+
# eco preset uses BSB-Lan mode 2, none preset uses mode 1 (auto)
142155
if kwargs[ATTR_PRESET_MODE] == PRESET_ECO:
143-
data[ATTR_HVAC_MODE] = PRESET_ECO
156+
data[ATTR_HVAC_MODE] = 2
144157
elif kwargs[ATTR_PRESET_MODE] == PRESET_NONE:
145-
data[ATTR_HVAC_MODE] = PRESET_NONE
158+
data[ATTR_HVAC_MODE] = 1
146159

147160
try:
148161
await self.coordinator.client.thermostat(**data)

homeassistant/components/bsblan/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"integration_type": "device",
88
"iot_class": "local_polling",
99
"loggers": ["bsblan"],
10-
"requirements": ["python-bsblan==3.1.1"],
10+
"requirements": ["python-bsblan==3.1.3"],
1111
"zeroconf": [
1212
{
1313
"name": "bsb-lan*",

homeassistant/components/bsblan/water_heater.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from typing import Any
66

7-
from bsblan import BSBLANError
7+
from bsblan import BSBLANError, SetHotWaterParam
88

99
from homeassistant.components.water_heater import (
1010
STATE_ECO,
@@ -131,7 +131,9 @@ async def async_set_temperature(self, **kwargs: Any) -> None:
131131
"""Set new target temperature."""
132132
temperature = kwargs.get(ATTR_TEMPERATURE)
133133
try:
134-
await self.coordinator.client.set_hot_water(nominal_setpoint=temperature)
134+
await self.coordinator.client.set_hot_water(
135+
SetHotWaterParam(nominal_setpoint=temperature)
136+
)
135137
except BSBLANError as err:
136138
raise HomeAssistantError(
137139
translation_domain=DOMAIN,
@@ -144,7 +146,9 @@ async def async_set_operation_mode(self, operation_mode: str) -> None:
144146
"""Set new operation mode."""
145147
bsblan_mode = OPERATION_MODES_REVERSE.get(operation_mode)
146148
try:
147-
await self.coordinator.client.set_hot_water(operating_mode=bsblan_mode)
149+
await self.coordinator.client.set_hot_water(
150+
SetHotWaterParam(operating_mode=bsblan_mode)
151+
)
148152
except BSBLANError as err:
149153
raise HomeAssistantError(
150154
translation_domain=DOMAIN,

requirements_all.txt

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

requirements_test_all.txt

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/components/bsblan/fixtures/state.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"hvac_mode": {
33
"name": "Operating mode",
44
"error": 0,
5-
"value": "heat",
5+
"value": 3,
66
"desc": "Komfort",
77
"dataType": 1,
88
"readonly": 0,

tests/components/bsblan/snapshots/test_diagnostics.ambr

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@
121121
'readonly': 0,
122122
'readwrite': 0,
123123
'unit': '',
124-
'value': 'heat',
124+
'value': 3,
125125
}),
126126
'hvac_mode_changeover': None,
127127
'room1_temp_setpoint_boost': dict({
@@ -243,7 +243,6 @@
243243
}),
244244
'legionella_circulation_pump': None,
245245
'legionella_circulation_temp_diff': None,
246-
'legionella_dwelling_time': None,
247246
'legionella_function': dict({
248247
'data_type': 1,
249248
'desc': 'Off',
@@ -256,29 +255,10 @@
256255
'value': 0,
257256
}),
258257
'legionella_function_day': None,
258+
'legionella_function_dwelling_time': None,
259+
'legionella_function_periodicity': None,
260+
'legionella_function_setpoint': None,
259261
'legionella_function_time': None,
260-
'legionella_periodicity': dict({
261-
'data_type': 1,
262-
'desc': 'Weekly',
263-
'error': 0,
264-
'name': 'Legionella function periodicity',
265-
'precision': None,
266-
'readonly': 0,
267-
'readwrite': 0,
268-
'unit': '',
269-
'value': 7,
270-
}),
271-
'legionella_setpoint': dict({
272-
'data_type': 0,
273-
'desc': '',
274-
'error': 0,
275-
'name': 'Legionella function setpoint',
276-
'precision': None,
277-
'readonly': 0,
278-
'readwrite': 0,
279-
'unit': '°C',
280-
'value': 60.0,
281-
}),
282262
'nominal_setpoint_max': dict({
283263
'data_type': 0,
284264
'desc': '',

0 commit comments

Comments
 (0)