Skip to content

Commit 526356e

Browse files
committed
Fixed pylint failures - mostly line-too-long
1 parent b3a9086 commit 526356e

File tree

7 files changed

+94
-52
lines changed

7 files changed

+94
-52
lines changed

adafruit_azureiot/__init__.py

Lines changed: 2 additions & 1 deletion
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

Lines changed: 4 additions & 2 deletions
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

Lines changed: 8 additions & 4 deletions
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+
f" - 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+
f"$dps/registrations/GET/iotdps-get-operationstatus/?$rid="
153+
f"{self._device_id}&operationId={self._operation_id}",
152154
message,
153155
)
154156

@@ -176,15 +178,17 @@ 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 = (f"{self._id_scope}/registrations/{self._device_id}/api-version="
182+
f"{constants.DPS_API_VERSION}")
180183

181184
# pylint: disable=C0103
182185
sr = self._id_scope + "%2Fregistrations%2F" + self._device_id
183186
sig_no_encode = compute_derived_symmetric_key(
184187
self._device_sas_key, sr + "\n" + str(expiry)
185188
)
186189
sig_encoded = quote(sig_no_encode, "~()*!.'")
187-
auth_string = f"SharedAccessSignature sr={sr}&sig={sig_encoded}&se={expiry}&skn=registration"
190+
auth_string = (f"SharedAccessSignature sr={sr}&sig={sig_encoded}&se={expiry}"
191+
f"&skn=registration")
188192

189193
MQTT.set_socket(self._socket, self._iface)
190194

adafruit_azureiot/hmac.py

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,32 @@ def sha_init() -> dict:
6565
return sha_info
6666

6767

68-
ROR = (
69-
lambda x, y: (((x & 0xFFFFFFFF) >> (y & 31)) | (x << (32 - (y & 31)))) & 0xFFFFFFFF
70-
)
71-
Ch = lambda x, y, z: (z ^ (x & (y ^ z)))
72-
Maj = lambda x, y, z: (((x | y) & z) | (x & y))
73-
S = lambda x, n: ROR(x, n)
74-
R = lambda x, n: (x & 0xFFFFFFFF) >> n
75-
Sigma0 = lambda x: (S(x, 2) ^ S(x, 13) ^ S(x, 22))
76-
Sigma1 = lambda x: (S(x, 6) ^ S(x, 11) ^ S(x, 25))
77-
Gamma0 = lambda x: (S(x, 7) ^ S(x, 18) ^ R(x, 3))
78-
Gamma1 = lambda x: (S(x, 17) ^ S(x, 19) ^ R(x, 10))
68+
def ROR(x, y):
69+
return (((x & 0xFFFFFFFF) >> (y & 31)) | (x << (32 - (y & 31)))) & 0xFFFFFFFF
70+
71+
def Ch(x, y, z):
72+
return (z ^ (x & (y ^ z)))
73+
74+
def Maj(x, y, z):
75+
return (((x | y) & z) | (x & y))
76+
77+
def S(x, n):
78+
return ROR(x, n)
79+
80+
def R(x, n):
81+
return (x & 0xFFFFFFFF) >> n
82+
83+
def Sigma0(x):
84+
return (S(x, 2) ^ S(x, 13) ^ S(x, 22))
85+
86+
def Sigma1(x):
87+
return (S(x, 6) ^ S(x, 11) ^ S(x, 25))
88+
89+
def Gamma0(x):
90+
return (S(x, 7) ^ S(x, 18) ^ R(x, 3))
91+
92+
def Gamma1(x):
93+
return (S(x, 17) ^ S(x, 19) ^ R(x, 10))
7994

8095

8196
def sha_transform(sha_info: dict) -> None:

adafruit_azureiot/iot_mqtt.py

Lines changed: 6 additions & 3 deletions
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
@@ -122,7 +123,8 @@ def _create_mqtt_client(self) -> None:
122123

123124
self._logger.debug(
124125
str.replace(
125-
f"- iot_mqtt :: _on_connect :: username = {self._username}, password = {self._passwd}",
126+
f"- iot_mqtt :: _on_connect :: username = {self._username}, password ="
127+
f"{self._passwd}",
126128
"%",
127129
"%%",
128130
)
@@ -334,7 +336,8 @@ def __init__(
334336
:param IoTMQTTCallback callback: A callback class
335337
:param socket: The socket to communicate over
336338
: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
339+
:param str hostname: The hostname of the MQTT broker to connect to, get this by registering
340+
the device
338341
:param str device_id: The device ID of the device to register
339342
:param str device_sas_key: The primary or secondary key of the device to register
340343
:param int token_expires: The number of seconds till the token expires, defaults to 6 hours

adafruit_azureiot/iotcentral_device.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -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

0 commit comments

Comments
 (0)