Skip to content

Commit

Permalink
chore: added get_thermostat_state to the control_device script
Browse files Browse the repository at this point in the history
Signed-off-by: Tomer Figenblat <tomer.figenblat@gmail.com>
  • Loading branch information
TomerFi committed Sep 24, 2022
1 parent 97d9698 commit 4a925d0
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 11 deletions.
23 changes: 21 additions & 2 deletions docs/scripts.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Print only protocol type 2 devices:
```shell
usage: control_device.py [-h]
{control_thermostat,create_schedule,delete_schedule,get_schedules,get_state,set_auto_shutdown,set_name,set_shutter_position,stop_shutter,turn_off,turn_on}
{control_thermostat,create_schedule,delete_schedule,get_schedules,get_state,get_thermostat_state,set_auto_shutdown,set_name,set_shutter_position,stop_shutter,turn_off,turn_on}
...
Control your Switcher device
Expand All @@ -69,12 +69,14 @@ options:
subcommands:
supported actions
{control_thermostat,create_schedule,delete_schedule,get_schedules,get_state,set_auto_shutdown,set_name,set_shutter_position,stop_shutter,turn_off,turn_on}
{control_thermostat,create_schedule,delete_schedule,get_schedules,get_state,get_thermostat_state,set_auto_shutdown,set_name,set_shutter_position,stop_shutter,turn_off,turn_on}
control_thermostat control a breeze device
create_schedule create a new schedule
delete_schedule delete a device schedule
get_schedules retrieve a device schedules
get_state get the current state of a device
get_thermostat_state
get the current state a thermostat (breeze) device
set_auto_shutdown set the auto shutdown property (1h-24h)
set_name set the name of the device
set_shutter_position
Expand Down Expand Up @@ -109,6 +111,8 @@ python control_device.py -d f2239a -i "192.168.50.98" stop_shutter
python control_device.py -d f2239a -i "192.168.50.98" set_shutter_position -p 50
python control_device.py -d 3a20b7 -i "192.168.50.77" get_thermostat_state
python control_device.py -d 3a20b7 -i "192.168.50.77" control_thermostat -r ELEC7001 -s on
python control_device.py -d 3a20b7 -i "192.168.50.77" control_thermostat -r ELEC7001 -m cool -f high -t 24
Expand Down Expand Up @@ -216,6 +220,21 @@ options:
the ip address assigned to the device
```
### script/control_device.py get_thermostat_state
```shell
usage: control_device.py get_thermostat_state [-h] [-v] -d DEVICE_ID -i
IP_ADDRESS

options:
-h, --help show this help message and exit
-v, --verbose include the raw message
-d DEVICE_ID, --device-id DEVICE_ID
the identification of the device
-i IP_ADDRESS, --ip-address IP_ADDRESS
the ip address assigned to the device
```
### script/control_device.py set_auto_shutdown
```shell
Expand Down
48 changes: 39 additions & 9 deletions scripts/control_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
python control_device.py -d f2239a -i "192.168.50.98" stop_shutter\n
python control_device.py -d f2239a -i "192.168.50.98" set_shutter_position -p 50\n
python control_device.py -d 3a20b7 -i "192.168.50.77" get_thermostat_state\n
python control_device.py -d 3a20b7 -i "192.168.50.77" control_thermostat -r ELEC7001 -s on\n
python control_device.py -d 3a20b7 -i "192.168.50.77" control_thermostat -r ELEC7001 -m cool -f high -t 24\n
python control_device.py -d 3a20b7 -i "192.168.50.77" control_thermostat -r ELEC7001 -m dry\n
Expand Down Expand Up @@ -87,9 +89,7 @@
formatter_class=RawDescriptionHelpFormatter,
)

subparsers = main_parser.add_subparsers(
dest="action", description="supported actions"
)
subparsers = main_parser.add_subparsers(dest="action", description="supported actions")

# control_thermostat parser
control_thermostat_parser = subparsers.add_parser(
Expand Down Expand Up @@ -181,10 +181,21 @@
)

# get_schedules parser
subparsers.add_parser("get_schedules", help="retrieve a device schedules", parents=[shared_parser])
subparsers.add_parser(
"get_schedules", help="retrieve a device schedules", parents=[shared_parser]
)

# get_state parser
subparsers.add_parser("get_state", help="get the current state of a device", parents=[shared_parser])
subparsers.add_parser(
"get_state", help="get the current state of a device", parents=[shared_parser]
)

# get_thermostat_state parser
subparsers.add_parser(
"get_thermostat_state",
help="get the current state a thermostat (breeze) device",
parents=[shared_parser],
)

# set_auto_shutdown parser
set_auto_shutdown_parser = subparsers.add_parser(
Expand All @@ -209,7 +220,9 @@
)

# set_name parser
set_name_parser = subparsers.add_parser("set_name", help="set the name of the device", parents=[shared_parser])
set_name_parser = subparsers.add_parser(
"set_name", help="set the name of the device", parents=[shared_parser]
)
set_name_parser.add_argument(
"-n",
"--name",
Expand All @@ -233,13 +246,19 @@
)

# stop shutter parser
stop_shutter_parser = subparsers.add_parser("stop_shutter", help="stop shutter", parents=[shared_parser])
stop_shutter_parser = subparsers.add_parser(
"stop_shutter", help="stop shutter", parents=[shared_parser]
)

# turn_off parser
turn_on_parser = subparsers.add_parser("turn_off", help="turn off the device", parents=[shared_parser])
turn_on_parser = subparsers.add_parser(
"turn_off", help="turn off the device", parents=[shared_parser]
)

# turn_on parser
turn_on_parser = subparsers.add_parser("turn_on", help="turn on the device", parents=[shared_parser])
turn_on_parser = subparsers.add_parser(
"turn_on", help="turn on the device", parents=[shared_parser]
)
turn_on_parser.add_argument(
"-t",
"--timer",
Expand All @@ -249,6 +268,7 @@
help="set minutes timer for turn on operation",
)


def asdict(dc: object, verbose: bool = False) -> Dict[str, Any]:
"""Use as custom implementation of the asdict utility method."""
return {
Expand All @@ -258,6 +278,12 @@ def asdict(dc: object, verbose: bool = False) -> Dict[str, Any]:
}


async def get_thermostat_state(device_id: str, device_ip: str, verbose: bool) -> None:
"""Use to launch a get_breeze_state request."""
async with SwitcherType2Api(device_ip, device_id) as api:
printer.pprint(asdict(await api.get_breeze_state(), verbose))


async def get_state(device_id: str, device_ip: str, verbose: bool) -> None:
"""Use to launch a get_state request."""
async with SwitcherType1Api(device_ip, device_id) as api:
Expand Down Expand Up @@ -470,6 +496,10 @@ async def set_shutter_position(
args.verbose,
)
)
elif args.action == "get_thermostat_state":
get_event_loop().run_until_complete(
get_thermostat_state(args.device_id, args.ip_address, args.verbose)
)

except KeyboardInterrupt:
exit()

0 comments on commit 4a925d0

Please sign in to comment.