Skip to content

Commit f40fca6

Browse files
feat: add heater support (#835)
* init heater support * refactoring * heater continue * heater continue * Update __init__.py and test_device_enum_helpers.py * Update __init__.py * Update bridge.py, test_device_dataclasses.py, test_udp_datagram_parsing.py, and 2 more files * refactoring * refactoring and support turn on and off for heater * refactoring and add tests * refactoring and add tests * refactoring * add get_heater_state with tests * fix linting * Update messages.py * Update supported.md and get_heater_state_response.txt * Update scripts.md * Update scripts.md * Update usage_api.md * Update messages.py * Update bridge.py and __init__.py * Update test_device_dataclasses.py and test_a_heater_datagram_produces_device.txt * fix based on requested changes * fix based on CodeRabbit * fix tests * Update control_device.py, test_api_tcp_client.py, test_datagram_state_off_heater.txt, and 1 more file * Update scripts.md and test_api_tcp_client.py * Update control_device.py * Update test_udp_datagram_parsing.py * fix tests * Update test_udp_datagram_parsing.py * Update test_udp_datagram_parsing.py * Update scripts.md and control_device.py * Update docs/supported.md Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com> Signed-off-by: YogevBokobza <[email protected]> * Update docs/usage_api.md Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com> Signed-off-by: YogevBokobza <[email protected]> --------- Signed-off-by: YogevBokobza <[email protected]> Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
1 parent f087f18 commit f40fca6

19 files changed

+481
-50
lines changed

.github/ISSUE_TEMPLATE/bug_report.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ body:
4646
- Switcher Light SL02
4747
- Switcher Light SL02 Mini
4848
- Switcher Light SL03
49+
- Switcher Heater
4950
validations:
5051
required: true
5152

docs/scripts.md

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ options:
170170
-c DEVICE_TYPE, --device-type DEVICE_TYPE
171171
the type of the device
172172
-k TOKEN, --token TOKEN
173-
the token for communicating with the new switcher devices
173+
the token for communicating with switcher token-based devices
174174
-d DEVICE_ID, --device-id DEVICE_ID
175175
the identification of the device
176176
-l DEVICE_KEY, --device-key DEVICE_KEY
@@ -245,7 +245,7 @@ options:
245245
-c DEVICE_TYPE, --device-type DEVICE_TYPE
246246
the type of the device
247247
-k TOKEN, --token TOKEN
248-
the token for communicating with the new switcher devices
248+
the token for communicating with switcher token-based devices
249249
-d DEVICE_ID, --device-id DEVICE_ID
250250
the identification of the device
251251
-l DEVICE_KEY, --device-key DEVICE_KEY
@@ -385,7 +385,7 @@ options:
385385
-c DEVICE_TYPE, --device-type DEVICE_TYPE
386386
the type of the device
387387
-k TOKEN, --token TOKEN
388-
the token for communicating with the new switcher devices
388+
the token for communicating with switcher token-based devices
389389
-d DEVICE_ID, --device-id DEVICE_ID
390390
the identification of the device
391391
-l DEVICE_KEY, --device-key DEVICE_KEY
@@ -423,7 +423,7 @@ options:
423423
-c DEVICE_TYPE, --device-type DEVICE_TYPE
424424
the type of the device
425425
-k TOKEN, --token TOKEN
426-
the token for communicating with the new switcher devices
426+
the token for communicating with switcher token-based devices
427427
-d DEVICE_ID, --device-id DEVICE_ID
428428
the identification of the device
429429
-l DEVICE_KEY, --device-key DEVICE_KEY
@@ -451,13 +451,15 @@ python control_device.py stop_shutter -c "runners12" -k "zvVvd7JxtN7CgvkD1Psujw=
451451
```shell title="scripts/control_device.py turn_off"
452452
$ poetry run control_device turn_off --help
453453

454-
usage: control_device.py turn_off [-h] [-v] -c DEVICE_TYPE -d DEVICE_ID [-l DEVICE_KEY] -i IP_ADDRESS
454+
usage: control_device.py turn_off [-h] [-v] -c DEVICE_TYPE [-k TOKEN] -d DEVICE_ID [-l DEVICE_KEY] -i IP_ADDRESS
455455

456456
options:
457457
-h, --help show this help message and exit
458458
-v, --verbose include the raw message
459459
-c DEVICE_TYPE, --device-type DEVICE_TYPE
460460
the type of the device
461+
-k TOKEN, --token TOKEN
462+
the token for communicating with switcher token-based devices
461463
-d DEVICE_ID, --device-id DEVICE_ID
462464
the identification of the device
463465
-l DEVICE_KEY, --device-key DEVICE_KEY
@@ -470,21 +472,25 @@ example usage:
470472
python control_device.py turn_off -c "touch" -d ab1c2d -i "111.222.11.22"
471473

472474
python control_device.py turn_off -c "touch" -d ab1c2d -l 18 -i "111.222.11.22"
475+
476+
python control_device.py turn_off -c "heater" -k "zvVvd7JxtN7CgvkD1Psujw==" -d f2239a -l 18 -i "192.168.50.98"
473477
```
474478

475479
### Turn on
476480

477481
```shell title="scripts/control_device.py turn_on"
478482
$ poetry run control_device turn_on --help
479483

480-
usage: control_device.py turn_on [-h] [-v] -c DEVICE_TYPE -d DEVICE_ID [-l DEVICE_KEY] -i IP_ADDRESS
484+
usage: control_device.py turn_on [-h] [-v] -c DEVICE_TYPE [-k TOKEN] -d DEVICE_ID [-l DEVICE_KEY] -i IP_ADDRESS
481485
[-t [TIMER]]
482486

483487
options:
484488
-h, --help show this help message and exit
485489
-v, --verbose include the raw message
486490
-c DEVICE_TYPE, --device-type DEVICE_TYPE
487491
the type of the device
492+
-k TOKEN, --token TOKEN
493+
the token for communicating with switcher token-based devices
488494
-d DEVICE_ID, --device-id DEVICE_ID
489495
the identification of the device
490496
-l DEVICE_KEY, --device-key DEVICE_KEY
@@ -501,6 +507,10 @@ python control_device.py turn_on -c "touch" -d ab1c2d -i "111.222.11.22"
501507
python control_device.py turn_on -c "touch" -d ab1c2d -l 18 -i "111.222.11.22"
502508

503509
python control_device.py turn_on -c "touch" -d ab1c2d -i "111.222.11.22" -t 15
510+
511+
python control_device.py turn_on -c "heater" -k "zvVvd7JxtN7CgvkD1Psujw==" -d f2239a -l 18 -i "192.168.50.98"
512+
513+
python control_device.py turn_on -c "heater" -k "zvVvd7JxtN7CgvkD1Psujw==" -d f2239a -l 18 -i "192.168.50.98" -t 15
504514
```
505515

506516
### Turn off light
@@ -516,7 +526,7 @@ options:
516526
-c DEVICE_TYPE, --device-type DEVICE_TYPE
517527
the type of the device
518528
-k TOKEN, --token TOKEN
519-
the token for communicating with the new switcher devices
529+
the token for communicating with switcher token-based devices
520530
-d DEVICE_ID, --device-id DEVICE_ID
521531
the identification of the device
522532
-l DEVICE_KEY, --device-key DEVICE_KEY
@@ -566,7 +576,7 @@ options:
566576
-c DEVICE_TYPE, --device-type DEVICE_TYPE
567577
the type of the device
568578
-k TOKEN, --token TOKEN
569-
the token for communicating with the new switcher devices
579+
the token for communicating with switcher token-based devices
570580
-d DEVICE_ID, --device-id DEVICE_ID
571581
the identification of the device
572582
-l DEVICE_KEY, --device-key DEVICE_KEY
@@ -616,7 +626,7 @@ options:
616626
-c DEVICE_TYPE, --device-type DEVICE_TYPE
617627
the type of the device
618628
-k TOKEN, --token TOKEN
619-
the token for communicating with the new switcher devices
629+
the token for communicating with switcher token-based devices
620630
-d DEVICE_ID, --device-id DEVICE_ID
621631
the identification of the device
622632
-l DEVICE_KEY, --device-key DEVICE_KEY
@@ -652,7 +662,7 @@ options:
652662
-c DEVICE_TYPE, --device-type DEVICE_TYPE
653663
the type of the device
654664
-k TOKEN, --token TOKEN
655-
the token for communicating with the new switcher devices
665+
the token for communicating with switcher token-based devices
656666
-d DEVICE_ID, --device-id DEVICE_ID
657667
the identification of the device
658668
-l DEVICE_KEY, --device-key DEVICE_KEY
@@ -675,6 +685,32 @@ python control_device.py turn_on_shutter_child_lock -c "runners11" -k "zvVvd7Jxt
675685
python control_device.py turn_on_shutter_child_lock -c "runners12" -k "zvVvd7JxtN7CgvkD1Psujw==" -d ab1c2d -i "111.222.11.22"
676686
```
677687

688+
### Get heater state
689+
690+
```shell title="scripts/control_device.py get_heater_state"
691+
$ poetry run control_device get_heater_state --help
692+
693+
usage: control_device.py get_heater_state [-h] [-v] -c DEVICE_TYPE [-k TOKEN] -d DEVICE_ID [-l DEVICE_KEY] -i IP_ADDRESS
694+
695+
options:
696+
-h, --help show this help message and exit
697+
-v, --verbose include the raw message
698+
-c DEVICE_TYPE, --device-type DEVICE_TYPE
699+
the type of the device
700+
-k TOKEN, --token TOKEN
701+
the token for communicating with switcher token-based devices
702+
-d DEVICE_ID, --device-id DEVICE_ID
703+
the identification of the device
704+
-l DEVICE_KEY, --device-key DEVICE_KEY
705+
the login key of the device
706+
-i IP_ADDRESS, --ip-address IP_ADDRESS
707+
the ip address assigned to the device
708+
709+
example usage:
710+
711+
python control_device.py get_heater_state -c "heater" -k "zvVvd7JxtN7CgvkD1Psujw==" -d f2239a -i "192.168.50.98"
712+
```
713+
678714
## Discover devices
679715

680716
Use to discover devices and their states.

docs/supported.md

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
1-
| Name | Link | Included from version |
2-
|--------------------------|:-----------------------------------:|:---------------------:|
3-
| Switcher V2 | [product][switcher-v2] | 1.x.x |
4-
| Switcher Mini | [product][switcher-mini] | 1.x.x |
5-
| Switcher Touch (V3) | [product][switcher-touch] | 1.x.x |
6-
| Switcher V4 | [product][switcher-v4] | 1.x.x |
7-
| Switcher Power Plug | [product][switcher-power-plug] | 2.x.x |
8-
| Switcher Breeze | [product][switcher-breeze] | 3.x.x |
9-
| Switcher Runner | [product][switcher-runner] | 3.x.x |
10-
| Switcher Runner Mini | [product][switcher-runner-mini] | 3.x.x |
11-
| Switcher Runner S11 | [product][switcher-runner-s11] | 4.x.x |
12-
| Switcher Runner S12 | [product][switcher-runner-s12] | 4.1.x |
13-
| Switcher Light SL01 | [product][switcher-light-sl01] | 4.2.x |
14-
| Switcher Light SL01 Mini | [product][switcher-light-sl01-mini] | 4.2.x |
15-
| Switcher Light SL02 | [product][switcher-light-sl02] | 4.3.x |
16-
| Switcher Light SL02 Mini | [product][switcher-light-sl02-mini] | 4.3.x |
17-
| Switcher Light SL03 | [product][switcher-light-sl03] | 4.4.x |
1+
| Name | Link | Included from version | Requires token |
2+
|--------------------------|:-----------------------------------:|:---------------------:|:------------------:|
3+
| Switcher V2 | [product][switcher-v2] | 1.x.x | No |
4+
| Switcher Mini | [product][switcher-mini] | 1.x.x | No |
5+
| Switcher Touch (V3) | [product][switcher-touch] | 1.x.x | No |
6+
| Switcher V4 | [product][switcher-v4] | 1.x.x | No |
7+
| Switcher Power Plug | [product][switcher-power-plug] | 2.x.x | No |
8+
| Switcher Breeze | [product][switcher-breeze] | 3.x.x | No |
9+
| Switcher Runner | [product][switcher-runner] | 3.x.x | No |
10+
| Switcher Runner Mini | [product][switcher-runner-mini] | 3.x.x | No |
11+
| Switcher Runner S11 | [product][switcher-runner-s11] | 4.x.x | Yes |
12+
| Switcher Runner S12 | [product][switcher-runner-s12] | 4.1.x | Yes |
13+
| Switcher Light SL01 | [product][switcher-light-sl01] | 4.2.x | Yes |
14+
| Switcher Light SL01 Mini | [product][switcher-light-sl01-mini] | 4.2.x | Yes |
15+
| Switcher Light SL02 | [product][switcher-light-sl02] | 4.3.x | Yes |
16+
| Switcher Light SL02 Mini | [product][switcher-light-sl02-mini] | 4.3.x | Yes |
17+
| Switcher Light SL03 | [product][switcher-light-sl03] | 4.4.x | Yes |
18+
| Switcher Heater | [product][switcher-heater] | 6.x.x | Yes |
1819

1920
!!!note
2021
Newer Switcher devices, such as Runner S11, require a token. Get yours at: https://switcher.co.il/GetKey
@@ -34,3 +35,4 @@
3435
[switcher-light-sl02]: https://switcher.co.il/%D7%9E%D7%95%D7%A6%D7%A8/switcher-light-sl02/
3536
[switcher-light-sl02-mini]: https://switcher.co.il/%D7%9E%D7%95%D7%A6%D7%A8/switcher-light-slmini02/
3637
[switcher-light-sl03]: https://switcher.co.il/%D7%9E%D7%95%D7%A6%D7%A8/switcher-light-sl03/
38+
[switcher-heater]: https://switcher.co.il/%D7%9E%D7%95%D7%A6%D7%A8/switcher-heater/

docs/usage_api.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,23 @@ asyncio.run(control_light(DeviceType.LIGHT_SL02, "111.222.11.22", "ab1c2d", "00"
141141
asyncio.run(control_light(DeviceType.LIGHT_SL02_MINI, "111.222.11.22", "ab1c2d", "00", "zvVvd7JxtN7CgvkD1Psujw=="))
142142
asyncio.run(control_light(DeviceType.LIGHT_SL03, "111.222.11.22", "ab1c2d", "00", "zvVvd7JxtN7CgvkD1Psujw=="))
143143
```
144+
145+
## Heater excerpt
146+
147+
```python
148+
import asyncio
149+
from aioswitcher.api import Command, SwitcherApi
150+
from aioswitcher.device import DeviceType
151+
152+
async def control_heater(device_type, device_ip, device_id, device_key, token) :
153+
# for connecting to a device we need its type, id, login key, ip address and token
154+
async with SwitcherApi(device_type, device_ip, device_id, device_key, token) as api:
155+
# get the device's current state
156+
await api.get_heater_state()
157+
# turn the device on for 15 minutes
158+
await api.control_device(Command.ON, 15)
159+
# turn the device off
160+
await api.control_device(Command.OFF)
161+
162+
asyncio.run(control_heater(DeviceType.HEATER, "111.222.11.22", "ab1c2d" , "00", "zvVvd7JxtN7CgvkD1Psujw=="))
163+
```

scripts/control_device.py

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
"light02": DeviceType.LIGHT_SL02,
5454
"light02mini": DeviceType.LIGHT_SL02_MINI,
5555
"light03": DeviceType.LIGHT_SL03,
56+
"heater": DeviceType.HEATER,
5657
}
5758

