Skip to content

Fixed pylint failures - mostly line-too-long #54

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion adafruit_azureiot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@

**With Native Networking**

* CircuitPython's Wifi Module: https://docs.circuitpython.org/en/latest/shared-bindings/wifi/index.html
* CircuitPython's Wifi Module:
https://docs.circuitpython.org/en/latest/shared-bindings/wifi/index.html
* Adafruit's Requests Library: https://github.com/adafruit/Adafruit_CircuitPython_Requests/
"""

Expand Down
6 changes: 4 additions & 2 deletions adafruit_azureiot/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
`constants`
================================================================================

This file is for maintaining Microsoft Azure IoT constants that could be changed or added to over time for different scenarios
This file is for maintaining Microsoft Azure IoT constants that could be changed or added to over
time for different scenarios

* Author(s): Jim Bennett, Elena Horton
"""
Expand All @@ -18,5 +19,6 @@
# The version of the Azure Device Provisioning Service this code is built against
DPS_API_VERSION = "2019-03-31"

# The Azure Device Provisioning service endpoint that this library uses to provision IoT Central devices
# The Azure Device Provisioning service endpoint that this library uses to provision IoT Central
# devices
DPS_END_POINT = "global.azure-devices-provisioning.net"
16 changes: 12 additions & 4 deletions adafruit_azureiot/device_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ def _connect_to_mqtt(self) -> None:
self._mqtt.loop()

self._logger.info(
f" - device_registration :: connect :: on_connect must be fired. Connected ? {self._mqtt.is_connected()}"
" - device_registration :: connect :: on_connect must be fired. Connected ?"
f"{self._mqtt.is_connected()}"
)

if not self._mqtt.is_connected():
Expand Down Expand Up @@ -148,7 +149,8 @@ def _start_registration(self) -> None:
def _wait_for_operation(self) -> None:
message = json.dumps({"operationId": self._operation_id})
self._mqtt.publish(
f"$dps/registrations/GET/iotdps-get-operationstatus/?$rid={self._device_id}&operationId={self._operation_id}",
"$dps/registrations/GET/iotdps-get-operationstatus/?$rid="
f"{self._device_id}&operationId={self._operation_id}",
message,
)

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

username = f"{self._id_scope}/registrations/{self._device_id}/api-version={constants.DPS_API_VERSION}"
username = (
f"{self._id_scope}/registrations/{self._device_id}/api-version="
+ f"{constants.DPS_API_VERSION}"
)

# pylint: disable=C0103
sr = self._id_scope + "%2Fregistrations%2F" + self._device_id
sig_no_encode = compute_derived_symmetric_key(
self._device_sas_key, sr + "\n" + str(expiry)
)
sig_encoded = quote(sig_no_encode, "~()*!.'")
auth_string = f"SharedAccessSignature sr={sr}&sig={sig_encoded}&se={expiry}&skn=registration"
auth_string = (
f"SharedAccessSignature sr={sr}&sig={sig_encoded}&se={expiry}"
"&skn=registration"
)

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

Expand Down
2 changes: 1 addition & 1 deletion adafruit_azureiot/hmac.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

"""

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

try:
from typing import Union
Expand Down
13 changes: 9 additions & 4 deletions adafruit_azureiot/iot_mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ class IoTResponse:
def __init__(self, code: int, message: str):
"""Creates an IoT Response object

:param int code: The HTTP response code for this method call, for example 200 if the method was handled successfully
:param int code: The HTTP response code for this method call, for example 200 if the method
was handled successfully
:param str message: The HTTP response message for this method call
"""
self.response_code = code
Expand Down Expand Up @@ -120,9 +121,12 @@ def _gen_sas_token(self) -> str:
def _create_mqtt_client(self) -> None:
MQTT.set_socket(self._socket, self._iface)

log_text = (
f"- iot_mqtt :: _on_connect :: username = {self._username}, password = "
+ f"{self._passwd}"
)
self._logger.debug(
str.replace(
f"- iot_mqtt :: _on_connect :: username = {self._username}, password = {self._passwd}",
log_text.replace(
"%",
"%%",
)
Expand Down Expand Up @@ -334,7 +338,8 @@ def __init__(
:param IoTMQTTCallback callback: A callback class
:param socket: The socket to communicate over
:param iface: The network interface to communicate over
:param str hostname: The hostname of the MQTT broker to connect to, get this by registering the device
:param str hostname: The hostname of the MQTT broker to connect to, get this by registering
the device
:param str device_id: The device ID of the device to register
:param str device_sas_key: The primary or secondary key of the device to register
:param int token_expires: The number of seconds till the token expires, defaults to 6 hours
Expand Down
18 changes: 11 additions & 7 deletions adafruit_azureiot/iotcentral_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from .iot_mqtt import IoTMQTT, IoTMQTTCallback, IoTResponse


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

def connection_status_change(self, connected: bool) -> None:
Expand Down Expand Up @@ -120,23 +120,27 @@ def __init__(
self._mqtt = None

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

self.on_command_executed = None
"""A callback method that is called when a command is executed on the device. This method should have the following signature:
"""A callback method that is called when a command is executed on the device.
This method should have the following signature:
def connection_status_changed(method_name: str, payload: str) -> IoTResponse:

This method returns an IoTResponse containing a status code and message from the command call. Set this appropriately
depending on if the command was successfully handled or not. For example, if the command was handled successfully, set
the code to 200 and message to "OK":
This method returns an IoTResponse containing a status code and message from the command
call. Set this appropriately depending on if the command was successfully handled or not.
For example, if the command was handled successfully, set the code to 200 and message to
"OK":

return IoTResponse(200, "OK")
"""

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

Expand Down
67 changes: 40 additions & 27 deletions adafruit_azureiot/iothub_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def _validate_keys(connection_string_parts: Mapping) -> None:
]


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

def connection_status_change(self, connected: bool) -> None:
Expand Down Expand Up @@ -135,7 +135,7 @@ def device_twin_reported_updated(
reported_property_name, reported_property_value, reported_version
)

def __init__(
def __init__( # pylint: disable=too-many-arguments
self,
socket,
iface,
Expand Down Expand Up @@ -168,7 +168,8 @@ def __init__(
)
except (ValueError, AttributeError) as e:
raise ValueError(
"Connection string is required and should not be empty or blank and must be supplied as a string"
"Connection string is required and should not be empty or blank and must be"
"supplied as a string"
) from e

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

@property
def on_connection_status_changed(self) -> Callable:
"""A callback method that is called when the connection status is changed. This method should have the following signature:
"""A callback method that is called when the connection status is changed.
This method should have the following signature:
def connection_status_changed(connected: bool) -> None
"""
return self._on_connection_status_changed
Expand All @@ -203,40 +205,46 @@ def connection_status_changed(connected: bool) -> None
def on_connection_status_changed(
self, new_on_connection_status_changed: Callable
) -> None:
"""A callback method that is called when the connection status is changed. This method should have the following signature:
"""A callback method that is called when the connection status is changed.
This method should have the following signature:
def connection_status_changed(connected: bool) -> None
"""
self._on_connection_status_changed = new_on_connection_status_changed

@property
def on_direct_method_invoked(self) -> Callable:
"""A callback method that is called when a direct method is invoked. This method should have the following signature:
"""A callback method that is called when a direct method is invoked.
This method should have the following signature:
def direct_method_invoked(method_name: str, payload: str) -> IoTResponse:

This method returns an IoTResponse containing a status code and message from the method invocation. Set this appropriately
depending on if the method was successfully handled or not. For example, if the method was handled successfully, set
the code to 200 and message to "OK":
This method returns an IoTResponse containing a status code and message from the method
invocation. Set this appropriately depending on if the method was successfully handled or
not. For example, if the method was handled successfully, set the code to 200 and message
to "OK":

return IoTResponse(200, "OK")
"""
return self._on_direct_method_invoked

@on_direct_method_invoked.setter
def on_direct_method_invoked(self, new_on_direct_method_invoked: Callable) -> None:
"""A callback method that is called when a direct method is invoked. This method should have the following signature:
"""A callback method that is called when a direct method is invoked.
This method should have the following signature:
def direct_method_invoked(method_name: str, payload: str) -> IoTResponse:

This method returns an IoTResponse containing a status code and message from the method invocation. Set this appropriately
depending on if the method was successfully handled or not. For example, if the method was handled successfully, set
the code to 200 and message to "OK":
This method returns an IoTResponse containing a status code and message from the method
invocation. Set this appropriately depending on if the method was successfully handled or
not. For example, if the method was handled successfully, set the code to 200 and message
to "OK":

return IoTResponse(200, "OK")
"""
self._on_direct_method_invoked = new_on_direct_method_invoked

@property
def on_cloud_to_device_message_received(self) -> Callable:
"""A callback method that is called when a cloud to device message is received. This method should have the following signature:
"""A callback method that is called when a cloud to device message is received.
This method should have the following signature:
def cloud_to_device_message_received(body: str, properties: dict) -> None:
"""
return self._on_cloud_to_device_message_received
Expand All @@ -245,7 +253,8 @@ def cloud_to_device_message_received(body: str, properties: dict) -> None:
def on_cloud_to_device_message_received(
self, new_on_cloud_to_device_message_received: Callable
) -> None:
"""A callback method that is called when a cloud to device message is received. This method should have the following signature:
"""A callback method that is called when a cloud to device message is received.
This method should have the following signature:
def cloud_to_device_message_received(body: str, properties: dict) -> None:
"""
self._on_cloud_to_device_message_received = (
Expand All @@ -254,19 +263,21 @@ def cloud_to_device_message_received(body: str, properties: dict) -> None:

@property
def on_device_twin_desired_updated(self) -> Callable:
"""A callback method that is called when the desired properties of the devices device twin are updated.
This method should have the following signature:
def device_twin_desired_updated(desired_property_name: str, desired_property_value, desired_version: int) -> None:
"""A callback method that is called when the desired properties of the devices device twin
are updated. This method should have the following signature:
def device_twin_desired_updated(desired_property_name: str, desired_property_value,
desired_version: int) -> None:
"""
return self._on_device_twin_desired_updated

@on_device_twin_desired_updated.setter
def on_device_twin_desired_updated(
self, new_on_device_twin_desired_updated: Callable
) -> None:
"""A callback method that is called when the desired properties of the devices device twin are updated.
This method should have the following signature:
def device_twin_desired_updated(desired_property_name: str, desired_property_value, desired_version: int) -> None:
"""A callback method that is called when the desired properties of the devices device twin
are updated. This method should have the following signature:
def device_twin_desired_updated(desired_property_name: str, desired_property_value,
desired_version: int) -> None:
"""
self._on_device_twin_desired_updated = new_on_device_twin_desired_updated

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

@property
def on_device_twin_reported_updated(self) -> Callable:
"""A callback method that is called when the reported properties of the devices device twin are updated.
This method should have the following signature:
def device_twin_reported_updated(reported_property_name: str, reported_property_value, reported_version: int) -> None:
"""A callback method that is called when the reported properties of the devices device twin
are updated. This method should have the following signature:
def device_twin_reported_updated(reported_property_name: str, reported_property_value,
reported_version: int) -> None:
"""
return self._on_device_twin_reported_updated

@on_device_twin_reported_updated.setter
def on_device_twin_reported_updated(
self, new_on_device_twin_reported_updated: Callable
) -> None:
"""A callback method that is called when the reported properties of the devices device twin are updated.
This method should have the following signature:
def device_twin_reported_updated(reported_property_name: str, reported_property_value, reported_version: int) -> None:
"""A callback method that is called when the reported properties of the devices device twin
are updated. This method should have the following signature:
def device_twin_reported_updated(reported_property_name: str, reported_property_value,
reported_version: int) -> None:
"""
self._on_device_twin_reported_updated = new_on_device_twin_reported_updated

Expand Down
8 changes: 5 additions & 3 deletions examples/azureiot_esp32spi/azureiot_central_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,13 @@
# If you are not a student, head to https://aka.ms/FreeAz and sign up to get $200 of credit for 30
# days, as well as free tiers of a load of services
#
# Create an Azure IoT Central app by following these instructions: https://aka.ms/CreateIoTCentralApp
# Create an Azure IoT Central app by following these instructions:
# https://aka.ms/CreateIoTCentralApp
# Add a device template with telemetry, properties and commands, as well as a view to visualize the
# telemetry and execute commands, and a form to set properties.
#
# Next create a device using the device template, and select Connect to get the device connection details.
# Next create a device using the device template, and select Connect to get the device connection
# details.
# Add the connection details to your secrets.py file, using the following values:
#
# 'id_scope' - the devices ID scope
Expand All @@ -92,7 +94,7 @@
#
# The adafruit-circuitpython-azureiot library depends on the following libraries:
#
# From the Adafruit CircuitPython Bundle (https://github.com/adafruit/Adafruit_CircuitPython_Bundle):
# From the Adafruit CircuitPython Bundle https://github.com/adafruit/Adafruit_CircuitPython_Bundle:
# * adafruit-circuitpython-minimqtt
# * adafruit-circuitpython-requests
# pylint: disable=wrong-import-position
Expand Down
8 changes: 5 additions & 3 deletions examples/azureiot_esp32spi/azureiot_central_notconnected.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,13 @@
# If you are not a student, head to https://aka.ms/FreeAz and sign up to get $200 of credit for 30
# days, as well as free tiers of a load of services
#
# Create an Azure IoT Central app by following these instructions: https://aka.ms/CreateIoTCentralApp
# Create an Azure IoT Central app by following these instructions:
# https://aka.ms/CreateIoTCentralApp
# Add a device template with telemetry, properties and commands, as well as a view to visualize the
# telemetry and execute commands, and a form to set properties.
#
# Next create a device using the device template, and select Connect to get the device connection details.
# Next create a device using the device template, and select Connect to get the device connection
# details.
# Add the connection details to your secrets.py file, using the following values:
#
# 'id_scope' - the devices ID scope
Expand All @@ -86,7 +88,7 @@
#
# The adafruit-circuitpython-azureiot library depends on the following libraries:
#
# From the Adafruit CircuitPython Bundle (https://github.com/adafruit/Adafruit_CircuitPython_Bundle):
# From the Adafruit CircuitPython Bundle https://github.com/adafruit/Adafruit_CircuitPython_Bundle:
# * adafruit-circuitpython-minimqtt
# * adafruit-circuitpython-requests
# pylint: disable=wrong-import-position
Expand Down
Loading