Skip to content

Commit 8514ffe

Browse files
Ran black
1 parent 151c1f2 commit 8514ffe

File tree

3 files changed

+44
-45
lines changed

3 files changed

+44
-45
lines changed

PyPortal_Azure_Plant_Monitor/azure_gfx_helper.py

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
from adafruit_display_text.label import Label
77
from adafruit_bitmap_font import bitmap_font
88

9-
cwd = ("/"+__file__).rsplit('/', 1)[0] # the current working directory (where this file is)
9+
# the current working directory (where this file is)
10+
cwd = ("/" + __file__).rsplit("/", 1)[0]
1011

1112
# Fonts within /fonts folder
12-
main_font = cwd+"/fonts/EarthHeart-26.bdf"
13-
data_font = cwd+"/fonts/Collegiate-50.bdf"
13+
main_font = cwd + "/fonts/EarthHeart-26.bdf"
14+
data_font = cwd + "/fonts/Collegiate-50.bdf"
15+
1416

1517
class Azure_GFX(displayio.Group):
1618
def __init__(self, is_celsius):
@@ -34,18 +36,18 @@ def __init__(self, is_celsius):
3436
self._icon_sprite = None
3537
self._icon_file = None
3638
self._cwd = cwd
37-
self.set_icon(self._cwd+"/images/azure_splash.bmp")
39+
self.set_icon(self._cwd + "/images/azure_splash.bmp")
3840

39-
print('loading fonts...')
40-
glyphs = b'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-,.: '
41-
data_glyphs = b'012345678-,.:/FC'
41+
print("loading fonts...")
42+
glyphs = b"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-,.: "
43+
data_glyphs = b"012345678-,.:/FC"
4244
self.main_font = bitmap_font.load_font(main_font)
4345
self.main_font.load_glyphs(glyphs)
4446
self.data_font = bitmap_font.load_font(data_font)
4547
self.data_font.load_glyphs(data_glyphs)
46-
self.data_font.load_glyphs(('°',)) # extra glyph for temperature font
48+
self.data_font.load_glyphs(("°",)) # extra glyph for temperature font
4749

48-
print('setting up labels...')
50+
print("setting up labels...")
4951
self.title_text = Label(self.main_font, text="Azure Plant Monitor")
5052
self.title_text.x = 35
5153
self.title_text.y = 25
@@ -89,7 +91,7 @@ def display_moisture(self, moisture_data):
8991
"""Displays the moisture from the Stemma Soil Sensor.
9092
:param int moisture_data: Moisture value
9193
"""
92-
print('Moisture Level: ', moisture_data)
94+
print("Moisture Level: ", moisture_data)
9395
self.moisture_text.text = str(moisture_data)
9496

