Skip to content

Commit 56e1b54

Browse files
committed
Code formating using black.
1 parent 21cb023 commit 56e1b54

File tree

2 files changed

+81
-47
lines changed

2 files changed

+81
-47
lines changed

zhaquirks/bosch/rbsh_rth0_zb_eu.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,34 @@
2323
BOOST_ATTR_ID = 0x4043
2424

2525
"""Bosch specific user interface attribute ids."""
26-
SCREEN_TIMEOUT_ATTR_ID = 0x403a
27-
SCREEN_BRIGHTNESS_ATTR_ID = 0x403b
26+
SCREEN_TIMEOUT_ATTR_ID = 0x403A
27+
SCREEN_BRIGHTNESS_ATTR_ID = 0x403B
2828

2929
"""Bosh operating mode attribute values."""
30+
31+
3032
class BoschOperatingMode(t.enum8):
3133
Schedule = 0x00
3234
Manual = 0x01
3335
Pause = 0x05
3436

37+
3538
"""Bosch thermostat preset."""
39+
40+
3641
class BoschPreset(t.enum8):
3742
Normal = 0x00
3843
Boost = 0x01
3944

45+
4046
"""Binary attribute (window open) value."""
47+
48+
4149
class State(t.enum8):
4250
Off = 0x00
4351
On = 0x01
4452

53+
4554
class BoschThermostatCluster(CustomCluster, Thermostat):
4655
"""Bosch thermostat cluster."""
4756

@@ -94,10 +103,9 @@ class AttributeDefs(UserInterface.AttributeDefs):
94103
class BoschThermostat(CustomDeviceV2):
95104
"""Bosch thermostat custom device."""
96105

106+
97107
(
98-
add_to_registry_v2(
99-
"Bosch", "RBSH-RTH0-ZB-EU"
100-
)
108+
add_to_registry_v2("Bosch", "RBSH-RTH0-ZB-EU")
101109
.device_class(BoschThermostat)
102110
.replaces(BoschThermostatCluster)
103111
.replaces(BoschUserInterfaceCluster)
@@ -106,20 +114,20 @@ class BoschThermostat(CustomDeviceV2):
106114
BoschThermostatCluster.AttributeDefs.operating_mode.name,
107115
BoschOperatingMode,
108116
BoschThermostatCluster.cluster_id,
109-
translation_key="switch_mode"
117+
translation_key="switch_mode",
110118
)
111119
# Preset - normal/boost.
112120
.enum(
113121
BoschThermostatCluster.AttributeDefs.boost.name,
114122
BoschPreset,
115123
BoschThermostatCluster.cluster_id,
116-
translation_key="preset"
124+
translation_key="preset",
117125
)
118126
# Window open switch: manually set or through an automation.
119127
.switch(
120128
BoschThermostatCluster.AttributeDefs.window_open.name,
121129
BoschThermostatCluster.cluster_id,
122-
translation_key="window_detection"
130+
translation_key="window_detection",
123131
)
124132
# Display time-out
125133
.number(
@@ -128,7 +136,7 @@ class BoschThermostat(CustomDeviceV2):
128136
min_value=5,
129137
max_value=30,
130138
step=1,
131-
translation_key="on_off_transition_time"
139+
translation_key="on_off_transition_time",
132140
)
133141
# Display brightness
134142
.number(
@@ -137,6 +145,6 @@ class BoschThermostat(CustomDeviceV2):
137145
min_value=0,
138146
max_value=10,
139147
step=1,
140-
translation_key="backlight_mode"
148+
translation_key="backlight_mode",
141149
)
142150
)

zhaquirks/bosch/rbsh_trv0_zb_eu.py

Lines changed: 63 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -24,37 +24,52 @@
2424
BOOST_ATTR_ID = 0x4043
2525

2626
"""Bosch specific user interface attribute ids."""
27-
SCREEN_ORIENTATION_ATTR_ID = 0x400b
27+
SCREEN_ORIENTATION_ATTR_ID = 0x400B
2828
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
3131

