Skip to content

Commit 5b42670

Browse files
committed
Travis fixes
1 parent 89f30f3 commit 5b42670

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

PyPortal_Smart_Switch/code.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from adafruit_esp32spi import adafruit_esp32spi
88
import adafruit_requests as requests
99
import digitalio
10-
import displayio
1110
import analogio
1211
from adafruit_pyportal import PyPortal
1312
from adafruit_display_shapes.circle import Circle
@@ -62,7 +61,6 @@
6261
print("MAC addr:", [hex(i) for i in esp.MAC_address])
6362

6463
pyportal = PyPortal(esp=esp, external_spi=spi)
65-
#light = analogio.AnalogIn(board.LIGHT)
6664

6765
for ap in esp.scan_networks():
6866
print("\t%s\t\tRSSI: %d" % (str(ap['ssid'], 'utf-8'), ap['rssi']))
@@ -102,15 +100,15 @@ def create_text_areas(configs):
102100
return text_areas
103101

104102
class Switch(object):
105-
def __init__(self, pin, pyportal):
103+
def __init__(self, pin, my_pyportal):
106104
self.switch = digitalio.DigitalInOut(pin)
107105
self.switch.direction = digitalio.Direction.OUTPUT
108106
rect = RoundRect(SWITCHX, SWITCHY, 31, 60, 16, fill=0x0, outline=DISPLAY_COLOR, stroke=3)
109-
pyportal.splash.append(rect)
107+
my_pyportal.splash.append(rect)
110108
self.circle_on = Circle(SWITCHX + 15, SWITCHY + 16, 10, fill=0x0)
111-
pyportal.splash.append(self.circle_on)
109+
my_pyportal.splash.append(self.circle_on)
112110
self.circle_off = Circle(SWITCHX + 15, SWITCHY + 42, 10, fill=DISPLAY_COLOR)
113-
pyportal.splash.append(self.circle_off)
111+
my_pyportal.splash.append(self.circle_off)
114112

115113
# turn switch on or off
116114
def enable(self, enable):
@@ -124,7 +122,7 @@ def enable(self, enable):
124122
self.circle_off.fill = DISPLAY_COLOR
125123

126124
def toggle(self):
127-
if self.switch.value == True:
125+
if self.switch.value:
128126
self.enable(False)
129127
else:
130128
self.enable(True)
@@ -137,26 +135,28 @@ def status(self):
137135
# See https://apidock.com/ruby/DateTime/strftime for full options
138136
TIME_SERVICE_TIMESTAMP = '&fmt=%25s+%25z'
139137

140-
class Clock(object):
138+
class Clock(object, my_pyportal):
141139
def __init__(self):
142140
self.low_light = False
143141
self.update_time = None
144142
self.snapshot_time = None
143+
self.pyportal = my_pyportal
144+
self.current_time = 0
145145
self.light = analogio.AnalogIn(board.LIGHT)
146146
text_area_configs = [dict(x=0, y=110, size=72, color=DISPLAY_COLOR, font=time_font),
147147
dict(x=260, y=165, size=18, color=DISPLAY_COLOR, font=ampm_font),
148148
dict(x=10, y=40, size=18, color=DISPLAY_COLOR, font=date_font)]
149149
self.text_areas = create_text_areas(text_area_configs)
150150
for ta in self.text_areas:
151-
pyportal.splash.append(ta)
151+
self.pyportal.splash.append(ta)
152152

153153
def adjust_backlight(self, force=False):
154154
"""Check light level. Adjust the backlight and background image if it's dark."""
155155
if force or (self.light.value >= 1500 and self.low_light):
156-
pyportal.set_backlight(1.00)
156+
self.pyportal.set_backlight(1.00)
157157
self.low_light = False
158158
elif self.light.value <= 1000 and not self.low_light:
159-
pyportal.set_backlight(0.1)
159+
self.pyportal.set_backlight(0.1)
160160
self.low_light = True
161161

162162
def tick(self, now):
@@ -228,6 +228,8 @@ def get_local_timestamp(self, location=None):
228228
gc.collect()
229229
return int(seconds + tzseconds)
230230

231+
# Define callback methods which are called when events occur
232+
# pylint: disable=unused-argument, redefined-outer-name
231233
def connected(client, userdata, flags, rc):
232234
# This function will be called when the client is connected
233235
# successfully to the broker.
@@ -263,7 +265,7 @@ def message(client, topic, message):
263265
mqtt_client.on_message = message
264266

265267
mqtt_client.connect()
266-
clock = Clock()
268+
clock = Clock(pyportal)
267269
switch = Switch(board.D4, pyportal)
268270

269271
second_timer = time.monotonic()

0 commit comments

Comments
 (0)