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