Skip to content

Commit fa225cb

Browse files
author
brentru
committed
pylint and rename all mqtt examples, drop mqtt prefix as they're in the mqtt folder already
1 parent 99f3d0a commit fa225cb

File tree

4 files changed

+36
-35
lines changed

4 files changed

+36
-35
lines changed

examples/mqtt/adafruit_io_groups.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
import time
44
from random import randint
55

6-
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
76
import board
87
import busio
98
import neopixel
10-
from adafruit_esp32spi import adafruit_esp32spi, adafruit_esp32spi_wifimanager
9+
from adafruit_esp32spi import adafruit_esp32spi
10+
from adafruit_esp32spi import adafruit_esp32spi_wifimanager
11+
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
1112
from adafruit_io.adafruit_io import IO_MQTT
1213
from adafruit_minimqtt import MQTT
1314
from digitalio import DigitalInOut
@@ -50,6 +51,7 @@
5051

5152

5253
# Define callback functions which will be called when certain events happen.
54+
# pylint: disable=unused-argument
5355
def connected(client):
5456
# Connected function will be called when the client is connected to Adafruit IO.
5557
# This is a good place to subscribe to feed changes. The client parameter
@@ -60,12 +62,12 @@ def connected(client):
6062
# Subscribe to Group
6163
io.subscribe(group_key=group_name)
6264

63-
65+
# pylint: disable=unused-argument
6466
def disconnected(client):
6567
# Disconnected function will be called when the client disconnects.
6668
print("Disconnected from Adafruit IO!")
6769

68-
70+
# pylint: disable=unused-argument
6971
def message(client, feed_id, payload):
7072
# Message function will be called when a subscribed feed has a new value.
7173
# The feed_id parameter identifies the feed, and the payload parameter has
@@ -77,7 +79,7 @@ def message(client, feed_id, payload):
7779
wifi.connect()
7880

7981
# Initialize a new MQTT Client object
80-
client = MQTT(
82+
mqtt_client = MQTT(
8183
socket=socket,
8284
broker="io.adafruit.com",
8385
username=secrets["aio_user"],
@@ -86,7 +88,7 @@ def message(client, feed_id, payload):
8688
)
8789

8890
# Initialize an Adafruit IO MQTT Client
89-
io = IO_MQTT(client)
91+
io = IO_MQTT(mqtt_client)
9092

9193
# Connect the callback methods defined above to Adafruit IO
9294
io.on_connect = connected
@@ -97,8 +99,8 @@ def message(client, feed_id, payload):
9799
group_name = "weatherstation"
98100

99101
# Feeds within the group
100-
temp_feed = "brubell/feeds/weatherstation.temperature"
101-
humid_feed = "brubell/feeds/weatherstation.humidity"
102+
temp_feed = "weatherstation.temperature"
103+
humid_feed = "weatherstation.humidity"
102104

103105
# Connect to Adafruit IO
104106
io.connect()
@@ -109,9 +111,9 @@ def message(client, feed_id, payload):
109111
io.loop()
110112
temp_reading = randint(0, 100)
111113
print("Publishing value {0} to feed: {1}".format(temp_reading, temp_feed))
112-
client.publish(temp_feed, temp_reading)
114+
io.publish(temp_feed, temp_reading)
113115

114116
humid_reading = randint(0, 100)
115117
print("Publishing value {0} to feed: {1}".format(humid_reading, humid_feed))
116-
client.publish(humid_feed, humid_reading)
118+
io.publish(humid_feed, humid_reading)
117119
time.sleep(5)

examples/mqtt/adafruit_io_mqtt_location.py renamed to examples/mqtt/adafruit_io_location.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Example of tagging data with location values
22
# and sending it to an Adafruit IO feed.
33

4-
from random import randint
54
import board
65
import neopixel
76
import busio
@@ -50,22 +49,23 @@
5049
wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light)
5150

5251
# Define callback functions which will be called when certain events happen.
52+
# pylint: disable=unused-argument
5353
def connected(client):
5454
# Connected function will be called when the client is connected to Adafruit IO.
5555
# This is a good place to subscribe to feed changes. The client parameter
5656
# passed to this function is the Adafruit IO MQTT client so you can make
5757
# calls against it easily.
5858
print("Connected to Adafruit IO!")
5959

60-
# Subscribe to a location feed!
60+
# Subscribe to a feed named location
6161
io.subscribe("location")
6262

63-
63+
# pylint: disable=unused-argument
6464
def disconnected(client):
6565
# Disconnected function will be called when the client disconnects.
6666
print("Disconnected from Adafruit IO!")
6767

68-
68+
# pylint: disable=unused-argument
6969
def message(client, feed_id, payload):
7070
# Message function will be called when a subscribed feed has a new value.
7171
# The feed_id parameter identifies the feed, and the payload parameter has
@@ -77,7 +77,7 @@ def message(client, feed_id, payload):
7777
wifi.connect()
7878