3232
"""Bosh operating mode attribute values."""
33+
34+
3335
class BoschOperatingMode(t.enum8):
3436
Schedule = 0x00
3537
Manual = 0x01
3638
Pause = 0x05
3739

40+
3841
"""Bosch thermostat preset."""
42+
43+
3944
class BoschPreset(t.enum8):
4045
Normal = 0x00
4146
Boost = 0x01
4247

48+
4349
"""Binary attribute (window open) value."""
50+
51+
4452
class State(t.enum8):
4553
Off = 0x00
4654
On = 0x01
4755

56+
4857
"""Bosch display orientation attribute values."""
58+
59+
4960
class BoschDisplayOrientation(t.enum8):
5061
Normal = 0x00
5162
Flipped = 0x01
5263

64+
5365
"""Bosch displayed temperature attribute values."""
66+
67+
5468
class BoschDisplayedTemperature(t.enum8):
5569
Target = 0x00
5670
Measured = 0x01
5771

72+
5873
"""HA thermostat attribute that needs special handling in the Bosch thermostat entity."""
5974
SYSTEM_MODE_ATTR = Thermostat.AttributeDefs.system_mode
6075

@@ -65,7 +80,7 @@ class BoschDisplayedTemperature(t.enum8):
6580
BoschOperatingMode.Pause: Thermostat.SystemMode.Off,
6681
"BoschOperatingMode.Schedule": Thermostat.SystemMode.Auto,
6782
"BoschOperatingMode.Manual": Thermostat.SystemMode.Heat,
68-
"BoschOperatingMode.Pause": Thermostat.SystemMode.Off
83+
"BoschOperatingMode.Pause": Thermostat.SystemMode.Off,
6984
}
7085

7186
"""HA system mode to Bosch operating mode mapping."""
@@ -75,16 +90,17 @@ class BoschDisplayedTemperature(t.enum8):
7590
Thermostat.SystemMode.Auto: BoschOperatingMode.Schedule,
7691
"SystemMode.Off": BoschOperatingMode.Pause,
7792
"SystemMode.Heat": BoschOperatingMode.Manual,
78-
"SystemMode.Auto": BoschOperatingMode.Schedule
93+
"SystemMode.Auto": BoschOperatingMode.Schedule,
7994
}
8095

8196
DISPLAY_ORIENTATION_ENUM_TO_INT_MAP = {
8297
0x00: 0x00,
8398
0x01: 0x01,
8499
"BoschDisplayOrientation.Normal": 0x00,
85-
"BoschDisplayOrientation.Flipped": 0x01
100+
"BoschDisplayOrientation.Flipped": 0x01,
86101
}
87102

103+
88104
class BoschThermostatCluster(CustomCluster, Thermostat):
89105
"""Bosch thermostat cluster."""
90106

@@ -121,14 +137,12 @@ class AttributeDefs(Thermostat.AttributeDefs):
121137
)
122138

123139
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
127141
) -> list:
128142
"""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
132146
"""
133147

134148
operating_mode_attr = self.AttributeDefs.operating_mode
@@ -162,25 +176,32 @@ async def write_attributes(
162176

163177
if operating_mode_attribute_id is not None:
164178
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+
)
166182
else:
167183
operating_mode_value = attributes.get(operating_mode_attribute_id)
168184