5859
# shared parse
@@ -78,7 +79,7 @@
7879
"--token",
7980
default=None,
8081
type=str,
81-
help="the token for communicating with the new switcher devices",
82+
help="the token for communicating with switcher token-based devices",
8283
)
8384
shared_parser.add_argument(
8485
"-d",
@@ -582,6 +583,18 @@
582583
help="the circuit number to turn on",
583584
)
584585

586+
# get_heater_state parser
587+
_get_heater_state_examples = """example usage:
588+
589+
poetry run control_device get_heater_state -c "heater" -k "zvVvd7JxtN7CgvkD1Psujw==" -d ab1c2d -i "111.222.11.22"\n """ # noqa E501
590+
subparsers.add_parser(
591+
"get_heater_state",
592+
help="get the current state of a heater device",
593+
epilog=_get_heater_state_examples,
594+
formatter_class=RawDescriptionHelpFormatter,
595+
parents=[shared_parser],
596+
)
597+
585598

586599
def asdict(dc: object, verbose: bool = False) -> Dict[str, Any]:
587600
"""Use as custom implementation of the asdict utility method."""
@@ -671,9 +684,10 @@ async def turn_on(
671684
device_ip: str,
672685
timer: int,
673686
verbose: bool,
687+
token: Union[str, None] = None,
674688
) -> None:
675689
"""Use to launch a turn_on request."""
676-
async with SwitcherApi(device_type, device_ip, device_id, device_key) as api:
690+
async with SwitcherApi(device_type, device_ip, device_id, device_key, token) as api:
677691
printer.pprint(asdict(await api.control_device(Command.ON, timer), verbose))
678692

