24
24
BOOST_ATTR_ID = 0x4043
25
25
26
26
"""Bosch specific user interface attribute ids."""
27
- SCREEN_ORIENTATION_ATTR_ID = 0x400b
27
+ SCREEN_ORIENTATION_ATTR_ID = 0x400B
28
28
DISPLAY_MODE_ATTR_ID = 0x4039
29
- SCREEN_TIMEOUT_ATTR_ID = 0x403a
30
- SCREEN_BRIGHTNESS_ATTR_ID = 0x403b
29
+ SCREEN_TIMEOUT_ATTR_ID = 0x403A
30
+ SCREEN_BRIGHTNESS_ATTR_ID = 0x403B
31
31
32
32
"""Bosh operating mode attribute values."""
33
+
34
+
33
35
class BoschOperatingMode (t .enum8 ):
34
36
Schedule = 0x00
35
37
Manual = 0x01
36
38
Pause = 0x05
37
39
40
+
38
41
"""Bosch thermostat preset."""
42
+
43
+
39
44
class BoschPreset (t .enum8 ):
40
45
Normal = 0x00
41
46
Boost = 0x01
42
47
48
+
43
49
"""Binary attribute (window open) value."""
50
+
51
+
44
52
class State (t .enum8 ):
45
53
Off = 0x00
46
54
On = 0x01
47
55
56
+
48
57
"""Bosch display orientation attribute values."""
58
+
59
+
49
60
class BoschDisplayOrientation (t .enum8 ):
50
61
Normal = 0x00
51
62
Flipped = 0x01
52
63
64
+
53
65
"""Bosch displayed temperature attribute values."""
66
+
67
+
54
68
class BoschDisplayedTemperature (t .enum8 ):
55
69
Target = 0x00
56
70
Measured = 0x01
57
71
72
+
58
73
"""HA thermostat attribute that needs special handling in the Bosch thermostat entity."""
59
74
SYSTEM_MODE_ATTR = Thermostat .AttributeDefs .system_mode
60
75
@@ -65,7 +80,7 @@ class BoschDisplayedTemperature(t.enum8):
65
80
BoschOperatingMode .Pause : Thermostat .SystemMode .Off ,
66
81
"BoschOperatingMode.Schedule" : Thermostat .SystemMode .Auto ,
67
82
"BoschOperatingMode.Manual" : Thermostat .SystemMode .Heat ,
68
- "BoschOperatingMode.Pause" : Thermostat .SystemMode .Off
83
+ "BoschOperatingMode.Pause" : Thermostat .SystemMode .Off ,
69
84
}
70
85
71
86
"""HA system mode to Bosch operating mode mapping."""
@@ -75,16 +90,17 @@ class BoschDisplayedTemperature(t.enum8):
75
90
Thermostat .SystemMode .Auto : BoschOperatingMode .Schedule ,
76
91
"SystemMode.Off" : BoschOperatingMode .Pause ,
77
92
"SystemMode.Heat" : BoschOperatingMode .Manual ,
78
- "SystemMode.Auto" : BoschOperatingMode .Schedule
93
+ "SystemMode.Auto" : BoschOperatingMode .Schedule ,
79
94
}
80
95
81
96
DISPLAY_ORIENTATION_ENUM_TO_INT_MAP = {
82
97
0x00 : 0x00 ,
83
98
0x01 : 0x01 ,
84
99
"BoschDisplayOrientation.Normal" : 0x00 ,
85
- "BoschDisplayOrientation.Flipped" : 0x01
100
+ "BoschDisplayOrientation.Flipped" : 0x01 ,
86
101
}
87
102
103
+
88
104
class BoschThermostatCluster (CustomCluster , Thermostat ):
89
105
"""Bosch thermostat cluster."""
90
106
@@ -121,14 +137,12 @@ class AttributeDefs(Thermostat.AttributeDefs):
121
137
)
122
138
123
139
async def write_attributes (
124
- self ,
125
- attributes : dict [str | int , Any ],
126
- manufacturer : int | None = None
140
+ self , attributes : dict [str | int , Any ], manufacturer : int | None = None
127
141
) -> list :
128
142
"""system_mode special handling:
129
- - turn off by setting operating_mode to Pause
130
- - turn on by setting operating_mode to Manual
131
- - add new system_mode value to the internal zigpy Cluster cache
143
+ - turn off by setting operating_mode to Pause
144
+ - turn on by setting operating_mode to Manual
145
+ - add new system_mode value to the internal zigpy Cluster cache
132
146
"""
133
147
134
148
operating_mode_attr = self .AttributeDefs .operating_mode
@@ -162,25 +176,32 @@ async def write_attributes(
162
176
163
177
if operating_mode_attribute_id is not None :
164
178
if system_mode_value is not None :
165
- operating_mode_value = remaining_attributes .pop (operating_mode_attribute_id )
179
+ operating_mode_value = remaining_attributes .pop (
180
+ operating_mode_attribute_id
181
+ )
166
182
else :
167
183
operating_mode_value = attributes .get (operating_mode_attribute_id )
168
184
169
185
if system_mode_value is not None :
170
186
"""Write operating_mode (from system_mode value)."""
171
- new_operating_mode_value = SYSTEM_MODE_TO_OPERATING_MODE_MAP [system_mode_value ]
172
- result += await super ().write_attributes ({operating_mode_attr .id : new_operating_mode_value }, manufacturer )
187
+ new_operating_mode_value = SYSTEM_MODE_TO_OPERATING_MODE_MAP [
188
+ system_mode_value
189
+ ]
190
+ result += await super ().write_attributes (
191
+ {operating_mode_attr .id : new_operating_mode_value }, manufacturer
192
+ )
173
193
self ._update_attribute (SYSTEM_MODE_ATTR .id , system_mode_value )
174
194
elif operating_mode_value is not None :
175
- new_system_mode_value = OPERATING_MODE_TO_SYSTEM_MODE_MAP [operating_mode_value ]
195
+ new_system_mode_value = OPERATING_MODE_TO_SYSTEM_MODE_MAP [
196
+ operating_mode_value
197
+ ]
176
198
self ._update_attribute (SYSTEM_MODE_ATTR .id , new_system_mode_value )
177
199
178
200
"""Write the remaining attributes to thermostat cluster."""
179
201
if remaining_attributes :
180
202
result += await super ().write_attributes (remaining_attributes , manufacturer )
181
203
return result
182
204
183
-
184
205
async def read_attributes (
185
206
self ,
186
207
attributes : list [int | str ],
@@ -189,7 +210,7 @@ async def read_attributes(
189
210
manufacturer : int | t .uint16_t | None = None ,
190
211
):
191
212
"""system_mode special handling:
192
- - read and convert operating_mode to system_mode.
213
+ - read and convert operating_mode to system_mode.
193
214
"""
194
215
195
216
operating_mode_attr = self .AttributeDefs .operating_mode
@@ -212,7 +233,9 @@ async def read_attributes(
212
233
)
213
234
if operating_mode_attr .name in successful_r :
214
235
operating_mode_value = successful_r .pop (operating_mode_attr .name )
215
- system_mode_value = OPERATING_MODE_TO_SYSTEM_MODE_MAP [operating_mode_value ]
236
+ system_mode_value = OPERATING_MODE_TO_SYSTEM_MODE_MAP [
237
+ operating_mode_value
238
+ ]
216
239
successful_r [system_mode_attribute_id ] = system_mode_value
217
240
self ._update_attribute (SYSTEM_MODE_ATTR .id , system_mode_value )
218
241
@@ -260,12 +283,10 @@ class AttributeDefs(UserInterface.AttributeDefs):
260
283
)
261
284
262
285
async def write_attributes (
263
- self ,
264
- attributes : dict [str | int , Any ],
265
- manufacturer : int | None = None
286
+ self , attributes : dict [str | int , Any ], manufacturer : int | None = None
266
287
) -> list :
267
288
"""display_orientation special handling:
268
- - convert from enum to uint8_t
289
+ - convert from enum to uint8_t
269
290
"""
270
291
display_orientation_attr = self .AttributeDefs .display_orientation
271
292
@@ -279,20 +300,25 @@ async def write_attributes(
279
300
display_orientation_attribute_id = display_orientation_attr .name
280
301
281
302
if display_orientation_attribute_id is not None :
282
- display_orientation_value = remaining_attributes .pop (display_orientation_attr .id )
283
- new_display_orientation_value = DISPLAY_ORIENTATION_ENUM_TO_INT_MAP [display_orientation_value ]
284
- remaining_attributes [display_orientation_attribute_id ] = new_display_orientation_value
303
+ display_orientation_value = remaining_attributes .pop (
304
+ display_orientation_attr .id
305
+ )
306
+ new_display_orientation_value = DISPLAY_ORIENTATION_ENUM_TO_INT_MAP [
307
+ display_orientation_value
308
+ ]
309
+ remaining_attributes [display_orientation_attribute_id ] = (
310
+ new_display_orientation_value
311
+ )
285
312
286
313
return await super ().write_attributes (remaining_attributes , manufacturer )
287
314
288
315
289
316
class BoschThermostat (CustomDeviceV2 ):
290
317
"""Bosch thermostat custom device."""
291
318
319
+
292
320
(
293
- add_to_registry_v2 (
294
- "BOSCH" , "RBSH-TRV0-ZB-EU"
295
- )
321
+ add_to_registry_v2 ("BOSCH" , "RBSH-TRV0-ZB-EU" )
296
322
.device_class (BoschThermostat )
297
323
.replaces (BoschThermostatCluster )
298
324
.replaces (BoschUserInterfaceCluster )
@@ -301,20 +327,20 @@ class BoschThermostat(CustomDeviceV2):
301
327
BoschThermostatCluster .AttributeDefs .operating_mode .name ,
302
328
BoschOperatingMode ,
303
329
BoschThermostatCluster .cluster_id ,
304
- translation_key = "switch_mode"
330
+ translation_key = "switch_mode" ,
305
331
)
306
332
# Preset - normal/boost.
307
333
.enum (
308
334
BoschThermostatCluster .AttributeDefs .boost .name ,
309
335
BoschPreset ,
310
336
BoschThermostatCluster .cluster_id ,
311
- translation_key = "preset"
337
+ translation_key = "preset" ,
312
338
)
313
339
# Window open switch: manually set or through an automation.
314
340
.switch (
315
341
BoschThermostatCluster .AttributeDefs .window_open .name ,
316
342
BoschThermostatCluster .cluster_id ,
317
- translation_key = "window_detection"
343
+ translation_key = "window_detection" ,
318
344
)
319
345
# Remote temperature
320
346
.number (
@@ -325,21 +351,21 @@ class BoschThermostat(CustomDeviceV2):
325
351
step = 0.1 ,
326
352
multiplier = 100 ,
327
353
device_class = NumberDeviceClass .TEMPERATURE ,
328
- #translation_key="external_sensor"
354
+ # translation_key="external_sensor"
329
355
)
330
356
# Display temperature.
331
357
.enum (
332
358
BoschUserInterfaceCluster .AttributeDefs .displayed_temperature .name ,
333
359
BoschDisplayedTemperature ,
334
360
BoschUserInterfaceCluster .cluster_id ,
335
- translation_key = "device_temperature"
361
+ translation_key = "device_temperature" ,
336
362
)
337
363
# Display orientation
338
364
.enum (
339
365
BoschUserInterfaceCluster .AttributeDefs .display_orientation .name ,
340
366
BoschDisplayOrientation ,
341
367
BoschUserInterfaceCluster .cluster_id ,
342
- translation_key = "inverted"
368
+ translation_key = "inverted" ,
343
369
)
344
370
# Display time-out
345
371
.number (
@@ -348,7 +374,7 @@ class BoschThermostat(CustomDeviceV2):
348
374
min_value = 5 ,
349
375
max_value = 30 ,
350
376
step = 1 ,
351
- translation_key = "on_off_transition_time"
377
+ translation_key = "on_off_transition_time" ,
352
378
)
353
379
# Display brightness
354
380
.number (
@@ -357,6 +383,6 @@ class BoschThermostat(CustomDeviceV2):
357
383
min_value = 0 ,
358
384
max_value = 10 ,
359
385
step = 1 ,
360
- translation_key = "backlight_mode"
386
+ translation_key = "backlight_mode" ,
361
387
)
362
388
)
0 commit comments