Skip to content

Commit 145bce2

Browse files
authored
Merge pull request #54 from adafruit/pylint-fix
Fixed pylint failures - mostly line-too-long
2 parents b3a9086 + 1028aeb commit 145bce2

24 files changed

+152
-94
lines changed

adafruit_azureiot/__init__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
2828
**With Native Networking**
2929
30-
* CircuitPython's Wifi Module: https://docs.circuitpython.org/en/latest/shared-bindings/wifi/index.html
30+
* CircuitPython's Wifi Module:
31+
https://docs.circuitpython.org/en/latest/shared-bindings/wifi/index.html
3132
* Adafruit's Requests Library: https://github.com/adafruit/Adafruit_CircuitPython_Requests/
3233
"""
3334

adafruit_azureiot/constants.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
`constants`
88
================================================================================
99
10-
This file is for maintaining Microsoft Azure IoT constants that could be changed or added to over time for different scenarios
10+
This file is for maintaining Microsoft Azure IoT constants that could be changed or added to over
11+
time for different scenarios
1112
1213
* Author(s): Jim Bennett, Elena Horton
1314
"""
@@ -18,5 +19,6 @@
1819
# The version of the Azure Device Provisioning Service this code is built against
1920
DPS_API_VERSION = "2019-03-31"
2021

21-
# The Azure Device Provisioning service endpoint that this library uses to provision IoT Central devices
22+
# The Azure Device Provisioning service endpoint that this library uses to provision IoT Central
23+
# devices
2224
DPS_END_POINT = "global.azure-devices-provisioning.net"

adafruit_azureiot/device_registration.py

+12-4
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ def _connect_to_mqtt(self) -> None:
115115
self._mqtt.loop()
116116

117117
self._logger.info(
118-
f" - device_registration :: connect :: on_connect must be fired. Connected ? {self._mqtt.is_connected()}"
118+
" - device_registration :: connect :: on_connect must be fired. Connected ?"
119+
f"{self._mqtt.is_connected()}"
119120
)
120121

121122
if not self._mqtt.is_connected():
@@ -148,7 +149,8 @@ def _start_registration(self) -> None:
148149
def _wait_for_operation(self) -> None:
149150
message = json.dumps({"operationId": self._operation_id})
150151
self._mqtt.publish(
151-
f"$dps/registrations/GET/iotdps-get-operationstatus/?$rid={self._device_id}&operationId={self._operation_id}",
152+
"$dps/registrations/GET/iotdps-get-operationstatus/?$rid="
153+
f"{self._device_id}&operationId={self._operation_id}",
152154
message,
153155
)
154156

@@ -176,15 +178,21 @@ def register_device(self, expiry: int) -> str:
176178
:raises RuntimeError: if the internet connection is not responding or is unable to connect
177179
"""
178180

179-
username = f"{self._id_scope}/registrations/{self._device_id}/api-version={constants.DPS_API_VERSION}"
181+
username = (
182+
f"{self._id_scope}/registrations/{self._device_id}/api-version="
183+
+ f"{constants.DPS_API_VERSION}"
184+
)
180185

181186
# pylint: disable=C0103
182187
sr = self._id_scope + "%2Fregistrations%2F" + self._device_id
183188
sig_no_encode = compute_derived_symmetric_key(
184189
self._device_sas_key, sr + "\n" + str(expiry)
185190
)
186191
sig_encoded = quote(sig_no_encode, "~()*!.'")
187-
auth_string = f"SharedAccessSignature sr={sr}&sig={sig_encoded}&se={expiry}&skn=registration"
192+
auth_string = (
193+
f"SharedAccessSignature sr={sr}&sig={sig_encoded}&se={expiry}"
194+
"&skn=registration"
195+
)
188196

189197
MQTT.set_socket(self._socket, self._iface)
190198

adafruit_azureiot/hmac.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
1515
"""
1616

17-
# pylint: disable=C0103, W0108, R0915, C0116, C0115
17+
# pylint: disable=C0103, W0108, R0915, C0116, C0115, unnecessary-lambda-assignment
1818

1919
try:
2020
from typing import Union

adafruit_azureiot/iot_mqtt.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ class IoTResponse:
3333
def __init__(self, code: int, message: str):
3434
"""Creates an IoT Response object
3535
36-
:param int code: The HTTP response code for this method call, for example 200 if the method was handled successfully
36+
:param int code: The HTTP response code for this method call, for example 200 if the method
37+
was handled successfully
3738
:param str message: The HTTP response message for this method call
3839
"""
3940
self.response_code = code
@@ -120,9 +121,12 @@ def _gen_sas_token(self) -> str:
120121
def _create_mqtt_client(self) -> None:
121122
MQTT.set_socket(self._socket, self._iface)
122123

