Skip to content

Commit

Permalink
chore: Avoid get_event_loop() deprecation warning in control_device.py
Browse files Browse the repository at this point in the history
Signed-off-by: thecode <levyshay1@gmail.com>
  • Loading branch information
thecode committed Oct 16, 2022
1 parent c1d411e commit 1f05dac
Showing 1 changed file with 13 additions and 19 deletions.
32 changes: 13 additions & 19 deletions scripts/control_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

"""Python script for controlling Switcher devices."""

import asyncio
from argparse import ArgumentParser, RawDescriptionHelpFormatter
from asyncio import get_event_loop
from datetime import timedelta
from pprint import PrettyPrinter
from typing import Any, Dict, List, Union
Expand Down Expand Up @@ -426,23 +426,19 @@ async def set_shutter_position(
args = main_parser.parse_args()

if args.action == "get_state":
get_event_loop().run_until_complete(
get_state(args.device_id, args.ip_address, args.verbose)
)
asyncio.run(get_state(args.device_id, args.ip_address, args.verbose))
elif args.action == "turn_on":
get_event_loop().run_until_complete(
asyncio.run(
turn_on(args.device_id, args.ip_address, args.timer, args.verbose)
)
elif args.action == "turn_off":
get_event_loop().run_until_complete(
turn_off(args.device_id, args.ip_address, args.verbose)
)
asyncio.run(turn_off(args.device_id, args.ip_address, args.verbose))
elif args.action == "set_name":
get_event_loop().run_until_complete(
asyncio.run(
set_name(args.device_id, args.ip_address, args.name, args.verbose)
)
elif args.action == "set_auto_shutdown":
get_event_loop().run_until_complete(
asyncio.run(
set_auto_shutdown(
args.device_id,
args.ip_address,
Expand All @@ -452,17 +448,15 @@ async def set_shutter_position(
)
)
elif args.action == "get_schedules":
get_event_loop().run_until_complete(
get_schedules(args.device_id, args.ip_address, args.verbose)
)
asyncio.run(get_schedules(args.device_id, args.ip_address, args.verbose))
elif args.action == "delete_schedule":
get_event_loop().run_until_complete(
asyncio.run(
delete_schedule(
args.device_id, args.ip_address, args.schedule_id, args.verbose
)
)
elif args.action == "create_schedule":
get_event_loop().run_until_complete(
asyncio.run(
create_schedule(
args.device_id,
args.ip_address,
Expand All @@ -474,7 +468,7 @@ async def set_shutter_position(
)

elif args.action == "stop_shutter":
get_event_loop().run_until_complete(
asyncio.run(
stop_shutter(
args.device_id,
args.ip_address,
Expand All @@ -483,7 +477,7 @@ async def set_shutter_position(
)

elif args.action == "set_shutter_position":
get_event_loop().run_until_complete(
asyncio.run(
set_shutter_position(
args.device_id,
args.ip_address,
Expand All @@ -493,7 +487,7 @@ async def set_shutter_position(
)

elif args.action == "control_thermostat":
get_event_loop().run_until_complete(
asyncio.run(
control_thermostat(
args.device_id,
args.ip_address,
Expand All @@ -508,7 +502,7 @@ async def set_shutter_position(
)
)
elif args.action == "get_thermostat_state":
get_event_loop().run_until_complete(
asyncio.run(
get_thermostat_state(args.device_id, args.ip_address, args.verbose)
)

Expand Down

0 comments on commit 1f05dac

Please sign in to comment.