Skip to content

Commit

Permalink
Fix async stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
frimtec committed Feb 10, 2021
1 parent ff4f3db commit ad676c2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
12 changes: 10 additions & 2 deletions compal_wifi_switch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def find_in_band(band):
return found_entry

@staticmethod
async def status(host, password):
def status(host, password):
modem = Compal(host, password)
modem.login()

Expand Down Expand Up @@ -114,7 +114,11 @@ async def status(host, password):
}

@staticmethod
async def switch(host, password, state, band, guest, pause, verbose=False):
async def async_status(host, password):
return Commands.status(host, password)

@staticmethod
def switch(host, password, state, band, guest, pause, verbose=False):
guest_networks = guest
enable_guest_networks = len(guest_networks) > 0
if enable_guest_networks:
Expand Down Expand Up @@ -189,3 +193,7 @@ async def switch(host, password, state, band, guest, pause, verbose=False):
modem.logout()

print("Finished.")

@staticmethod
async def async_switch(host, password, state, band, guest, pause, verbose=False):
Commands.switch(host, password, state, band, guest, pause, verbose)
16 changes: 7 additions & 9 deletions compal_wifi_switch/main.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import argparse
import os
import asyncio
import json

import pkg_resources

from compal_wifi_switch import (Switch, Band, Commands, Format)


async def status(args):
status_object = await Commands.status(args.host, args.password)
def status(args):
status_object = Commands.status(args.host, args.password)
if args.format == Format.JSON:
print(json.dumps(status_object, indent=2))
else:
Expand Down Expand Up @@ -45,8 +44,8 @@ async def status(args):
f"{interface['mac']} {('ON' if interface['hidden'] else 'OFF'):6} {interface['ssid']}")


async def switch(args):
await Commands.switch(args.host, args.password, args.state, args.band, args.guest, args.pause, args.verbose)
def switch(args):
Commands.switch(args.host, args.password, args.state, args.band, args.guest, args.pause, args.verbose)


def add_modem_arguments(parser):
Expand All @@ -61,7 +60,7 @@ def add_modem_arguments(parser):
parser.add_argument('--verbose', action='store_true', help="verbose logging")


async def main():
def main():
parser = argparse.ArgumentParser(description="Compal-Wifi-Switch configuration")
parser.add_argument('--version', '-v', action='version',
version='%(prog)s v' + pkg_resources.get_distribution('compal_wifi_switch').version)
Expand Down Expand Up @@ -102,9 +101,8 @@ async def main():
if args.host is None or args.password is None:
raise ValueError('Missing value for HOST or PASSWORD arguments!')

await args.func(args)
args.func(args)


if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
main()

0 comments on commit ad676c2

Please sign in to comment.