124+
log_text = (
125+
f"- iot_mqtt :: _on_connect :: username = {self._username}, password = "
126+
+ f"{self._passwd}"
127+
)
123128
self._logger.debug(
124-
str.replace(
125-
f"- iot_mqtt :: _on_connect :: username = {self._username}, password = {self._passwd}",
129+
log_text.replace(
126130
"%",
127131
"%%",
128132
)
@@ -334,7 +338,8 @@ def __init__(
334338
:param IoTMQTTCallback callback: A callback class
335339
:param socket: The socket to communicate over
336340
:param iface: The network interface to communicate over
337-
:param str hostname: The hostname of the MQTT broker to connect to, get this by registering the device
341+
:param str hostname: The hostname of the MQTT broker to connect to, get this by registering
342+
the device
338343
:param str device_id: The device ID of the device to register
339344
:param str device_sas_key: The primary or secondary key of the device to register
340345
:param int token_expires: The number of seconds till the token expires, defaults to 6 hours

adafruit_azureiot/iotcentral_device.py

+11-7
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from .iot_mqtt import IoTMQTT, IoTMQTTCallback, IoTResponse
2222

2323

24-
class IoTCentralDevice(IoTMQTTCallback):
24+
class IoTCentralDevice(IoTMQTTCallback): # pylint: disable=too-many-instance-attributes
2525
"""A device client for the Azure IoT Central service"""
2626

2727
def connection_status_change(self, connected: bool) -> None:
@@ -120,23 +120,27 @@ def __init__(
120120
self._mqtt = None
121121

122122
self.on_connection_status_changed = None
123-
"""A callback method that is called when the connection status is changed. This method should have the following signature:
123+
"""A callback method that is called when the connection status is changed.
124+
This method should have the following signature:
124125
def connection_status_changed(connected: bool) -> None
125126
"""
126127

127128
self.on_command_executed = None
128-
"""A callback method that is called when a command is executed on the device. This method should have the following signature:
129+
"""A callback method that is called when a command is executed on the device.
130+
This method should have the following signature:
129131
def connection_status_changed(method_name: str, payload: str) -> IoTResponse:
130132
131-
This method returns an IoTResponse containing a status code and message from the command call. Set this appropriately
132-
depending on if the command was successfully handled or not. For example, if the command was handled successfully, set
133-
the code to 200 and message to "OK":
133+
This method returns an IoTResponse containing a status code and message from the command
134+
call. Set this appropriately depending on if the command was successfully handled or not.
135+
For example, if the command was handled successfully, set the code to 200 and message to
136+
"OK":
134137
135138
return IoTResponse(200, "OK")
136139
"""
137140

138141
self.on_property_changed = None
139-
"""A callback method that is called when property values are updated. This method should have the following signature:
142+
"""A callback method that is called when property values are updated.
143+
This method should have the following signature:
140144
def property_changed(_property_name: str, property_value, version: int) -> None
141145
"""
142146

adafruit_azureiot/iothub_device.py

+40-27
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def _validate_keys(connection_string_parts: Mapping) -> None:
6161
]
6262

6363

64-
class IoTHubDevice(IoTMQTTCallback):
64+
class IoTHubDevice(IoTMQTTCallback): # pylint: disable=too-many-instance-attributes
6565
"""A device client for the Azure IoT Hub service"""
6666

6767
def connection_status_change(self, connected: bool) -> None:
@@ -135,7 +135,7 @@ def device_twin_reported_updated(
135135
reported_property_name, reported_property_value, reported_version
136136
)
137137

138-
def __init__(
138+
def __init__( # pylint: disable=too-many-arguments
139139
self,
140140
socket,
141141
iface,
@@ -168,7 +168,8 @@ def __init__(
168168
)
169169
except (ValueError, AttributeError) as e:
170170
raise ValueError(
171-
"Connection string is required and should not be empty or blank and must be supplied as a string"
171+
"Connection string is required and should not be empty or blank and must be"
172+
"supplied as a string"
172173
) from e
173174

174175
if len(cs_args) != len(connection_string_values):
@@ -194,7 +195,8 @@ def __init__(
194195

195196
@property
196197
def on_connection_status_changed(self) -> Callable:
197-
"""A callback method that is called when the connection status is changed. This method should have the following signature:
198+
"""A callback method that is called when the connection status is changed.
199+
This method should have the following signature:
198200
def connection_status_changed(connected: bool) -> None
199201
"""
200202
return self._on_connection_status_changed
@@ -203,40 +205,46 @@ def connection_status_changed(connected: bool) -> None
203205
def on_connection_status_changed(
204206
self, new_on_connection_status_changed: Callable
205207
) -> None:
206-
"""A callback method that is called when the connection status is changed. This method should have the following signature:
208+
"""A callback method that is called when the connection status is changed.
209+
This method should have the following signature:
207210
def connection_status_changed(connected: bool) -> None
208211
"""
209212
self._on_connection_status_changed = new_on_connection_status_changed
210213

211214
@property
212215
def on_direct_method_invoked(self) -> Callable:
213-
"""A callback method that is called when a direct method is invoked. This method should have the following signature:
216+
"""A callback method that is called when a direct method is invoked.
217+
This method should have the following signature:
214218
def direct_method_invoked(method_name: str, payload: str) -> IoTResponse:
215219
216-
This method returns an IoTResponse containing a status code and message from the method invocation. Set this appropriately
217-
depending on if the method was successfully handled or not. For example, if the method was handled successfully, set
218-
the code to 200 and message to "OK":
220+
This method returns an IoTResponse containing a status code and message from the method
221+
invocation. Set this appropriately depending on if the method was successfully handled or
222+
not. For example, if the method was handled successfully, set the code to 200 and message
223+
to "OK":
219224
220225
return IoTResponse(200, "OK")
221226
"""
222227
return self._on_direct_method_invoked
223228

224229
@on_direct_method_invoked.setter
225230
def on_direct_method_invoked(self, new_on_direct_method_invoked: Callable) -> None:
226-
"""A callback method that is called when a direct method is invoked. This method should have the following signature:
231+
"""A callback method that is called when a direct method is invoked.
232+
This method should have the following signature:
227233
def direct_method_invoked(method_name: str, payload: str) -> IoTResponse:
228234
229-
This method returns an IoTResponse containing a status code and message from the method invocation. Set this appropriately
230-
depending on if the method was successfully handled or not. For example, if the method was handled successfully, set
231-
the code to 200 and message to "OK":
235+
This method returns an IoTResponse containing a status code and message from the method
236+
invocation. Set this appropriately depending on if the method was successfully handled or
237+
not. For example, if the method was handled successfully, set the code to 200 and message
238+
to "OK":
232239
233240
return IoTResponse(200, "OK")
234241
"""
235242
self._on_direct_method_invoked = new_on_direct_method_invoked
236243

237244
@property
238245
def on_cloud_to_device_message_received(self) -> Callable:
239-
"""A callback method that is called when a cloud to device message is received. This method should have the following signature:
246+
"""A callback method that is called when a cloud to device message is received.
247+
This method should have the following signature:
240248
def cloud_to_device_message_received(body: str, properties: dict) -> None:
241249
"""
242250
return self._on_cloud_to_device_message_received
@@ -245,7 +253,8 @@ def cloud_to_device_message_received(body: str, properties: dict) -> None:
245253
def on_cloud_to_device_message_received(
246254
self, new_on_cloud_to_device_message_received: Callable
247255
) -> None:
248-
"""A callback method that is called when a cloud to device message is received. This method should have the following signature:
256+
"""A callback method that is called when a cloud to device message is received.
257+
This method should have the following signature:
249258
def cloud_to_device_message_received(body: str, properties: dict) -> None:
250259
"""
251260
self._on_cloud_to_device_message_received = (
@@ -254,19 +263,21 @@ def cloud_to_device_message_received(body: str, properties: dict) -> None:
254263

255264
@property
256265
def on_device_twin_desired_updated(self) -> Callable:
257-
"""A callback method that is called when the desired properties of the devices device twin are updated.
258-
This method should have the following signature:
259-
def device_twin_desired_updated(desired_property_name: str, desired_property_value, desired_version: int) -> None:
266+
"""A callback method that is called when the desired properties of the devices device twin
267+
are updated. This method should have the following signature:
268+
def device_twin_desired_updated(desired_property_name: str, desired_property_value,
269+
desired_version: int) -> None:
260270
"""
261271
return self._on_device_twin_desired_updated
262272

263273
@on_device_twin_desired_updated.setter
264274
def on_device_twin_desired_updated(
265275
self, new_on_device_twin_desired_updated: Callable
266276
) -> None:
267-
"""A callback method that is called when the desired properties of the devices device twin are updated.
268-
This method should have the following signature:
269-
def device_twin_desired_updated(desired_property_name: str, desired_property_value, desired_version: int) -> None:
277+
"""A callback method that is called when the desired properties of the devices device twin
278+
are updated. This method should have the following signature:
279+
def device_twin_desired_updated(desired_property_name: str, desired_property_value,
280+
desired_version: int) -> None:
270281
"""
271282
self._on_device_twin_desired_updated = new_on_device_twin_desired_updated
272283

@@ -275,19 +286,21 @@ def device_twin_desired_updated(desired_property_name: str, desired_property_val
275286

276287
@property
277288
def on_device_twin_reported_updated(self) -> Callable:
278-
"""A callback method that is called when the reported properties of the devices device twin are updated.
279-
This method should have the following signature:
280-
def device_twin_reported_updated(reported_property_name: str, reported_property_value, reported_version: int) -> None:
289+
"""A callback method that is called when the reported properties of the devices device twin
290+
are updated. This method should have the following signature:
291+
def device_twin_reported_updated(reported_property_name: str, reported_property_value,
292+
reported_version: int) -> None:
281293
"""
282294
return self._on_device_twin_reported_updated
283295

284296
@on_device_twin_reported_updated.setter
285297
def on_device_twin_reported_updated(
286298
self, new_on_device_twin_reported_updated: Callable
287299
) -> None:
288-
"""A callback method that is called when the reported properties of the devices device twin are updated.
289-
This method should have the following signature:
290-
def device_twin_reported_updated(reported_property_name: str, reported_property_value, reported_version: int) -> None:
300+
"""A callback method that is called when the reported properties of the devices device twin
301+
are updated. This method should have the following signature:
302+
def device_twin_reported_updated(reported_property_name: str, reported_property_value,
303+
reported_version: int) -> None:
291304
"""
292305
self._on_device_twin_reported_updated = new_on_device_twin_reported_updated
293306

examples/azureiot_esp32spi/azureiot_central_commands.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,13 @@
7979
# If you are not a student, head to https://aka.ms/FreeAz and sign up to get $200 of credit for 30
8080
# days, as well as free tiers of a load of services
8181
#
82-
# Create an Azure IoT Central app by following these instructions: https://aka.ms/CreateIoTCentralApp
82+
# Create an Azure IoT Central app by following these instructions:
83+
# https://aka.ms/CreateIoTCentralApp
8384
# Add a device template with telemetry, properties and commands, as well as a view to visualize the
8485
# telemetry and execute commands, and a form to set properties.
8586
#
86-
# Next create a device using the device template, and select Connect to get the device connection details.
87+
# Next create a device using the device template, and select Connect to get the device connection
88+
# details.
8789
# Add the connection details to your secrets.py file, using the following values:
8890
#
8991
# 'id_scope' - the devices ID scope
@@ -92,7 +94,7 @@
9294
#
9395
# The adafruit-circuitpython-azureiot library depends on the following libraries:
9496
#
95-
# From the Adafruit CircuitPython Bundle (https://github.com/adafruit/Adafruit_CircuitPython_Bundle):
97+
# From the Adafruit CircuitPython Bundle https://github.com/adafruit/Adafruit_CircuitPython_Bundle:
9698
# * adafruit-circuitpython-minimqtt
9799
# * adafruit-circuitpython-requests
98100
# pylint: disable=wrong-import-position

examples/azureiot_esp32spi/azureiot_central_notconnected.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,13 @@
7373
# If you are not a student, head to https://aka.ms/FreeAz and sign up to get $200 of credit for 30
7474
# days, as well as free tiers of a load of services
7575
#
76-
# Create an Azure IoT Central app by following these instructions: https://aka.ms/CreateIoTCentralApp
76+
# Create an Azure IoT Central app by following these instructions:
77+
# https://aka.ms/CreateIoTCentralApp
7778
# Add a device template with telemetry, properties and commands, as well as a view to visualize the
7879
# telemetry and execute commands, and a form to set properties.
7980
#
80-
# Next create a device using the device template, and select Connect to get the device connection details.
81+
# Next create a device using the device template, and select Connect to get the device connection
82+
# details.
8183
# Add the connection details to your secrets.py file, using the following values:
8284
#
8385
# 'id_scope' - the devices ID scope
@@ -86,7 +88,7 @@
8688
#
8789
# The adafruit-circuitpython-azureiot library depends on the following libraries:
8890
#
89-
# From the Adafruit CircuitPython Bundle (https://github.com/adafruit/Adafruit_CircuitPython_Bundle):
91+
# From the Adafruit CircuitPython Bundle https://github.com/adafruit/Adafruit_CircuitPython_Bundle:
9092
# * adafruit-circuitpython-minimqtt
9193
# * adafruit-circuitpython-requests
9294
# pylint: disable=wrong-import-position

0 commit comments

Comments
 (0)