aiocomfoconnect 0.3.3__tar.gz → 0.4.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {aiocomfoconnect-0.3.3 → aiocomfoconnect-0.4.0}/PKG-INFO +19 -15
- {aiocomfoconnect-0.3.3 → aiocomfoconnect-0.4.0}/README.md +16 -13
- aiocomfoconnect-0.4.0/aiocomfoconnect/__main__.py +296 -0
- {aiocomfoconnect-0.3.3 → aiocomfoconnect-0.4.0}/aiocomfoconnect/bridge.py +192 -264
- aiocomfoconnect-0.4.0/aiocomfoconnect/comfoconnect.py +612 -0
- {aiocomfoconnect-0.3.3 → aiocomfoconnect-0.4.0}/aiocomfoconnect/const.py +55 -8
- {aiocomfoconnect-0.3.3 → aiocomfoconnect-0.4.0}/aiocomfoconnect/discovery.py +18 -18
- {aiocomfoconnect-0.3.3 → aiocomfoconnect-0.4.0}/aiocomfoconnect/exceptions.py +23 -9
- aiocomfoconnect-0.4.0/aiocomfoconnect/properties.py +93 -0
- aiocomfoconnect-0.4.0/aiocomfoconnect/sensors.py +228 -0
- {aiocomfoconnect-0.3.3 → aiocomfoconnect-0.4.0}/aiocomfoconnect/util.py +8 -34
- {aiocomfoconnect-0.3.3 → aiocomfoconnect-0.4.0}/pyproject.toml +2 -2
- aiocomfoconnect-0.3.3/aiocomfoconnect/__main__.py +0 -543
- aiocomfoconnect-0.3.3/aiocomfoconnect/comfoconnect.py +0 -689
- aiocomfoconnect-0.3.3/aiocomfoconnect/properties.py +0 -73
- aiocomfoconnect-0.3.3/aiocomfoconnect/sensors.py +0 -222
- {aiocomfoconnect-0.3.3 → aiocomfoconnect-0.4.0}/LICENSE +0 -0
- {aiocomfoconnect-0.3.3 → aiocomfoconnect-0.4.0}/aiocomfoconnect/__init__.py +0 -0
- {aiocomfoconnect-0.3.3 → aiocomfoconnect-0.4.0}/aiocomfoconnect/protobuf/nanopb_pb2.py +0 -0
- {aiocomfoconnect-0.3.3 → aiocomfoconnect-0.4.0}/aiocomfoconnect/protobuf/zehnder_pb2.py +0 -0
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: aiocomfoconnect
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.0
|
|
4
4
|
Summary: aiocomfoconnect is an asyncio Python 3 library for communicating with a Zehnder ComfoAir Q350/450/600 ventilation system
|
|
5
|
+
License: MIT
|
|
5
6
|
License-File: LICENSE
|
|
6
7
|
Author: Michaël Arnauts
|
|
7
8
|
Author-email: michael.arnauts@gmail.com
|
|
8
9
|
Requires-Python: >=3.13,<4.0
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
11
|
Classifier: Programming Language :: Python :: 3
|
|
10
12
|
Classifier: Programming Language :: Python :: 3.13
|
|
11
13
|
Classifier: Programming Language :: Python :: 3.14
|
|
12
14
|
Classifier: Programming Language :: Python :: 3.15
|
|
13
|
-
Requires-Dist: aiohttp (>=3.8.0,<4.0.0)
|
|
14
15
|
Requires-Dist: protobuf (>=6.31,<8)
|
|
15
16
|
Project-URL: Homepage, https://github.com/michaelarnauts/aiocomfoconnect
|
|
16
17
|
Description-Content-Type: text/markdown
|
|
@@ -38,6 +39,8 @@ $ python -m aiocomfoconnect --help
|
|
|
38
39
|
$ python -m aiocomfoconnect discover
|
|
39
40
|
|
|
40
41
|
$ python -m aiocomfoconnect register --host 192.168.1.213
|
|
42
|
+
$ python -m aiocomfoconnect deregister --host 192.168.1.213 # List the registered apps
|
|
43
|
+
$ python -m aiocomfoconnect deregister --host 192.168.1.213 <uuid> # Deregister an app
|
|
41
44
|
|
|
42
45
|
$ python -m aiocomfoconnect set-speed away --host 192.168.1.213
|
|
43
46
|
$ python -m aiocomfoconnect set-speed low --host 192.168.1.213
|
|
@@ -54,11 +57,14 @@ $ python -m aiocomfoconnect show-sensor 276 --host 192.168.1.213
|
|
|
54
57
|
$ python -m aiocomfoconnect show-sensor 276 --host 192.168.1.213 -f
|
|
55
58
|
|
|
56
59
|
$ python -m aiocomfoconnect get-property --host 192.168.1.213 1 1 8 9 # Unit 0x01, SubUnit 0x01, Property 0x08, Type STRING. See PROTOCOL-RMI.md
|
|
60
|
+
$ python -m aiocomfoconnect get-property --host 192.168.1.213 30 1 4 6 # The airflow of the low speed in m³/h (away=3, low=4, medium=5, high=6), Type INT16
|
|
61
|
+
$ python -m aiocomfoconnect set-property --host 192.168.1.213 30 1 4 6 120 # Set the airflow of the low speed to 120 m³/h
|
|
57
62
|
```
|
|
58
63
|
|
|
59
64
|
## Available methods
|
|
60
65
|
|
|
61
|
-
- `async connect()`: Connect to the bridge.
|
|
66
|
+
- `async connect()`: Connect to the bridge. The connection is kept: when it is lost, it reconnects, and when nothing was received for `heartbeat_interval` seconds (30 by default, `None` disables it), it checks that the bridge still answers.
|
|
67
|
+
- `connection_state_callback`: Pass it to `ComfoConnect()` to be called with a `ConnectionState` when the state of the session changes.
|
|
62
68
|
- `async disconnect()`: Disconnect from the bridge.
|
|
63
69
|
- `async register_sensor(sensor)`: Register a sensor.
|
|
64
70
|
- `async deregister_sensor(sensor)`: Deregister a sensor.
|
|
@@ -66,26 +72,24 @@ $ python -m aiocomfoconnect get-property --host 192.168.1.213 1 1 8 9 # Unit 0x
|
|
|
66
72
|
- `async set_mode(mode)`: Set the ventilation mode. (auto / manual) Selecting `auto` also cancels the temporary fan-speed override and returns control to the unit's schedule.
|
|
67
73
|
- `async get_comfocool_mode()`: Get Comfocool mode
|
|
68
74
|
- `async set_comfocool_mode()`: Set Comfocool mode. (auto / off)
|
|
69
|
-
- `async get_speed()`: Get the ventilation speed.
|
|
75
|
+
- `async get_speed()`: Get the ventilation speed, or `None` when no speed is set and the unit follows its schedule (auto mode).
|
|
70
76
|
- `async set_speed(speed)`: Set the ventilation speed. (away / low / medium / high)
|
|
71
77
|
- `async get_bypass()`: Get the bypass mode.
|
|
72
78
|
- `async set_bypass(mode, timeout=-1)`: Set the bypass mode. (auto / on / off)
|
|
73
79
|
- `async get_balance_mode()`: Get the balance mode.
|
|
74
80
|
- `async set_balance_mode(mode, timeout=-1)`: Set the balance mode. (balance / supply only / exhaust only)
|
|
75
81
|
- `async get_boost()`: Get the boost mode.
|
|
76
|
-
- `async set_boost(mode, timeout
|
|
82
|
+
- `async set_boost(mode, timeout=3600)`: Set the boost mode. (boolean)
|
|
77
83
|
- `async get_away()`: Get the away mode.
|
|
78
|
-
- `async set_away(mode, timeout
|
|
79
|
-
- `async get_temperature_profile()`: Get the temperature profile.
|
|
84
|
+
- `async set_away(mode, timeout=3600)`: Set the away mode. (boolean)
|
|
85
|
+
- `async get_temperature_profile()`: Get the temperature profile, or `None` when no profile is set and the unit follows its schedule.
|
|
80
86
|
- `async set_temperature_profile(profile)`: Set the temperature profile. (warm / normal / cool)
|
|
81
|
-
- `async
|
|
82
|
-
- `async
|
|
83
|
-
-
|
|
84
|
-
-
|
|
85
|
-
- `
|
|
86
|
-
- `async
|
|
87
|
-
- `async get_property(prop)`: Get the value of a property, e.g. `PROPERTY_RMOT_HEATING_THRESHOLD`.
|
|
88
|
-
- `async get_property_constraints(prop)`: Get the raw value of a numeric property, together with the range and step size the unit accepts.
|
|
87
|
+
- `async get_property(prop, node_id=None)`: Get the value of a property, e.g. `PROPERTY_RMOT_HEATING_THRESHOLD`. It is read from the node the property lives on: the ventilation unit, or the ComfoClime for the `PROPERTY_CLIME_*` properties. Pass `node_id` to read it from another node. A `NodeNotFoundException` is raised when the node isn't on the bus.
|
|
88
|
+
- `async set_property(prop, value, node_id=None)`: Set a property, on the same node as `get_property`.
|
|
89
|
+
- The airflow in m³/h of each fan speed is a property: `PROPERTY_FLOW_AWAY`, `PROPERTY_FLOW_LOW`, `PROPERTY_FLOW_MEDIUM` and `PROPERTY_FLOW_HIGH`, e.g. `await comfoconnect.set_property(PROPERTY_FLOW_LOW, 120)`.
|
|
90
|
+
- Properties that are an enum, like `PROPERTY_SENSOR_VENTILATION_TEMP_PASSIVE`, `PROPERTY_SENSOR_VENTILATION_HUMIDITY_COMFORT` and `PROPERTY_SENSOR_VENTILATION_HUMIDITY_PROTECTION` (off / auto / on), `PROPERTY_TEMPERATURE_PROFILE_MODE` (adaptive / fixed), `PROPERTY_CLIME_SEASON` and `PROPERTY_CLIME_TEMPERATURE_PROFILE`, have `options`: `get_property` returns the option and `set_property` takes it. `get_property_constraints` still uses the raw values.
|
|
91
|
+
- Temperatures in tenths of a degree, like `PROPERTY_RMOT_HEATING_THRESHOLD`, `PROPERTY_PROFILE_TEMPERATURE_NORMAL` and the ComfoClime temperatures, have `scale=0.1`: `get_property` and `get_property_constraints` return °C (215 becomes 21.5) and `set_property` takes °C.
|
|
92
|
+
- `async get_property_constraints(prop, node_id=None)`: Get the value of a numeric property, together with the range and step size the unit accepts.
|
|
89
93
|
- `bridge_type`: The type of the bridge (`GatewayType.LANC`, `SEASON` or `PRO`). Discovery reports it, and a ComfoConnect Pro is also recognised once a session has started.
|
|
90
94
|
|
|
91
95
|
### Low-level API
|
|
@@ -21,6 +21,8 @@ $ python -m aiocomfoconnect --help
|
|
|
21
21
|
$ python -m aiocomfoconnect discover
|
|
22
22
|
|
|
23
23
|
$ python -m aiocomfoconnect register --host 192.168.1.213
|
|
24
|
+
$ python -m aiocomfoconnect deregister --host 192.168.1.213 # List the registered apps
|
|
25
|
+
$ python -m aiocomfoconnect deregister --host 192.168.1.213 <uuid> # Deregister an app
|
|
24
26
|
|
|
25
27
|
$ python -m aiocomfoconnect set-speed away --host 192.168.1.213
|
|
26
28
|
$ python -m aiocomfoconnect set-speed low --host 192.168.1.213
|
|
@@ -37,11 +39,14 @@ $ python -m aiocomfoconnect show-sensor 276 --host 192.168.1.213
|
|
|
37
39
|
$ python -m aiocomfoconnect show-sensor 276 --host 192.168.1.213 -f
|
|
38
40
|
|
|
39
41
|
$ python -m aiocomfoconnect get-property --host 192.168.1.213 1 1 8 9 # Unit 0x01, SubUnit 0x01, Property 0x08, Type STRING. See PROTOCOL-RMI.md
|
|
42
|
+
$ python -m aiocomfoconnect get-property --host 192.168.1.213 30 1 4 6 # The airflow of the low speed in m³/h (away=3, low=4, medium=5, high=6), Type INT16
|
|
43
|
+
$ python -m aiocomfoconnect set-property --host 192.168.1.213 30 1 4 6 120 # Set the airflow of the low speed to 120 m³/h
|
|
40
44
|
```
|
|
41
45
|
|
|
42
46
|
## Available methods
|
|
43
47
|
|
|
44
|
-
- `async connect()`: Connect to the bridge.
|
|
48
|
+
- `async connect()`: Connect to the bridge. The connection is kept: when it is lost, it reconnects, and when nothing was received for `heartbeat_interval` seconds (30 by default, `None` disables it), it checks that the bridge still answers.
|
|
49
|
+
- `connection_state_callback`: Pass it to `ComfoConnect()` to be called with a `ConnectionState` when the state of the session changes.
|
|
45
50
|
- `async disconnect()`: Disconnect from the bridge.
|
|
46
51
|
- `async register_sensor(sensor)`: Register a sensor.
|
|
47
52
|
- `async deregister_sensor(sensor)`: Deregister a sensor.
|
|
@@ -49,26 +54,24 @@ $ python -m aiocomfoconnect get-property --host 192.168.1.213 1 1 8 9 # Unit 0x
|
|
|
49
54
|
- `async set_mode(mode)`: Set the ventilation mode. (auto / manual) Selecting `auto` also cancels the temporary fan-speed override and returns control to the unit's schedule.
|
|
50
55
|
- `async get_comfocool_mode()`: Get Comfocool mode
|
|
51
56
|
- `async set_comfocool_mode()`: Set Comfocool mode. (auto / off)
|
|
52
|
-
- `async get_speed()`: Get the ventilation speed.
|
|
57
|
+
- `async get_speed()`: Get the ventilation speed, or `None` when no speed is set and the unit follows its schedule (auto mode).
|
|
53
58
|
- `async set_speed(speed)`: Set the ventilation speed. (away / low / medium / high)
|
|
54
59
|
- `async get_bypass()`: Get the bypass mode.
|
|
55
60
|
- `async set_bypass(mode, timeout=-1)`: Set the bypass mode. (auto / on / off)
|
|
56
61
|
- `async get_balance_mode()`: Get the balance mode.
|
|
57
62
|
- `async set_balance_mode(mode, timeout=-1)`: Set the balance mode. (balance / supply only / exhaust only)
|
|
58
63
|
- `async get_boost()`: Get the boost mode.
|
|
59
|
-
- `async set_boost(mode, timeout
|
|
64
|
+
- `async set_boost(mode, timeout=3600)`: Set the boost mode. (boolean)
|
|
60
65
|
- `async get_away()`: Get the away mode.
|
|
61
|
-
- `async set_away(mode, timeout
|
|
62
|
-
- `async get_temperature_profile()`: Get the temperature profile.
|
|
66
|
+
- `async set_away(mode, timeout=3600)`: Set the away mode. (boolean)
|
|
67
|
+
- `async get_temperature_profile()`: Get the temperature profile, or `None` when no profile is set and the unit follows its schedule.
|
|
63
68
|
- `async set_temperature_profile(profile)`: Set the temperature profile. (warm / normal / cool)
|
|
64
|
-
- `async
|
|
65
|
-
- `async
|
|
66
|
-
-
|
|
67
|
-
-
|
|
68
|
-
- `
|
|
69
|
-
- `async
|
|
70
|
-
- `async get_property(prop)`: Get the value of a property, e.g. `PROPERTY_RMOT_HEATING_THRESHOLD`.
|
|
71
|
-
- `async get_property_constraints(prop)`: Get the raw value of a numeric property, together with the range and step size the unit accepts.
|
|
69
|
+
- `async get_property(prop, node_id=None)`: Get the value of a property, e.g. `PROPERTY_RMOT_HEATING_THRESHOLD`. It is read from the node the property lives on: the ventilation unit, or the ComfoClime for the `PROPERTY_CLIME_*` properties. Pass `node_id` to read it from another node. A `NodeNotFoundException` is raised when the node isn't on the bus.
|
|
70
|
+
- `async set_property(prop, value, node_id=None)`: Set a property, on the same node as `get_property`.
|
|
71
|
+
- The airflow in m³/h of each fan speed is a property: `PROPERTY_FLOW_AWAY`, `PROPERTY_FLOW_LOW`, `PROPERTY_FLOW_MEDIUM` and `PROPERTY_FLOW_HIGH`, e.g. `await comfoconnect.set_property(PROPERTY_FLOW_LOW, 120)`.
|
|
72
|
+
- Properties that are an enum, like `PROPERTY_SENSOR_VENTILATION_TEMP_PASSIVE`, `PROPERTY_SENSOR_VENTILATION_HUMIDITY_COMFORT` and `PROPERTY_SENSOR_VENTILATION_HUMIDITY_PROTECTION` (off / auto / on), `PROPERTY_TEMPERATURE_PROFILE_MODE` (adaptive / fixed), `PROPERTY_CLIME_SEASON` and `PROPERTY_CLIME_TEMPERATURE_PROFILE`, have `options`: `get_property` returns the option and `set_property` takes it. `get_property_constraints` still uses the raw values.
|
|
73
|
+
- Temperatures in tenths of a degree, like `PROPERTY_RMOT_HEATING_THRESHOLD`, `PROPERTY_PROFILE_TEMPERATURE_NORMAL` and the ComfoClime temperatures, have `scale=0.1`: `get_property` and `get_property_constraints` return °C (215 becomes 21.5) and `set_property` takes °C.
|
|
74
|
+
- `async get_property_constraints(prop, node_id=None)`: Get the value of a numeric property, together with the range and step size the unit accepts.
|
|
72
75
|
- `bridge_type`: The type of the bridge (`GatewayType.LANC`, `SEASON` or `PRO`). Discovery reports it, and a ComfoConnect Pro is also recognised once a session has started.
|
|
73
76
|
|
|
74
77
|
### Low-level API
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
"""aiocomfoconnect CLI application"""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import asyncio
|
|
7
|
+
import logging
|
|
8
|
+
import sys
|
|
9
|
+
from contextlib import asynccontextmanager
|
|
10
|
+
from typing import AsyncIterator
|
|
11
|
+
|
|
12
|
+
from aiocomfoconnect import DEFAULT_NAME, DEFAULT_PIN, DEFAULT_UUID
|
|
13
|
+
from aiocomfoconnect.comfoconnect import ComfoConnect
|
|
14
|
+
from aiocomfoconnect.const import ProductId
|
|
15
|
+
from aiocomfoconnect.discovery import discover_bridges
|
|
16
|
+
from aiocomfoconnect.exceptions import BridgeNotFoundException, ComfoConnectNotAllowed
|
|
17
|
+
from aiocomfoconnect.properties import Property
|
|
18
|
+
from aiocomfoconnect.sensors import SENSORS
|
|
19
|
+
|
|
20
|
+
_LOGGER = logging.getLogger(__name__)
|
|
21
|
+
|
|
22
|
+
PRODUCT_NAMES = {value: name.lower() for name, value in vars(ProductId).items() if not name.startswith("_")}
|
|
23
|
+
|
|
24
|
+
# How long show-sensor waits for the first value. The bridge only reports a sensor after the sensor hold (5 seconds by default).
|
|
25
|
+
SENSOR_VALUE_TIMEOUT = 30
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class CliError(Exception):
|
|
29
|
+
"""An error that is shown to the user without a traceback."""
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
@asynccontextmanager
|
|
33
|
+
async def connected(args, *, connect: bool = True, **kwargs) -> AsyncIterator[ComfoConnect]:
|
|
34
|
+
"""Discover the bridge, connect to it and always disconnect afterwards.
|
|
35
|
+
|
|
36
|
+
The disconnect also happens when the command fails or is cancelled (Ctrl-C).
|
|
37
|
+
With connect=False, the caller opens the session itself (eg. by registering).
|
|
38
|
+
"""
|
|
39
|
+
bridges = await discover_bridges(args.host)
|
|
40
|
+
if not bridges:
|
|
41
|
+
raise BridgeNotFoundException("No bridge found")
|
|
42
|
+
|
|
43
|
+
comfoconnect = ComfoConnect(bridges[0].host, bridges[0].uuid, bridge_type=bridges[0].bridge_type, **kwargs)
|
|
44
|
+
try:
|
|
45
|
+
if connect:
|
|
46
|
+
try:
|
|
47
|
+
await comfoconnect.connect(args.uuid)
|
|
48
|
+
except ComfoConnectNotAllowed as exc:
|
|
49
|
+
raise CliError("Could not connect to bridge. Please register first.") from exc
|
|
50
|
+
yield comfoconnect
|
|
51
|
+
finally:
|
|
52
|
+
await comfoconnect.disconnect()
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
async def follow():
|
|
56
|
+
"""Keep receiving updates until cancelled (Ctrl-C). The library keeps the connection alive, and reconnects."""
|
|
57
|
+
await asyncio.Event().wait()
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
async def print_registered_apps(comfoconnect: ComfoConnect):
|
|
61
|
+
"""Print the apps that are registered on the bridge."""
|
|
62
|
+
print()
|
|
63
|
+
print("Registered applications:")
|
|
64
|
+
reply = await comfoconnect.cmd_list_registered_apps()
|
|
65
|
+
for app in reply.apps:
|
|
66
|
+
print(f"* {app.uuid.hex()}: {app.devicename}")
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
async def run_discover(args):
|
|
70
|
+
"""Discover all bridges on the network."""
|
|
71
|
+
bridges = await discover_bridges(args.host, broadcast_addresses=args.broadcast)
|
|
72
|
+
print("Discovered bridges:")
|
|
73
|
+
for bridge in bridges:
|
|
74
|
+
print(bridge)
|
|
75
|
+
print()
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
async def run_register(args):
|
|
79
|
+
"""Register an app on the bridge."""
|
|
80
|
+
async with connected(args, connect=False) as comfoconnect:
|
|
81
|
+
try:
|
|
82
|
+
registered = await comfoconnect.register(args.uuid, args.name, args.pin)
|
|
83
|
+
except ComfoConnectNotAllowed as exc:
|
|
84
|
+
raise CliError("Registration failed. Please check the PIN.") from exc
|
|
85
|
+
|
|
86
|
+
if registered:
|
|
87
|
+
print(f"UUID {args.uuid} is now registered.")
|
|
88
|
+
else:
|
|
89
|
+
print(f"UUID {args.uuid} is already registered.")
|
|
90
|
+
|
|
91
|
+
await print_registered_apps(comfoconnect)
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
async def run_deregister(args):
|
|
95
|
+
"""Deregister an app on the bridge, or list the registered apps when no UUID is given."""
|
|
96
|
+
if args.uuid2 and args.uuid2.lower() == args.uuid.lower():
|
|
97
|
+
raise CliError("You can't deregister the UUID you are connecting with. Use --uuid to connect with another registered UUID.")
|
|
98
|
+
|
|
99
|
+
async with connected(args) as comfoconnect:
|
|
100
|
+
if args.uuid2:
|
|
101
|
+
await comfoconnect.cmd_deregister_app(args.uuid2)
|
|
102
|
+
|
|
103
|
+
await print_registered_apps(comfoconnect)
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
async def run_set_speed(args):
|
|
107
|
+
"""Set ventilation speed."""
|
|
108
|
+
async with connected(args) as comfoconnect:
|
|
109
|
+
await comfoconnect.set_speed(args.speed)
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
async def run_set_mode(args):
|
|
113
|
+
"""Set ventilation mode."""
|
|
114
|
+
async with connected(args) as comfoconnect:
|
|
115
|
+
await comfoconnect.set_mode(args.mode)
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
async def run_set_comfocool(args):
|
|
119
|
+
"""Set comfocool mode."""
|
|
120
|
+
async with connected(args) as comfoconnect:
|
|
121
|
+
await comfoconnect.set_comfocool_mode(args.mode)
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
async def run_set_boost(args):
|
|
125
|
+
"""Set boost."""
|
|
126
|
+
async with connected(args) as comfoconnect:
|
|
127
|
+
await comfoconnect.set_boost(args.mode == "on", args.timeout)
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
async def run_show_sensors(args):
|
|
131
|
+
"""Show all sensors."""
|
|
132
|
+
|
|
133
|
+
def alarm_callback(node_id, errors):
|
|
134
|
+
"""Print alarm updates."""
|
|
135
|
+
print(f"Alarm received for Node {node_id}:")
|
|
136
|
+
for error_id, error in errors.items():
|
|
137
|
+
print(f"* {error_id}: {error}")
|
|
138
|
+
|
|
139
|
+
def sensor_callback(sensor, value):
|
|
140
|
+
"""Print sensor updates."""
|
|
141
|
+
print(f"{sensor.name:>40}: {value} {sensor.unit or ''}")
|
|
142
|
+
|
|
143
|
+
async with connected(args, sensor_callback=sensor_callback, alarm_callback=alarm_callback) as comfoconnect:
|
|
144
|
+
for sensor in SENSORS.values():
|
|
145
|
+
await comfoconnect.register_sensor(sensor)
|
|
146
|
+
|
|
147
|
+
await follow()
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
async def run_show_sensor(args):
|
|
151
|
+
"""Show a sensor."""
|
|
152
|
+
if args.sensor not in SENSORS:
|
|
153
|
+
raise CliError(f"Unknown sensor with ID {args.sensor}")
|
|
154
|
+
|
|
155
|
+
result = asyncio.get_running_loop().create_future()
|
|
156
|
+
|
|
157
|
+
def sensor_callback(sensor_, value):
|
|
158
|
+
"""Print sensor update."""
|
|
159
|
+
print(value)
|
|
160
|
+
if not result.done():
|
|
161
|
+
result.set_result(value)
|
|
162
|
+
|
|
163
|
+
async with connected(args, sensor_callback=sensor_callback) as comfoconnect:
|
|
164
|
+
await comfoconnect.register_sensor(SENSORS[args.sensor])
|
|
165
|
+
|
|
166
|
+
try:
|
|
167
|
+
await asyncio.wait_for(result, SENSOR_VALUE_TIMEOUT)
|
|
168
|
+
except asyncio.TimeoutError as exc:
|
|
169
|
+
raise CliError(f"No value received for sensor {args.sensor} within {SENSOR_VALUE_TIMEOUT} seconds") from exc
|
|
170
|
+
|
|
171
|
+
if args.follow:
|
|
172
|
+
await follow()
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
async def run_get_property(args):
|
|
176
|
+
"""Get a property."""
|
|
177
|
+
async with connected(args) as comfoconnect:
|
|
178
|
+
print(await comfoconnect.get_property(Property(args.unit, args.subunit, args.property_id, args.property_type), args.node_id))
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
async def run_set_property(args):
|
|
182
|
+
"""Set a property and print the value that is read back."""
|
|
183
|
+
async with connected(args) as comfoconnect:
|
|
184
|
+
prop = Property(args.unit, args.subunit, args.property_id, args.property_type)
|
|
185
|
+
await comfoconnect.set_property(prop, args.value, node_id=args.node_id)
|
|
186
|
+
print(await comfoconnect.get_property(prop, args.node_id))
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
async def run_list_nodes(args):
|
|
190
|
+
"""List the nodes that the bridge sees on the ComfoNet bus."""
|
|
191
|
+
async with connected(args) as comfoconnect:
|
|
192
|
+
await comfoconnect.cmd_node_request()
|
|
193
|
+
# Nodes arrive as unsolicited notifications, so give the bridge a moment to report them all.
|
|
194
|
+
await asyncio.sleep(2)
|
|
195
|
+
|
|
196
|
+
print("Nodes on the ComfoNet bus:")
|
|
197
|
+
for node in sorted(comfoconnect.nodes.values(), key=lambda n: n.node_id):
|
|
198
|
+
product = PRODUCT_NAMES.get(node.product_id, "unknown")
|
|
199
|
+
print(f"* node {node.node_id}: product {node.product_id} ({product}), zone {node.zone_id}, mode {node.mode}")
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
203
|
+
"""Build the argument parser."""
|
|
204
|
+
parser = argparse.ArgumentParser()
|
|
205
|
+
parser.add_argument("--debug", "-d", help="Enable debug logging", default=False, action="store_true")
|
|
206
|
+
subparsers = parser.add_subparsers(required=True, dest="action")
|
|
207
|
+
|
|
208
|
+
# Arguments that every command that connects to the bridge accepts.
|
|
209
|
+
bridge = argparse.ArgumentParser(add_help=False)
|
|
210
|
+
bridge.add_argument("--host", help="Host address of the bridge")
|
|
211
|
+
bridge.add_argument("--uuid", help="UUID of this app", default=DEFAULT_UUID)
|
|
212
|
+
|
|
213
|
+
p_discover = subparsers.add_parser("discover", help="discover ComfoConnect LAN C devices on your network")
|
|
214
|
+
p_discover.add_argument("--host", help="Host address of the bridge")
|
|
215
|
+
p_discover.add_argument("--broadcast", help="Broadcast address to search (eg. 192.168.1.255), can be repeated", action="append")
|
|
216
|
+
p_discover.set_defaults(func=run_discover)
|
|
217
|
+
|
|
218
|
+
p_register = subparsers.add_parser("register", parents=[bridge], help="register on a ComfoConnect LAN C device")
|
|
219
|
+
p_register.add_argument("--pin", help="PIN code to register on the bridge", type=int, default=DEFAULT_PIN)
|
|
220
|
+
p_register.add_argument("--name", help="Name of this app", default=DEFAULT_NAME)
|
|
221
|
+
p_register.set_defaults(func=run_register)
|
|
222
|
+
|
|
223
|
+
p_deregister = subparsers.add_parser("deregister", parents=[bridge], help="deregister an app on a ComfoConnect LAN C device, or list the registered apps")
|
|
224
|
+
p_deregister.add_argument("uuid2", help="UUID of the app to deregister (omit to only list the registered apps)", nargs="?", default=None)
|
|
225
|
+
# Deregistering doesn't need a PIN. Still accepted so existing scripts keep working.
|
|
226
|
+
p_deregister.add_argument("--pin", help=argparse.SUPPRESS, type=int, default=DEFAULT_PIN)
|
|
227
|
+
p_deregister.set_defaults(func=run_deregister)
|
|
228
|
+
|
|
229
|
+
p_set_speed = subparsers.add_parser("set-speed", parents=[bridge], help="set the fan speed")
|
|
230
|
+
p_set_speed.add_argument("speed", help="Fan speed", choices=["low", "medium", "high", "away"])
|
|
231
|
+
p_set_speed.set_defaults(func=run_set_speed)
|
|
232
|
+
|
|
233
|
+
p_set_mode = subparsers.add_parser("set-mode", parents=[bridge], help="set operation mode")
|
|
234
|
+
p_set_mode.add_argument("mode", help="Operation mode", choices=["auto", "manual"])
|
|
235
|
+
p_set_mode.set_defaults(func=run_set_mode)
|
|
236
|
+
|
|
237
|
+
p_set_comfocool = subparsers.add_parser("set-comfocool", parents=[bridge], help="set comfocool mode")
|
|
238
|
+
p_set_comfocool.add_argument("mode", help="Comfocool mode", choices=["auto", "off"])
|
|
239
|
+
p_set_comfocool.set_defaults(func=run_set_comfocool)
|
|
240
|
+
|
|
241
|
+
p_set_boost = subparsers.add_parser("set-boost", parents=[bridge], help="trigger or cancel a boost")
|
|
242
|
+
p_set_boost.add_argument("mode", help="Boost mode", choices=["on", "off"])
|
|
243
|
+
p_set_boost.add_argument("--timeout", "-t", help="Timeout in seconds (default: %(default)s)", type=int, default=3600)
|
|
244
|
+
p_set_boost.set_defaults(func=run_set_boost)
|
|
245
|
+
|
|
246
|
+
p_sensors = subparsers.add_parser("show-sensors", parents=[bridge], help="show the sensor values")
|
|
247
|
+
p_sensors.set_defaults(func=run_show_sensors)
|
|
248
|
+
|
|
249
|
+
p_sensor = subparsers.add_parser("show-sensor", parents=[bridge], help="show a single sensor value")
|
|
250
|
+
p_sensor.add_argument("sensor", help="The ID of the sensor", type=int)
|
|
251
|
+
p_sensor.add_argument("--follow", "-f", help="Follow", default=False, action="store_true")
|
|
252
|
+
p_sensor.set_defaults(func=run_show_sensor)
|
|
253
|
+
|
|
254
|
+
p_get_property = subparsers.add_parser("get-property", parents=[bridge], help="show a property value")
|
|
255
|
+
p_get_property.add_argument("unit", help="The Unit of the property", type=int)
|
|
256
|
+
p_get_property.add_argument("subunit", help="The Subunit of the property", type=int)
|
|
257
|
+
p_get_property.add_argument("property_id", help="The id of the property", type=int)
|
|
258
|
+
p_get_property.add_argument("property_type", help="The type of the property (default: %(default)s, a string)", type=int, nargs="?", default=0x09)
|
|
259
|
+
p_get_property.add_argument("--node_id", help="The Node ID of the query (defaults to the discovered ventilation unit)", type=int, default=None)
|
|
260
|
+
p_get_property.set_defaults(func=run_get_property)
|
|
261
|
+
|
|
262
|
+
p_set_property = subparsers.add_parser("set-property", parents=[bridge], help="set a property value")
|
|
263
|
+
p_set_property.add_argument("unit", help="The Unit of the property", type=int)
|
|
264
|
+
p_set_property.add_argument("subunit", help="The Subunit of the property", type=int)
|
|
265
|
+
p_set_property.add_argument("property_id", help="The id of the property", type=int)
|
|
266
|
+
p_set_property.add_argument("property_type", help="The type of the property", type=int)
|
|
267
|
+
p_set_property.add_argument("value", help="The raw value to write", type=int)
|
|
268
|
+
p_set_property.add_argument("--node_id", help="The Node ID to write to (defaults to the discovered ventilation unit)", type=int, default=None)
|
|
269
|
+
p_set_property.set_defaults(func=run_set_property)
|
|
270
|
+
|
|
271
|
+
p_list_nodes = subparsers.add_parser("list-nodes", parents=[bridge], help="list the nodes on the ComfoNet bus")
|
|
272
|
+
p_list_nodes.set_defaults(func=run_list_nodes)
|
|
273
|
+
|
|
274
|
+
return parser
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
def main_cli(argv=None):
|
|
278
|
+
"""Parse arguments and start async event loop."""
|
|
279
|
+
arguments = build_parser().parse_args(argv)
|
|
280
|
+
|
|
281
|
+
if arguments.debug:
|
|
282
|
+
logging.basicConfig(level=logging.DEBUG)
|
|
283
|
+
else:
|
|
284
|
+
logging.basicConfig(level=logging.WARNING)
|
|
285
|
+
|
|
286
|
+
try:
|
|
287
|
+
asyncio.run(arguments.func(arguments), debug=arguments.debug)
|
|
288
|
+
except KeyboardInterrupt:
|
|
289
|
+
pass
|
|
290
|
+
except (BridgeNotFoundException, CliError) as exc:
|
|
291
|
+
print(f"Error: {exc}", file=sys.stderr)
|
|
292
|
+
sys.exit(1)
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
if __name__ == "__main__":
|
|
296
|
+
main_cli()
|