Skip to content

Commit cd2696a

Browse files
Merge pull request #9 from szymonkups/add-set-mode-to-cli
Add set mode to CLI
2 parents 383cb94 + 35be87d commit cd2696a

3 files changed

Lines changed: 32 additions & 3 deletions

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ $ python -m aiocomfoconnect register --host 192.168.1.213
2222

2323
$ python -m aiocomfoconnect set-speed away --host 192.168.1.213
2424
$ python -m aiocomfoconnect set-speed low --host 192.168.1.213
25+
$ python -m aiocomfoconnect set-mode auto --host 192.168.1.213
2526
$ python -m aiocomfoconnect set-speed medium --host 192.168.1.213
2627
$ python -m aiocomfoconnect set-speed high --host 192.168.1.213
2728

@@ -140,7 +141,7 @@ if __name__ == "__main__":
140141

141142
### Decode network traffic
142143

143-
You can use the `scripts/decode_pcap.py` file to decode network traffic between the Mobile App and the ComfoConnect LAN C.
144+
You can use the `scripts/decode_pcap.py` file to decode network traffic between the Mobile App and the ComfoConnect LAN C.
144145
Make sure that the first TCP session in the capture is the connection between the bridge and the app. It's therefore recommended to start the capture before you open the app.
145146

146147
```shell

aiocomfoconnect/__main__.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ async def main(args):
3232
elif args.action == "set-speed":
3333
await run_set_speed(args.host, args.uuid, args.speed)
3434

35+
elif args.action == "set-mode":
36+
await run_set_mode(args.host, args.uuid, args.mode)
37+
3538
elif args.action == "show-sensors":
3639
await run_show_sensors(args.host, args.uuid)
3740

@@ -110,6 +113,26 @@ async def run_set_speed(host: str, uuid: str, speed: Literal["away", "low", "med
110113
await comfoconnect.disconnect()
111114

112115

116+
async def run_set_mode(host: str, uuid: str, mode: Literal["auto", "manual"]):
117+
"""Connect to a bridge."""
118+
# Discover bridge so we know the UUID
119+
bridges = await discover_bridges(host)
120+
if not bridges:
121+
raise Exception("No bridge found")
122+
123+
# Connect to the bridge
124+
comfoconnect = ComfoConnect(bridges[0].host, bridges[0].uuid)
125+
try:
126+
await comfoconnect.connect(uuid)
127+
except ComfoConnectNotAllowed:
128+
print("Could not connect to bridge. Please register first.")
129+
sys.exit(1)
130+
131+
await comfoconnect.set_mode(mode)
132+
133+
await comfoconnect.disconnect()
134+
135+
113136
async def run_show_sensors(host: str, uuid: str):
114137
"""Connect to a bridge."""
115138
# Discover bridge so we know the UUID
@@ -217,6 +240,11 @@ def sensor_callback(sensor_, value):
217240
p_set_speed.add_argument("--host", help="Host address of the bridge")
218241
p_set_speed.add_argument("--uuid", help="UUID of this app", default=DEFAULT_UUID)
219242

243+
p_set_mode = subparsers.add_parser("set-mode", help="set operation mode")
244+
p_set_mode.add_argument("mode", help="Operation mode", choices=["auto", "manual"])
245+
p_set_mode.add_argument("--host", help="Host address of the bridge")
246+
p_set_mode.add_argument("--uuid", help="UUID of this app", default=DEFAULT_UUID)
247+
220248
p_sensors = subparsers.add_parser("show-sensors", help="show the sensor values")
221249
p_sensors.add_argument("--host", help="Host address of the bridge")
222250
p_sensors.add_argument("--uuid", help="UUID of this app", default=DEFAULT_UUID)

docs/PROTOCOL.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ indicates the length of the `op` field, the rest of the data contains the `msg`.
9191
| Field | Data | Remark |
9292
|-----------------------|--------------------------------------|-------------------------------------------------------|
9393
| length (32 bit) | `0x0000004f` | Length of the whole message excluding this field |
94-
| src (12 bytes) | `0xaf154804169043898d2da77148f886be` | |
95-
| dst (12 bytes) | `0x0000000000251010800170b3d54264b4` | |
94+
| src (16 bytes) | `0xaf154804169043898d2da77148f886be` | |
95+
| dst (16 bytes) | `0x0000000000251010800170b3d54264b4` | |
9696
| op_length (16 bit | `0x0004` | Length of the `op` message |
9797
| op (variable length) | `0x08342002` | Message with type `GatewayOperation` |
9898
| msg (variable length) | `...` | Message with type that is stated in `op.type` |

0 commit comments

Comments
 (0)