679693

@@ -683,9 +697,10 @@ async def turn_off(
683697
device_key: str,
684698
device_ip: str,
685699
verbose: bool,
700+
token: Union[str, None] = None,
686701
) -> None:
687702
"""Use to launch a turn_off request."""
688-
async with SwitcherApi(device_type, device_ip, device_id, device_key) as api:
703+
async with SwitcherApi(device_type, device_ip, device_id, device_key, token) as api:
689704
printer.pprint(asdict(await api.control_device(Command.OFF), verbose))
690705

691706

@@ -889,6 +904,19 @@ async def turn_off_light(
889904
printer.pprint(asdict(await api.set_light(DeviceState.OFF, index), verbose))
890905

891906

907+
async def get_heater_state(
908+
device_type: DeviceType,
909+
device_id: str,
910+
device_key: str,
911+
device_ip: str,
912+
verbose: bool,
913+
token: Union[str, None] = None,
914+
) -> None:
915+
"""Use to launch a get_heater_state request."""
916+
async with SwitcherApi(device_type, device_ip, device_id, device_key, token) as api:
917+
printer.pprint(asdict(await api.get_heater_state(), verbose))
918+
919+
892920
def main() -> None:
893921
"""Run the device controller script."""
894922
try:
@@ -918,6 +946,7 @@ def main() -> None:
918946
args.ip_address,
919947
args.timer,
920948
args.verbose,
949+
args.token,
921950
)
922951
)
923952
elif args.action == "turn_off":
@@ -928,6 +957,7 @@ def main() -> None:
928957
args.device_key,
929958
args.ip_address,
930959
args.verbose,
960+
args.token,
931961
)
932962
)
933963
elif args.action == "set_name":
@@ -1123,6 +1153,18 @@ def main() -> None:
11231153
)
11241154
)
11251155

1156+
elif args.action == "get_heater_state":
1157+
asyncio.run(
1158+
get_heater_state(
1159+
device_type,
1160+
args.device_id,
1161+
args.device_key,
1162+
args.ip_address,
1163+
args.verbose,
1164+
args.token,
1165+
)
1166+
)
1167+
11261168
except KeyboardInterrupt:
11271169
exit()
11281170

0 commit comments

Comments
 (0)