15
15
SUBUNIT_06 ,
16
16
SUBUNIT_07 ,
17
17
SUBUNIT_08 ,
18
- TYPE_CN_BOOL ,
19
- TYPE_CN_INT8 ,
20
- TYPE_CN_INT16 ,
21
- TYPE_CN_INT64 ,
22
- TYPE_CN_STRING ,
23
- TYPE_CN_UINT8 ,
24
- TYPE_CN_UINT16 ,
25
- TYPE_CN_UINT32 ,
18
+ PdoType ,
26
19
UNIT_ERROR ,
27
20
UNIT_SCHEDULE ,
28
21
UNIT_TEMPHUMCONTROL ,
22
+ UNIT_VENTILATIONCONFIG ,
29
23
VentilationBalance ,
30
24
VentilationMode ,
31
25
VentilationSetting ,
34
28
)
35
29
from aiocomfoconnect .properties import Property
36
30
from aiocomfoconnect .sensors import Sensor
37
- from aiocomfoconnect .util import bytearray_to_bits , bytestring
31
+ from aiocomfoconnect .util import bytearray_to_bits , bytestring , encode_pdo_value
38
32
39
33
_LOGGER = logging .getLogger (__name__ )
40
34
@@ -102,13 +96,13 @@ async def get_single_property(self, unit: int, subunit: int, property_id: int, p
102
96
"""Get a property and convert to the right type."""
103
97
result = await self .cmd_rmi_request (bytes ([0x01 , unit , subunit , 0x10 , property_id ]), node_id = node_id )
104
98
105
- if property_type == TYPE_CN_STRING :
99
+ if property_type == PdoType . TYPE_CN_STRING :
106
100
return result .message .decode ("utf-8" ).rstrip ("\x00 " )
107
- if property_type in [TYPE_CN_INT8 , TYPE_CN_INT16 , TYPE_CN_INT64 ]:
101
+ if property_type in [PdoType . TYPE_CN_INT8 , PdoType . TYPE_CN_INT16 , PdoType . TYPE_CN_INT64 ]:
108
102
return int .from_bytes (result .message , byteorder = "little" , signed = True )
109
- if property_type in [TYPE_CN_UINT8 , TYPE_CN_UINT16 , TYPE_CN_UINT32 ]:
103
+ if property_type in [PdoType . TYPE_CN_UINT8 , PdoType . TYPE_CN_UINT16 , PdoType . TYPE_CN_UINT32 ]:
110
104
return int .from_bytes (result .message , byteorder = "little" , signed = False )
111
- if property_type in [TYPE_CN_BOOL ]:
105
+ if property_type in [PdoType . TYPE_CN_BOOL ]:
112
106
return result .message [0 ] == 1
113
107
114
108
return result .message
@@ -125,6 +119,15 @@ async def set_property(self, unit: int, subunit: int, property_id: int, value: i
125
119
126
120
return result .message
127
121
122
+ async def set_property_typed (self , unit : int , subunit : int , property_id : int , value : int , pdo_type : PdoType , node_id = 1 ) -> any :
123
+ """Set a typed property."""
124
+ value_bytes = encode_pdo_value (value , pdo_type )
125
+ message_bytes = bytes ([0x03 , unit , subunit , property_id ]) + value_bytes
126
+
127
+ result = await self .cmd_rmi_request (message_bytes , node_id = node_id )
128
+
129
+ return result .message
130
+
128
131
def _sensor_callback (self , sensor_id , sensor_value ):
129
132
"""Callback function for sensor updates."""
130
133
if self ._sensor_callback_fn is None :
@@ -212,6 +215,36 @@ async def set_speed(self, speed: Literal["away", "low", "medium", "high"]):
212
215
else :
213
216
raise ValueError (f"Invalid speed: { speed } " )
214
217
218
+ async def get_flow_for_speed (self , speed : Literal ["away" , "low" , "medium" , "high" ]) -> int :
219
+ """Get the targeted airflow in m³/h for the given VentilationSpeed (away / low / medium / high)."""
220
+
221
+ match speed :
222
+ case VentilationSpeed .AWAY :
223
+ property_id = 3
224
+ case VentilationSpeed .LOW :
225
+ property_id = 4
226
+ case VentilationSpeed .MEDIUM :
227
+ property_id = 5
228
+ case VentilationSpeed .HIGH :
229
+ property_id = 6
230
+
231
+ return await self .get_single_property (UNIT_VENTILATIONCONFIG , SUBUNIT_01 , property_id , PdoType .TYPE_CN_INT16 )
232
+
233
+ async def set_flow_for_speed (self , speed : Literal ["away" , "low" , "medium" , "high" ], desired_flow : int ):
234
+ """Set the targeted airflow in m³/h for the given VentilationSpeed (away / low / medium / high)."""
235
+
236
+ match speed :
237
+ case VentilationSpeed .AWAY :
238
+ property_id = 3
239
+ case VentilationSpeed .LOW :
240
+ property_id = 4
241
+ case VentilationSpeed .MEDIUM :
242
+ property_id = 5
243
+ case VentilationSpeed .HIGH :
244
+ property_id = 6
245
+
246
+ await self .set_property_typed (UNIT_VENTILATIONCONFIG , SUBUNIT_01 , property_id , desired_flow , PdoType .TYPE_CN_INT16 )
247
+
215
248
async def get_bypass (self ):
216
249
"""Get the bypass mode (auto / on / off)."""
217
250
result = await self .cmd_rmi_request (bytes ([0x83 , UNIT_SCHEDULE , SUBUNIT_02 , 0x01 ]))
0 commit comments