Fix tests, remove debug leftovers
parent
be985b3240
commit
4fb8205cab
|
@ -48,13 +48,17 @@ def h(p):
|
||||||
|
|
||||||
def w(p, c):
|
def w(p, c):
|
||||||
try:
|
try:
|
||||||
|
print("file", p)
|
||||||
makedirs(dirname(p))
|
makedirs(dirname(p))
|
||||||
with open(p, "wb") as f:
|
with open(p, "wb") as f:
|
||||||
f.write(binascii.a2b_base64(c))
|
f.write(binascii.a2b_base64(c))
|
||||||
os.sync()
|
os.sync()
|
||||||
|
print("OK")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(str(e))
|
import sys
|
||||||
return None
|
print("Error while writing file %s" % p)
|
||||||
|
sys.print_exception(e)
|
||||||
|
pass
|
||||||
|
|
||||||
def clean(path=""):
|
def clean(path=""):
|
||||||
for s in os.listdir(path):
|
for s in os.listdir(path):
|
||||||
|
|
|
@ -179,8 +179,10 @@ def write_via_repl(args, content, rel_path):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
cmd = "w(%s, \"%s\")\n" % (rel_path_as_string, content)
|
cmd = "w(%s, \"%s\")\n" % (rel_path_as_string, content)
|
||||||
execbuffer(pyb,cmd)
|
result = returnbuffer(pyb,cmd)
|
||||||
return True
|
if "OK" in result:
|
||||||
|
return True
|
||||||
|
raise Exception("Couldn't write %s to badge: %s" % (rel_path, result))
|
||||||
|
|
||||||
def end_copy_via_repl(args):
|
def end_copy_via_repl(args):
|
||||||
# do we need to do anything?
|
# do we need to do anything?
|
||||||
|
|
2
boot.py
2
boot.py
|
@ -17,7 +17,7 @@ def file(file, remove):
|
||||||
os.remove(file)
|
os.remove(file)
|
||||||
return app(a)
|
return app(a)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(str(e))
|
print("Not found: %s" % file)
|
||||||
|
|
||||||
def any_home():
|
def any_home():
|
||||||
h = [a for a in root if a.startswith("home")]
|
h = [a for a in root if a.startswith("home")]
|
||||||
|
|
|
@ -17,9 +17,9 @@ They also *may*:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
___license___ = "MIT"
|
___license___ = "MIT"
|
||||||
___dependencies___ = ["database", "buttons", "random", "app", "sleep", "ugfx_helper"]
|
___dependencies___ = ["database", "buttons", "random", "app", "sleep", "ugfx_helper", "wifi"]
|
||||||
|
|
||||||
import database, ugfx, random, buttons, tilda, sleep, ugfx_helper
|
import database, ugfx, random, buttons, tilda, sleep, ugfx_helper, wifi
|
||||||
from app import App
|
from app import App
|
||||||
|
|
||||||
_state = None
|
_state = None
|
||||||
|
|
|
@ -1,15 +1,19 @@
|
||||||
"""Tests for ntp"""
|
"""Tests for ntp"""
|
||||||
|
|
||||||
___license___ = "MIT"
|
___license___ = "MIT"
|
||||||
___dependencies___ = ["upip:unittest", "ntp", "wifi"]
|
___dependencies___ = ["upip:unittest", "ntp", "wifi", "ugfx_helper"]
|
||||||
|
|
||||||
import unittest, wifi, ntp, machine
|
import unittest, wifi, ntp, machine, ugfx_helper
|
||||||
|
|
||||||
class TestWifi(unittest.TestCase):
|
class TestWifi(unittest.TestCase):
|
||||||
|
|
||||||
def setUpClass(self):
|
def setUpClass(self):
|
||||||
|
ugfx_helper.init()
|
||||||
wifi.connect()
|
wifi.connect()
|
||||||
|
|
||||||
|
def tearDownClass(self):
|
||||||
|
ugfx_helper.deinit()
|
||||||
|
|
||||||
def test_get_time(self):
|
def test_get_time(self):
|
||||||
t = ntp.get_NTP_time()
|
t = ntp.get_NTP_time()
|
||||||
self.assertTrue(t > 588699276)
|
self.assertTrue(t > 588699276)
|
||||||
|
|
|
@ -1,19 +1,18 @@
|
||||||
"""Tests for wifi"""
|
"""Tests for wifi"""
|
||||||
|
|
||||||
___license___ = "MIT"
|
___license___ = "MIT"
|
||||||
___dependencies___ = ["upip:unittest", "wifi"]
|
___dependencies___ = ["upip:unittest", "wifi", "ugfx_helper"]
|
||||||
|
|
||||||
import unittest, wifi, ugfx
|
import unittest, wifi, ugfx_helper
|
||||||
from machine import Pin
|
from machine import Pin
|
||||||
|
|
||||||
class TestWifi(unittest.TestCase):
|
class TestWifi(unittest.TestCase):
|
||||||
|
|
||||||
def setUpClass(self):
|
def setUpClass(self):
|
||||||
ugfx.init()
|
ugfx_helper.init()
|
||||||
Pin(Pin.PWM_LCD_BLIGHT).on()
|
|
||||||
|
|
||||||
def tearDownClass(self):
|
def tearDownClass(self):
|
||||||
Pin(Pin.PWM_LCD_BLIGHT).off()
|
ugfx_helper.deinit()
|
||||||
|
|
||||||
def test_connect(self):
|
def test_connect(self):
|
||||||
wifi.connect(show_wait_message=True)
|
wifi.connect(show_wait_message=True)
|
||||||
|
|
33
lib/wifi.py
33
lib/wifi.py
|
@ -85,20 +85,22 @@ def connect_wifi(details, timeout, wait=False):
|
||||||
def is_connected():
|
def is_connected():
|
||||||
return nic().isconnected()
|
return nic().isconnected()
|
||||||
|
|
||||||
|
def get_strength():
|
||||||
|
n = nic()
|
||||||
|
if n.isconnected():
|
||||||
|
r
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
def get_security_level(ap):
|
def get_security_level(ap):
|
||||||
#todo: fix this
|
#todo: fix this
|
||||||
n = nic()
|
n = nic()
|
||||||
levels = {}
|
levels = {
|
||||||
try:
|
n.SCAN_SEC_OPEN: 0, # I am awful
|
||||||
levels = {
|
n.SCAN_SEC_WEP: 'WEP',
|
||||||
n.SCAN_SEC_OPEN: 0, # I am awful
|
n.SCAN_SEC_WPA: 'WPA',
|
||||||
n.SCAN_SEC_WEP: 'WEP',
|
n.SCAN_SEC_WPA2: 'WPA2',
|
||||||
n.SCAN_SEC_WPA: 'WPA',
|
}
|
||||||
n.SCAN_SEC_WPA2: 'WPA2',
|
|
||||||
}
|
|
||||||
except AttributeError:
|
|
||||||
print("Firmware too old to query wifi security level, please upgrade.")
|
|
||||||
return None
|
|
||||||
|
|
||||||
return levels.get(ap.get('security', None), None)
|
return levels.get(ap.get('security', None), None)
|
||||||
|
|
||||||
|
@ -111,9 +113,7 @@ def choose_wifi(dialog_title='TiLDA'):
|
||||||
print(visible_aps)
|
print(visible_aps)
|
||||||
sleep.sleep_ms(300)
|
sleep.sleep_ms(300)
|
||||||
#todo: timeout
|
#todo: timeout
|
||||||
print(visible_aps)
|
|
||||||
visible_aps.sort(key=lambda x:x[3], reverse=True)
|
visible_aps.sort(key=lambda x:x[3], reverse=True)
|
||||||
print(visible_aps)
|
|
||||||
# We'll get one result for each AP, so filter dupes
|
# We'll get one result for each AP, so filter dupes
|
||||||
for ap in visible_aps:
|
for ap in visible_aps:
|
||||||
title = ap[0]
|
title = ap[0]
|
||||||
|
@ -128,7 +128,6 @@ def choose_wifi(dialog_title='TiLDA'):
|
||||||
if ap['ssid'] not in [ a['ssid'] for a in filtered_aps ]:
|
if ap['ssid'] not in [ a['ssid'] for a in filtered_aps ]:
|
||||||
filtered_aps.append(ap)
|
filtered_aps.append(ap)
|
||||||
del visible_aps
|
del visible_aps
|
||||||
print(filtered_aps)
|
|
||||||
|
|
||||||
ap = dialogs.prompt_option(
|
ap = dialogs.prompt_option(
|
||||||
filtered_aps,
|
filtered_aps,
|
||||||
|
@ -142,11 +141,7 @@ def choose_wifi(dialog_title='TiLDA'):
|
||||||
if ap['security'] == None:
|
if ap['security'] == None:
|
||||||
ap['security'] = 'wifi'
|
ap['security'] = 'wifi'
|
||||||
|
|
||||||
key = dialogs.prompt_text(
|
key = dialogs.prompt_text("Enter %s key" % ap['security'])
|
||||||
"Enter %s key" % ap['security'],
|
|
||||||
width = 310,
|
|
||||||
height = 220
|
|
||||||
)
|
|
||||||
with open("wifi.json", "wt") as file:
|
with open("wifi.json", "wt") as file:
|
||||||
if key:
|
if key:
|
||||||
conn_details = {"ssid": ap['ssid'], "pw": key}
|
conn_details = {"ssid": ap['ssid'], "pw": key}
|
||||||
|
|
|
@ -9,7 +9,6 @@ ___categories___ = ["Sound"]
|
||||||
___dependencies___ = ["speaker", "buttons", "ugfx_helper"]
|
___dependencies___ = ["speaker", "buttons", "ugfx_helper"]
|
||||||
|
|
||||||
import ugfx, speaker, ugfx_helper
|
import ugfx, speaker, ugfx_helper
|
||||||
from app import *
|
|
||||||
from tilda import Buttons
|
from tilda import Buttons
|
||||||
from buttons import *
|
from buttons import *
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue