ruff config file. Merge main. remove duplicate 'of'.
This commit is contained in:
parent
ea7fb41be5
commit
7e70257a28
6 changed files with 125 additions and 60 deletions
|
|
@ -355,9 +355,7 @@ class PortalBase:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if self._alarm:
|
if self._alarm:
|
||||||
return self._alarm.time.TimeAlarm(
|
return self._alarm.time.TimeAlarm(monotonic_time=time.monotonic() + sleep_time)
|
||||||
monotonic_time=time.monotonic() + sleep_time
|
|
||||||
)
|
|
||||||
raise NotImplementedError(
|
raise NotImplementedError(
|
||||||
"Alarms not supported. Make sure you have the latest CircuitPython."
|
"Alarms not supported. Make sure you have the latest CircuitPython."
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -136,9 +136,7 @@ class GraphicsBase:
|
||||||
palette[1] = qr_color
|
palette[1] = qr_color
|
||||||
|
|
||||||
# bitmap the size of the matrix, plus border, monochrome (2 colors)
|
# bitmap the size of the matrix, plus border, monochrome (2 colors)
|
||||||
qr_bitmap = displayio.Bitmap(
|
qr_bitmap = displayio.Bitmap(qrcode.matrix.width + 2, qrcode.matrix.height + 2, 2)
|
||||||
qrcode.matrix.width + 2, qrcode.matrix.height + 2, 2
|
|
||||||
)
|
|
||||||
for i in range(qr_bitmap.width * qr_bitmap.height):
|
for i in range(qr_bitmap.width * qr_bitmap.height):
|
||||||
qr_bitmap[i] = 0
|
qr_bitmap[i] = 0
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,9 +38,7 @@ __version__ = "0.0.0+auto.0"
|
||||||
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_PortalBase.git"
|
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_PortalBase.git"
|
||||||
|
|
||||||
# you'll need to pass in an io username and key
|
# you'll need to pass in an io username and key
|
||||||
TIME_SERVICE = (
|
TIME_SERVICE = "https://io.adafruit.com/api/v2/%s/integrations/time/strftime?x-aio-key=%s"
|
||||||
"https://io.adafruit.com/api/v2/%s/integrations/time/strftime?x-aio-key=%s"
|
|
||||||
)
|
|
||||||
# our strftime is %Y-%m-%d %H:%M:%S.%L %j %u %z %Z see http://strftime.net/ for decoding details
|
# our strftime is %Y-%m-%d %H:%M:%S.%L %j %u %z %Z see http://strftime.net/ for decoding details
|
||||||
# See https://apidock.com/ruby/DateTime/strftime for full options
|
# See https://apidock.com/ruby/DateTime/strftime for full options
|
||||||
TIME_SERVICE_FORMAT = "%Y-%m-%d %H:%M:%S.%L %j %u %z %Z"
|
TIME_SERVICE_FORMAT = "%Y-%m-%d %H:%M:%S.%L %j %u %z %Z"
|
||||||
|
|
@ -146,9 +144,7 @@ class NetworkBase:
|
||||||
at a minimum in order to use network related features"""
|
at a minimum in order to use network related features"""
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
print(
|
print(f"{setting_name} not found. Please add this setting to settings.toml.")
|
||||||
f"{setting_name} not found. Please add this setting to settings.toml."
|
|
||||||
)
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def neo_status(self, value):
|
def neo_status(self, value):
|
||||||
|
|
@ -170,16 +166,12 @@ class NetworkBase:
|
||||||
"""
|
"""
|
||||||
value = json
|
value = json
|
||||||
if not isinstance(path, (list, tuple)):
|
if not isinstance(path, (list, tuple)):
|
||||||
raise ValueError(
|
raise ValueError("The json_path parameter should be enclosed in a list or tuple.")
|
||||||
"The json_path parameter should be enclosed in a list or tuple."
|
|
||||||
)
|
|
||||||
for x in path:
|
for x in path:
|
||||||
try:
|
try:
|
||||||
value = value[x]
|
value = value[x]
|
||||||
except (TypeError, KeyError, IndexError) as error:
|
except (TypeError, KeyError, IndexError) as error:
|
||||||
raise ValueError(
|
raise ValueError("The specified json_path was not found in the results.") from error
|
||||||
"The specified json_path was not found in the results."
|
|
||||||
) from error
|
|
||||||
gc.collect()
|
gc.collect()
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
@ -206,7 +198,7 @@ class NetworkBase:
|
||||||
Fetch a custom strftime relative to your location.
|
Fetch a custom strftime relative to your location.
|
||||||
|
|
||||||
:param str location: Your city and country, e.g. ``"America/New_York"``.
|
:param str location: Your city and country, e.g. ``"America/New_York"``.
|
||||||
:param max_attempts: The maximum number of of attempts to connect to WiFi before
|
:param max_attempts: The maximum number of attempts to connect to WiFi before
|
||||||
failing or use None to disable. Defaults to 10.
|
failing or use None to disable. Defaults to 10.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
@ -218,7 +210,9 @@ class NetworkBase:
|
||||||
aio_key = self._get_setting("AIO_KEY")
|
aio_key = self._get_setting("AIO_KEY")
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise KeyError(
|
raise KeyError(
|
||||||
"\n\nOur time service requires a login/password to rate-limit. Please register for a free adafruit.io account and place the user/key in your secrets file under 'AIO_USERNAME' and 'AIO_KEY'"
|
"\n\nOur time service requires a login/password to rate-limit. "
|
||||||
|
"Please register for a free adafruit.io account and place the user/key "
|
||||||
|
"in your secrets file under 'AIO_USERNAME' and 'AIO_KEY'"
|
||||||
) from KeyError
|
) from KeyError
|
||||||
|
|
||||||
if location is None:
|
if location is None:
|
||||||
|
|
@ -238,8 +232,7 @@ class NetworkBase:
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
print(response)
|
print(response)
|
||||||
error_message = (
|
error_message = (
|
||||||
"Error connecting to Adafruit IO. The response was: "
|
"Error connecting to Adafruit IO. The response was: " + response.text
|
||||||
+ response.text
|
|
||||||
)
|
)
|
||||||
self.neo_status(STATUS_HTTP_ERROR)
|
self.neo_status(STATUS_HTTP_ERROR)
|
||||||
raise RuntimeError(error_message)
|
raise RuntimeError(error_message)
|
||||||
|
|
@ -260,16 +253,15 @@ class NetworkBase:
|
||||||
|
|
||||||
def get_local_time(self, location=None, max_attempts=10):
|
def get_local_time(self, location=None, max_attempts=10):
|
||||||
"""
|
"""
|
||||||
Fetch and "set" the local time of this microcontroller to the local time at the location, using an internet time API.
|
Fetch and "set" the local time of this microcontroller to the local time at the location,
|
||||||
|
using an internet time API.
|
||||||
|
|
||||||
:param str location: Your city and country, e.g. ``"America/New_York"``.
|
:param str location: Your city and country, e.g. ``"America/New_York"``.
|
||||||
:param max_attempts: The maximum number of of attempts to connect to WiFi before
|
:param max_attempts: The maximum number of attempts to connect to WiFi before
|
||||||
failing or use None to disable. Defaults to 10.
|
failing or use None to disable. Defaults to 10.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
reply = self.get_strftime(
|
reply = self.get_strftime(TIME_SERVICE_FORMAT, location=location, max_attempts=max_attempts)
|
||||||
TIME_SERVICE_FORMAT, location=location, max_attempts=max_attempts
|
|
||||||
)
|
|
||||||
if reply:
|
if reply:
|
||||||
times = reply.split(" ")
|
times = reply.split(" ")
|
||||||
the_date = times[0]
|
the_date = times[0]
|
||||||
|
|
@ -319,9 +311,7 @@ class NetworkBase:
|
||||||
print("Date: {}".format(headers["date"]))
|
print("Date: {}".format(headers["date"]))
|
||||||
self.neo_status(STATUS_HTTP_ERROR) # red = http error
|
self.neo_status(STATUS_HTTP_ERROR) # red = http error
|
||||||
raise HttpError(
|
raise HttpError(
|
||||||
"Code {}: {}".format(
|
"Code {}: {}".format(response.status_code, response.reason.decode("utf-8")),
|
||||||
response.status_code, response.reason.decode("utf-8")
|
|
||||||
),
|
|
||||||
response,
|
response,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -340,10 +330,7 @@ class NetworkBase:
|
||||||
remaining -= len(i)
|
remaining -= len(i)
|
||||||
file.write(i)
|
file.write(i)
|
||||||
if self._debug:
|
if self._debug:
|
||||||
print(
|
print("Read %d bytes, %d remaining" % (content_length - remaining, remaining))
|
||||||
"Read %d bytes, %d remaining"
|
|
||||||
% (content_length - remaining, remaining)
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
print(".", end="")
|
print(".", end="")
|
||||||
if not remaining:
|
if not remaining:
|
||||||
|
|
@ -352,9 +339,7 @@ class NetworkBase:
|
||||||
|
|
||||||
response.close()
|
response.close()
|
||||||
stamp = time.monotonic() - stamp
|
stamp = time.monotonic() - stamp
|
||||||
print(
|
print("Created file of %d bytes in %0.1f seconds" % (os.stat(filename)[6], stamp))
|
||||||
"Created file of %d bytes in %0.1f seconds" % (os.stat(filename)[6], stamp)
|
|
||||||
)
|
|
||||||
self.neo_status(STATUS_OFF)
|
self.neo_status(STATUS_OFF)
|
||||||
if not content_length == os.stat(filename)[6]:
|
if not content_length == os.stat(filename)[6]:
|
||||||
raise RuntimeError
|
raise RuntimeError
|
||||||
|
|
@ -363,7 +348,7 @@ class NetworkBase:
|
||||||
"""
|
"""
|
||||||
Connect to WiFi using the settings found in secrets.py
|
Connect to WiFi using the settings found in secrets.py
|
||||||
|
|
||||||
:param max_attempts: The maximum number of of attempts to connect to WiFi before
|
:param max_attempts: The maximum number of attempts to connect to WiFi before
|
||||||
failing or use None to disable. Defaults to 10.
|
failing or use None to disable. Defaults to 10.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
@ -392,19 +377,12 @@ class NetworkBase:
|
||||||
while not self._wifi.is_connected:
|
while not self._wifi.is_connected:
|
||||||
# secrets dictionary must contain 'ssid' and 'password' at a minimum
|
# secrets dictionary must contain 'ssid' and 'password' at a minimum
|
||||||
print("Connecting to AP", secret_entry["ssid"])
|
print("Connecting to AP", secret_entry["ssid"])
|
||||||
if (
|
if secret_entry["ssid"] == "CHANGE ME" or secret_entry["password"] == "CHANGE ME":
|
||||||
secret_entry["ssid"] == "CHANGE ME"
|
|
||||||
or secret_entry["password"] == "CHANGE ME"
|
|
||||||
):
|
|
||||||
change_me = "\n" + "*" * 45
|
change_me = "\n" + "*" * 45
|
||||||
change_me += "\nPlease update the 'settings.toml' file on your\n"
|
change_me += "\nPlease update the 'settings.toml' file on your\n"
|
||||||
change_me += "CIRCUITPY drive to include your local WiFi\n"
|
change_me += "CIRCUITPY drive to include your local WiFi\n"
|
||||||
change_me += (
|
change_me += "access point SSID name in 'CIRCUITPY_WIFI_SSID' and SSID\n"
|
||||||
"access point SSID name in 'CIRCUITPY_WIFI_SSID' and SSID\n"
|
change_me += "password in 'CIRCUITPY_WIFI_PASSWORD'. Then save to reload!\n"
|
||||||
)
|
|
||||||
change_me += (
|
|
||||||
"password in 'CIRCUITPY_WIFI_PASSWORD'. Then save to reload!\n"
|
|
||||||
)
|
|
||||||
change_me += "*" * 45
|
change_me += "*" * 45
|
||||||
raise OSError(change_me)
|
raise OSError(change_me)
|
||||||
self._wifi.neo_status(STATUS_NO_CONNECTION) # red = not connected
|
self._wifi.neo_status(STATUS_NO_CONNECTION) # red = not connected
|
||||||
|
|
@ -425,9 +403,7 @@ class NetworkBase:
|
||||||
if self._wifi.is_connected:
|
if self._wifi.is_connected:
|
||||||
return
|
return
|
||||||
|
|
||||||
raise OSError(
|
raise OSError("Maximum number of attempts reached when trying to connect to WiFi")
|
||||||
"Maximum number of attempts reached when trying to connect to WiFi"
|
|
||||||
)
|
|
||||||
|
|
||||||
def _get_io_client(self):
|
def _get_io_client(self):
|
||||||
if self._io_client is not None:
|
if self._io_client is not None:
|
||||||
|
|
@ -609,9 +585,7 @@ class NetworkBase:
|
||||||
print("Date: {}".format(headers["date"]))
|
print("Date: {}".format(headers["date"]))
|
||||||
self.neo_status((100, 0, 0)) # red = http error
|
self.neo_status((100, 0, 0)) # red = http error
|
||||||
raise HttpError(
|
raise HttpError(
|
||||||
"Code {}: {}".format(
|
"Code {}: {}".format(response.status_code, response.reason.decode("utf-8")),
|
||||||
response.status_code, response.reason.decode("utf-8")
|
|
||||||
),
|
|
||||||
response,
|
response,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -62,9 +62,7 @@ class WiFi:
|
||||||
"""
|
"""
|
||||||
wifi.radio.connect(ssid, password)
|
wifi.radio.connect(ssid, password)
|
||||||
self.pool = socketpool.SocketPool(wifi.radio)
|
self.pool = socketpool.SocketPool(wifi.radio)
|
||||||
self.requests = adafruit_requests.Session(
|
self.requests = adafruit_requests.Session(self.pool, ssl.create_default_context())
|
||||||
self.pool, ssl.create_default_context()
|
|
||||||
)
|
|
||||||
self._connected = True
|
self._connected = True
|
||||||
|
|
||||||
def neo_status(self, value):
|
def neo_status(self, value):
|
||||||
|
|
|
||||||
|
|
@ -58,9 +58,7 @@ project = "Adafruit PortalBase Library"
|
||||||
creation_year = "2020"
|
creation_year = "2020"
|
||||||
current_year = str(datetime.datetime.now().year)
|
current_year = str(datetime.datetime.now().year)
|
||||||
year_duration = (
|
year_duration = (
|
||||||
current_year
|
current_year if current_year == creation_year else creation_year + " - " + current_year
|
||||||
if current_year == creation_year
|
|
||||||
else creation_year + " - " + current_year
|
|
||||||
)
|
)
|
||||||
copyright = year_duration + " Melissa LeBlanc-Williams"
|
copyright = year_duration + " Melissa LeBlanc-Williams"
|
||||||
author = "Melissa LeBlanc-Williams"
|
author = "Melissa LeBlanc-Williams"
|
||||||
|
|
|
||||||
99
ruff.toml
Normal file
99
ruff.toml
Normal file
|
|
@ -0,0 +1,99 @@
|
||||||
|
# SPDX-FileCopyrightText: 2024 Tim Cocks for Adafruit Industries
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
target-version = "py38"
|
||||||
|
line-length = 100
|
||||||
|
|
||||||
|
[lint]
|
||||||
|
select = ["I", "PL", "UP"]
|
||||||
|
|
||||||
|
extend-select = [
|
||||||
|
"D419", # empty-docstring
|
||||||
|
"E501", # line-too-long
|
||||||
|
"W291", # trailing-whitespace
|
||||||
|
"PLC0414", # useless-import-alias
|
||||||
|
"PLC2401", # non-ascii-name
|
||||||
|
"PLC2801", # unnecessary-dunder-call
|
||||||
|
"PLC3002", # unnecessary-direct-lambda-call
|
||||||
|
"E999", # syntax-error
|
||||||
|
"PLE0101", # return-in-init
|
||||||
|
"F706", # return-outside-function
|
||||||
|
"F704", # yield-outside-function
|
||||||
|
"PLE0116", # continue-in-finally
|
||||||
|
"PLE0117", # nonlocal-without-binding
|
||||||
|
"PLE0241", # duplicate-bases
|
||||||
|
"PLE0302", # unexpected-special-method-signature
|
||||||
|
"PLE0604", # invalid-all-object
|
||||||
|
"PLE0605", # invalid-all-format
|
||||||
|
"PLE0643", # potential-index-error
|
||||||
|
"PLE0704", # misplaced-bare-raise
|
||||||
|
"PLE1141", # dict-iter-missing-items
|
||||||
|
"PLE1142", # await-outside-async
|
||||||
|
"PLE1205", # logging-too-many-args
|
||||||
|
"PLE1206", # logging-too-few-args
|
||||||
|
"PLE1307", # bad-string-format-type
|
||||||
|
"PLE1310", # bad-str-strip-call
|
||||||
|
"PLE1507", # invalid-envvar-value
|
||||||
|
"PLE2502", # bidirectional-unicode
|
||||||
|
"PLE2510", # invalid-character-backspace
|
||||||
|
"PLE2512", # invalid-character-sub
|
||||||
|
"PLE2513", # invalid-character-esc
|
||||||
|
"PLE2514", # invalid-character-nul
|
||||||
|
"PLE2515", # invalid-character-zero-width-space
|
||||||
|
"PLR0124", # comparison-with-itself
|
||||||
|
"PLR0202", # no-classmethod-decorator
|
||||||
|
"PLR0203", # no-staticmethod-decorator
|
||||||
|
"UP004", # useless-object-inheritance
|
||||||
|
"PLR0206", # property-with-parameters
|
||||||
|
"PLR0904", # too-many-public-methods
|
||||||
|
"PLR0911", # too-many-return-statements
|
||||||
|
"PLR0912", # too-many-branches
|
||||||
|
"PLR0913", # too-many-arguments
|
||||||
|
"PLR0914", # too-many-locals
|
||||||
|
"PLR0915", # too-many-statements
|
||||||
|
"PLR0916", # too-many-boolean-expressions
|
||||||
|
"PLR1702", # too-many-nested-blocks
|
||||||
|
"PLR1704", # redefined-argument-from-local
|
||||||
|
"PLR1711", # useless-return
|
||||||
|
"C416", # unnecessary-comprehension
|
||||||
|
"PLR1733", # unnecessary-dict-index-lookup
|
||||||
|
"PLR1736", # unnecessary-list-index-lookup
|
||||||
|
|
||||||
|
# ruff reports this rule is unstable
|
||||||
|
#"PLR6301", # no-self-use
|
||||||
|
|
||||||
|
"PLW0108", # unnecessary-lambda
|
||||||
|
"PLW0120", # useless-else-on-loop
|
||||||
|
"PLW0127", # self-assigning-variable
|
||||||
|
"PLW0129", # assert-on-string-literal
|
||||||
|
"B033", # duplicate-value
|
||||||
|
"PLW0131", # named-expr-without-context
|
||||||
|
"PLW0245", # super-without-brackets
|
||||||
|
"PLW0406", # import-self
|
||||||
|
"PLW0602", # global-variable-not-assigned
|
||||||
|
"PLW0603", # global-statement
|
||||||
|
"PLW0604", # global-at-module-level
|
||||||
|
|
||||||
|
# fails on the try: import typing used by libraries
|
||||||
|
#"F401", # unused-import
|
||||||
|
|
||||||
|
"F841", # unused-variable
|
||||||
|
"E722", # bare-except
|
||||||
|
"PLW0711", # binary-op-exception
|
||||||
|
"PLW1501", # bad-open-mode
|
||||||
|
"PLW1508", # invalid-envvar-default
|
||||||
|
"PLW1509", # subprocess-popen-preexec-fn
|
||||||
|
"PLW2101", # useless-with-lock
|
||||||
|
"PLW3301", # nested-min-max
|
||||||
|
]
|
||||||
|
|
||||||
|
ignore = [
|
||||||
|
"PLR2004", # magic-value-comparison
|
||||||
|
"UP030", # format literals
|
||||||
|
"PLW1514", # unspecified-encoding
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
[format]
|
||||||
|
line-ending = "lf"
|
||||||
Loading…
Reference in a new issue