Skip to content

Commit c784f19

Browse files
author
yanshay
committed
format
1 parent 311bf15 commit c784f19

1 file changed

Lines changed: 25 additions & 9 deletions

File tree

src/tag/spoolease/processor.py

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,33 @@ class SpooleaseTagProcessor(NdefTagProcessor):
1010
def __init__(self, config: dict):
1111
super().__init__(config)
1212

13-
def process_ndef(self, scan_result: ScanResult, ndef_records: list[NdefRecord]) -> GenericFilament | None:
13+
def process_ndef(
14+
self, scan_result: ScanResult, ndef_records: list[NdefRecord]
15+
) -> GenericFilament | None:
1416
for record in ndef_records:
1517
if record.tnf == 0x01 and record.type == "U":
1618
filament = self.__parse_spoolease_payload(record.payload)
1719
return filament
18-
1920
return None
2021

2122
def __parse_spoolease_payload(self, payload: bytes) -> GenericFilament | None:
2223
if payload is None or not isinstance(payload, (bytes, bytearray)):
23-
self.logger.error("SpoolEase payload parsing failed: Invalid payload parameter")
24+
self.logger.error(
25+
"SpoolEase payload parsing failed: Invalid payload parameter"
26+
)
2427
return None
2528

2629
try:
2730
url = self.__decode_uri_payload(payload)
2831
parsed = urllib.parse.urlparse(url)
2932

30-
if parsed.netloc.lower() != "tag.spoolease.io" or not parsed.path.startswith("/S1"):
31-
self.logger.error("SpoolEase payload parsing failed: Unsupported URL '%s'", url)
33+
if (
34+
parsed.netloc.lower() != "tag.spoolease.io"
35+
or not parsed.path.startswith("/S1")
36+
):
37+
self.logger.error(
38+
"SpoolEase payload parsing failed: Unsupported URL '%s'", url
39+
)
3240
return None
3341

3442
query = urllib.parse.parse_qs(parsed.query, keep_blank_values=False)
@@ -44,19 +52,25 @@ def __parse_spoolease_payload(self, payload: bytes) -> GenericFilament | None:
4452
weight_grams = self.__parse_optional_int(query, "WL", 1000)
4553

4654
if hotend_max_temp_c < hotend_min_temp_c:
47-
self.logger.error("SpoolEase payload parsing failed: Invalid temperature values")
55+
self.logger.error(
56+
"SpoolEase payload parsing failed: Invalid temperature values"
57+
)
4858
return None
4959

5060
colors = self.__parse_colors(color_field)
5161
extra_data = Constants.FILAMENT_TYPE_TO_EXTENDED_DATA.get(material)
5262

5363
bed_temp_c = extra_data.bed_temp_c if extra_data is not None else 0.0
5464
drying_temp_c = extra_data.drying_temp_c if extra_data is not None else 0.0
55-
drying_time_hours = extra_data.drying_time_hours if extra_data is not None else 0.0
65+
drying_time_hours = (
66+
extra_data.drying_time_hours if extra_data is not None else 0.0
67+
)
5668

5769
return GenericFilament(
5870
source_processor=self.name,
59-
unique_id=GenericFilament.generate_unique_id("SpoolEase", brand, material, subtype, *colors, weight_grams),
71+
unique_id=GenericFilament.generate_unique_id(
72+
"SpoolEase", brand, material, subtype, *colors, weight_grams
73+
),
6074
manufacturer=brand,
6175
type=material,
6276
modifiers=[subtype] if subtype else [],
@@ -91,7 +105,9 @@ def __parse_required_int(self, query: dict[str, list[str]], key: str) -> int:
91105
raise ValueError(f"Missing required field '{key}'")
92106
return int(values[0])
93107

94-
def __parse_optional_int(self, query: dict[str, list[str]], key: str, default: int) -> int:
108+
def __parse_optional_int(
109+
self, query: dict[str, list[str]], key: str, default: int
110+
) -> int:
95111
values = query.get(key)
96112
if not values or values[0] == "":
97113
return default

0 commit comments

Comments
 (0)