9597
def display_temp(self, temp_data):
@@ -98,22 +100,22 @@ def display_temp(self, temp_data):
98100
"""
99101
if not self._is_celsius:
100102
temp_data = (temp_data * 9 / 5) + 32 - 15
101-
print('Temperature: %0.0f°F'%temp_data)
103+
print("Temperature: %0.0f°F" % temp_data)
102104
if temp_data >= 212:
103105
self.temp_text.color = 0xFD2EE
104106
elif temp_data <= 32:
105107
self.temp_text.color = 0xFF0000
106-
self.temp_text.text = '%0.0f°F'%temp_data
107-
temp_data = '%0.0f'%temp_data
108+
self.temp_text.text = "%0.0f°F" % temp_data
109+
temp_data = "%0.0f" % temp_data
108110
return int(temp_data)
109111
else:
110-
print('Temperature: %0.0f°C'%temp_data)
112+
print("Temperature: %0.0f°C" % temp_data)
111113
if temp_data <= 0:
112114
self.temp_text.color = 0xFD2EE
113115
elif temp_data >= 100:
114116
self.temp_text.color = 0xFF0000
115-
self.temp_text.text = '%0.0f°C'%temp_data
116-
temp_data = '%0.0f'%temp_data
117+
self.temp_text.text = "%0.0f°C" % temp_data
118+
temp_data = "%0.0f" % temp_data
117119
return int(temp_data)
118120

119121
def set_icon(self, filename):
@@ -133,8 +135,9 @@ def set_icon(self, filename):
133135
self._icon_file.close()
134136
self._icon_file = open(filename, "rb")
135137
icon = displayio.OnDiskBitmap(self._icon_file)
136-
self._icon_sprite = displayio.TileGrid(icon,
137-
pixel_shader=getattr(icon, 'pixel_shader', displayio.ColorConverter()))
138+
self._icon_sprite = displayio.TileGrid(
139+
icon, pixel_shader=getattr(icon, "pixel_shader", displayio.ColorConverter())
140+
)
138141

139142
# CircuitPython 7 compatible
140143
# # Remove self._icon_file - it is no longer used

PyPortal_Azure_Plant_Monitor/code.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,7 @@
5959

6060
# Create an instance of the Azure IoT Central device
6161
device = IoTCentralDevice(
62-
socket,
63-
esp,
64-
secrets["id_scope"],
65-
secrets["device_id"],
66-
secrets["key"]
62+
socket, esp, secrets["id_scope"], secrets["device_id"], secrets["key"]
6763
)
6864

6965
# Connect to Azure IoT Central
@@ -82,19 +78,16 @@
8278
gfx.display_moisture(moisture_level)
8379
gfx.display_temp(temperature)
8480

85-
print('Sending data to Azure')
86-
gfx.display_azure_status('Sending data...')
81+
print("Sending data to Azure")
82+
gfx.display_azure_status("Sending data...")
8783

8884
# send the temperature and moisture level to Azure
89-
message = {
90-
"Temperature": temperature,
91-
"MoistureLevel": moisture_level
92-
}
85+
message = {"Temperature": temperature, "MoistureLevel": moisture_level}
9386
device.send_telemetry(json.dumps(message))
9487
device.loop()
9588

96-
gfx.display_azure_status('Data sent!')
97-
print('Data sent!')
89+
gfx.display_azure_status("Data sent!")
90+
print("Data sent!")
9891
except (ValueError, RuntimeError) as e:
9992
print("Failed to get data, retrying\n", e)
10093
wifi.reset()

azure_gfx_helper.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
from adafruit_display_text.label import Label
77
from adafruit_bitmap_font import bitmap_font
88

9-
cwd = ("/"+__file__).rsplit('/', 1)[0] # the current working directory (where this file is)
9+
# the current working directory (where this file is)
10+
cwd = ("/" + __file__).rsplit("/", 1)[0]
1011

1112
# Fonts within /fonts folder
12-
info_font = cwd+"/fonts/Nunito-Black-17.bdf"
13-
temperature_font = cwd+"/fonts/Nunito-Light-75.bdf"
13+
info_font = cwd + "/fonts/Nunito-Black-17.bdf"
14+
temperature_font = cwd + "/fonts/Nunito-Light-75.bdf"
15+
1416

1517
class Azure_GFX(displayio.Group):
1618
def __init__(self, celsius=False):
@@ -35,18 +37,18 @@ def __init__(self, celsius=False):
3537
self._icon_sprite = None
3638
self._icon_file = None
3739
self._cwd = cwd
38-
self.set_icon(self._cwd+"/images/azure_splash.bmp")
40+
self.set_icon(self._cwd + "/images/azure_splash.bmp")
3941

40-
print('Loading Fonts...')
41-
glyphs = b'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-,.:/ '
42+
print("Loading Fonts...")
43+
glyphs = b"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-,.:/ "
4244
self.info_font = bitmap_font.load_font(info_font)
4345
self.info_font.load_glyphs(glyphs)
4446

4547
self.c_font = bitmap_font.load_font(temperature_font)
4648
self.c_font.load_glyphs(glyphs)
47-
self.c_font.load_glyphs(('°',)) # extra glyph for temperature font
49+
self.c_font.load_glyphs(("°",)) # extra glyph for temperature font
4850

49-
print('setting up labels...')
51+
print("setting up labels...")
5052
self.title_text = Label(self.info_font, text="Azure IoT Temperature Logger")
5153
self.title_text.x = 55
5254
self.title_text.y = 15
@@ -76,19 +78,19 @@ def display_temp(self, adt_data):
7678
"""
7779
if not self._celsius:
7880
adt_data = (adt_data * 9 / 5) + 32
79-
print('Temperature: %0.2f°F'%adt_data)
81+
print("Temperature: %0.2f°F" % adt_data)
8082
if adt_data >= 212:
8183
self.temp_text.color = 0xFD2EE
8284
elif adt_data <= 32:
8385
self.temp_text.color = 0xFF0000
84-
self.temp_text.text = '%0.2f°F'%adt_data
86+
self.temp_text.text = "%0.2f°F" % adt_data
8587
else:
86-
print('Temperature: %0.2f°C'%adt_data)
88+
print("Temperature: %0.2f°C" % adt_data)
8789
if adt_data <= 0:
8890
self.temp_text.color = 0xFD2EE
8991
elif adt_data >= 100:
9092
self.temp_text.color = 0xFF0000
91-
self.temp_text.text = '%0.2f°C'%adt_data
93+
self.temp_text.text = "%0.2f°C" % adt_data
9294

9395
def set_icon(self, filename):
9496
"""Sets the background image to a bitmap file.
@@ -107,8 +109,9 @@ def set_icon(self, filename):
107109
self._icon_file.close()
108110
self._icon_file = open(filename, "rb")
109111
icon = displayio.OnDiskBitmap(self._icon_file)
110-
self._icon_sprite = displayio.TileGrid(icon,
111-
pixel_shader=getattr(icon, 'pixel_shader', displayio.ColorConverter()))
112+
self._icon_sprite = displayio.TileGrid(
113+
icon, pixel_shader=getattr(icon, "pixel_shader", displayio.ColorConverter())
114+
)
112115

113116
# CircuitPython 7 compatible
114117
# # Remove self._icon_file - it is no longer used

0 commit comments

Comments
 (0)