169185
if system_mode_value is not None:
170186
"""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+
)
173193
self._update_attribute(SYSTEM_MODE_ATTR.id, system_mode_value)
174194
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+
]
176198
self._update_attribute(SYSTEM_MODE_ATTR.id, new_system_mode_value)
177199

178200
"""Write the remaining attributes to thermostat cluster."""
179201
if remaining_attributes:
180202
result += await super().write_attributes(remaining_attributes, manufacturer)
181203
return result
182204

183-
184205
async def read_attributes(
185206
self,
186207
attributes: list[int | str],
@@ -189,7 +210,7 @@ async def read_attributes(
189210
manufacturer: int | t.uint16_t | None = None,
190211
):
191212
"""system_mode special handling:
192-
- read and convert operating_mode to system_mode.
213+
- read and convert operating_mode to system_mode.
193214
"""
194215

195216
operating_mode_attr = self.AttributeDefs.operating_mode
@@ -212,7 +233,9 @@ async def read_attributes(
212233
)
213234
if operating_mode_attr.name in successful_r:
214235
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+
]
216239
successful_r[system_mode_attribute_id] = system_mode_value
217240
self._update_attribute(SYSTEM_MODE_ATTR.id, system_mode_value)
218241

@@ -260,12 +283,10 @@ class AttributeDefs(UserInterface.AttributeDefs):
260283
)
261284

262285
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
266287
) -> list:
267288
"""display_orientation special handling:
268-
- convert from enum to uint8_t
289+
- convert from enum to uint8_t
269290
"""
270291
display_orientation_attr = self.AttributeDefs.display_orientation
271292

@@ -279,20 +300,25 @@ async def write_attributes(
279300
display_orientation_attribute_id = display_orientation_attr.name
280301

281302
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+
)
285312

286313
return await super().write_attributes(remaining_attributes, manufacturer)
287314

288315

289316
class BoschThermostat(CustomDeviceV2):
290317
"""Bosch thermostat custom device."""
291318

319+
292320
(
293-
add_to_registry_v2(
294-
"BOSCH", "RBSH-TRV0-ZB-EU"
295-
)
321+
add_to_registry_v2("BOSCH", "RBSH-TRV0-ZB-EU")
296322
.device_class(BoschThermostat)
297323
.replaces(BoschThermostatCluster)
298324
.replaces(BoschUserInterfaceCluster)
@@ -301,20 +327,20 @@ class BoschThermostat(CustomDeviceV2):
301327
BoschThermostatCluster.AttributeDefs.operating_mode.name,
302328
BoschOperatingMode,
303329
BoschThermostatCluster.cluster_id,
304-
translation_key="switch_mode"
330+
translation_key="switch_mode",
305331
)
306332
# Preset - normal/boost.
307333
.enum(
308334
BoschThermostatCluster.AttributeDefs.boost.name,
309335
BoschPreset,
310336
BoschThermostatCluster.cluster_id,
311-
translation_key="preset"
337+
translation_key="preset",
312338
)
313339
# Window open switch: manually set or through an automation.
314340
.switch(
315341
BoschThermostatCluster.AttributeDefs.window_open.name,
316342
BoschThermostatCluster.cluster_id,
317-
translation_key="window_detection"
343+
translation_key="window_detection",
318344
)
319345
# Remote temperature
320346
.number(
@@ -325,21 +351,21 @@ class BoschThermostat(CustomDeviceV2):
325351
step=0.1,
326352
multiplier=100,
327353
device_class=NumberDeviceClass.TEMPERATURE,
328-
#translation_key="external_sensor"
354+
# translation_key="external_sensor"
329355
)
330356
# Display temperature.
331357
.enum(
332358
BoschUserInterfaceCluster.AttributeDefs.displayed_temperature.name,
333359
BoschDisplayedTemperature,
334360
BoschUserInterfaceCluster.cluster_id,
335-
translation_key="device_temperature"
361+
translation_key="device_temperature",
336362
)
337363
# Display orientation
338364
.enum(
339365
BoschUserInterfaceCluster.AttributeDefs.display_orientation.name,
340366
BoschDisplayOrientation,
341367
BoschUserInterfaceCluster.cluster_id,
342-
translation_key="inverted"
368+
translation_key="inverted",
343369
)
344370
# Display time-out
345371
.number(
@@ -348,7 +374,7 @@ class BoschThermostat(CustomDeviceV2):
348374
min_value=5,
349375
max_value=30,
350376
step=1,
351-
translation_key="on_off_transition_time"
377+
translation_key="on_off_transition_time",
352378
)
353379
# Display brightness
354380
.number(
@@ -357,6 +383,6 @@ class BoschThermostat(CustomDeviceV2):
357383
min_value=0,
358384
max_value=10,
359385
step=1,
360-
translation_key="backlight_mode"
386+
translation_key="backlight_mode",
361387
)
362388
)

0 commit comments

Comments
 (0)