7979
# Initialize a new MQTT Client object
80-
client = MQTT(
80+
mqtt_client = MQTT(
8181
socket=socket,
8282
broker="io.adafruit.com",
8383
username=secrets["aio_user"],
@@ -87,7 +87,7 @@ def message(client, feed_id, payload):
8787
)
8888

8989
# Initialize an Adafruit IO MQTT Client
90-
io = IO_MQTT(client)
90+
io = IO_MQTT(mqtt_client)
9191

9292
# Connect the callback methods defined above to Adafruit IO
9393
io.on_connect = connected

examples/mqtt/adafruit_io_mqtt_simpletest.py renamed to examples/mqtt/adafruit_io_simpletest.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@
66
# Modified by Brent Rubell for Adafruit Industries, 2019
77
import time
88
from random import randint
9+
10+
911
import board
10-
import neopixel
1112
import busio
12-
from digitalio import DigitalInOut
13+
import neopixel
1314
from adafruit_esp32spi import adafruit_esp32spi
1415
from adafruit_esp32spi import adafruit_esp32spi_wifimanager
1516
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
16-
17-
from adafruit_minimqtt import MQTT
1817
from adafruit_io.adafruit_io import IO_MQTT
18+
from adafruit_minimqtt import MQTT
19+
from digitalio import DigitalInOut
1920

2021
### WiFi ###
2122

@@ -54,6 +55,7 @@
5455
wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light)
5556

5657
# Define callback functions which will be called when certain events happen.
58+
# pylint: disable=unused-argument
5759
def connected(client):
5860
# Connected function will be called when the client is connected to Adafruit IO.
5961
# This is a good place to subscribe to feed changes. The client parameter
@@ -63,12 +65,12 @@ def connected(client):
6365
# Subscribe to changes on a feed named DemoFeed.
6466
client.subscribe("DemoFeed")
6567

66-
68+
# pylint: disable=unused-argument
6769
def disconnected(client):
6870
# Disconnected function will be called when the client disconnects.
6971
print("Disconnected from Adafruit IO!")
7072

71-
73+
# pylint: disable=unused-argument
7274
def message(client, feed_id, payload):
7375
# Message function will be called when a subscribed feed has a new value.
7476
# The feed_id parameter identifies the feed, and the payload parameter has
@@ -80,17 +82,16 @@ def message(client, feed_id, payload):
8082
wifi.connect()
8183

8284
# Initialize a new MQTT Client object
83-
client = MQTT(
85+
mqtt_client = MQTT(
8486
socket=socket,
8587
broker="io.adafruit.com",
8688
username=secrets["aio_user"],
8789
password=secrets["aio_key"],
88-
network_manager=wifi,
89-
log=True,
90+
network_manager=wifi
9091
)
9192

9293
# Initialize an Adafruit IO MQTT Client
93-
io = IO_MQTT(client)
94+
io = IO_MQTT(mqtt_client)
9495

9596
# Connect the callback methods defined above to Adafruit IO
9697
io.on_connect = connected

examples/mqtt/adafruit_io_mqtt_time.py renamed to examples/mqtt/adafruit_io_time.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
# Adafruit IO provides some built-in MQTT topics
22
# for obtaining the current server time, if you don't have
3-
# access to a RTC module.
3+
# access to a RTC module.
44

5-
import time
6-
from random import randint
75
import board
86
import neopixel
97
import busio
@@ -52,13 +50,14 @@
5250
wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light)
5351

5452
# Define callback functions which will be called when certain events happen.
53+
# pylint: disable=unused-argument
5554
def connected(client):
5655
# Connected function will be called when the client is connected to Adafruit IO.
5756
# This is a good place to subscribe to feed changes. The client parameter
5857
# passed to this function is the Adafruit IO MQTT client so you can make
5958
# calls against it easily.
6059
print("Connected to Adafruit IO!")
61-
60+
6261
# Subscribe to time/seconds topic
6362
# https://io.adafruit.com/api/docs/mqtt.html#time-seconds
6463
io.subscribe_to_time('seconds')
@@ -76,12 +75,12 @@ def connected(client):
7675
# https://io.adafruit.com/api/docs/mqtt.html#adafruit-io-monitor
7776
io.subscribe_to_time('hours')
7877

79-
78+
# pylint: disable=unused-argument
8079
def disconnected(client):
8180
# Disconnected function will be called when the client disconnects.
8281
print("Disconnected from Adafruit IO!")
8382

84-
83+
# pylint: disable=unused-argument
8584
def message(client, feed_id, payload):
8685
# Message function will be called when a subscribed feed has a new value.
8786
# The feed_id parameter identifies the feed, and the payload parameter has
@@ -93,17 +92,16 @@ def message(client, feed_id, payload):
9392
wifi.connect()
9493

9594
# Initialize a new MQTT Client object
96-
client = MQTT(
95+
mqtt_client = MQTT(
9796
socket=socket,
9897
broker="io.adafruit.com",
9998
username=secrets["aio_user"],
10099
password=secrets["aio_key"],
101100
network_manager=wifi,
102-
log=True
103101
)
104102

105103
# Initialize an Adafruit IO MQTT Client
106-
io = IO_MQTT(client)
104+
io = IO_MQTT(mqtt_client)
107105

108106
# Connect the callback methods defined above to Adafruit IO
109107
io.on_connect = connected

0 commit comments

Comments
 (0)