Skip to content

Commit f296b43

Browse files
committed
fix ruff warnings
1 parent 0bbfc5b commit f296b43

File tree

2 files changed

+40
-45
lines changed

2 files changed

+40
-45
lines changed

tests/stick_test_data.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
for x in range(168):
1616
delta_month = hour_timestamp - hour_timestamp.replace(day=1, hour=0)
1717
LOG_TIMESTAMPS[x] = (
18-
bytes(("%%0%dX" % 2) % (hour_timestamp.year - 2000), pw_constants.UTF8)
19-
+ bytes(("%%0%dX" % 2) % hour_timestamp.month, pw_constants.UTF8)
18+
bytes(("%%0%dX" % 2) % (hour_timestamp.year - 2000), pw_constants.UTF8) # noqa: UP031
19+
+ bytes(("%%0%dX" % 2) % hour_timestamp.month, pw_constants.UTF8) # noqa: UP031
2020
+ bytes(
21-
("%%0%dX" % 4)
21+
("%%0%dX" % 4) # noqa: UP031
2222
% int((delta_month.days * 1440) + (delta_month.seconds / 60)),
2323
pw_constants.UTF8,
2424
)
@@ -594,23 +594,23 @@
594594
b"000000C1", # Success ack
595595
b"003A" # msg_id
596596
+ b"0098765432101234" # mac
597-
+ bytes(("%%0%dd" % 2) % utc_now.second, pw_constants.UTF8)
598-
+ bytes(("%%0%dd" % 2) % utc_now.minute, pw_constants.UTF8)
599-
+ bytes(("%%0%dd" % 2) % utc_now.hour, pw_constants.UTF8)
600-
+ bytes(("%%0%dd" % 2) % utc_now.weekday(), pw_constants.UTF8)
601-
+ bytes(("%%0%dd" % 2) % utc_now.day, pw_constants.UTF8)
602-
+ bytes(("%%0%dd" % 2) % utc_now.month, pw_constants.UTF8)
603-
+ bytes(("%%0%dd" % 2) % (utc_now.year - 2000), pw_constants.UTF8),
597+
+ bytes(("%%0%dd" % 2) % utc_now.second, pw_constants.UTF8) # noqa: UP031
598+
+ bytes(("%%0%dd" % 2) % utc_now.minute, pw_constants.UTF8) # noqa: UP031
599+
+ bytes(("%%0%dd" % 2) % utc_now.hour, pw_constants.UTF8) # noqa: UP031
600+
+ bytes(("%%0%dd" % 2) % utc_now.weekday(), pw_constants.UTF8) # noqa: UP031
601+
+ bytes(("%%0%dd" % 2) % utc_now.day, pw_constants.UTF8) # noqa: UP031
602+
+ bytes(("%%0%dd" % 2) % utc_now.month, pw_constants.UTF8) # noqa: UP031
603+
+ bytes(("%%0%dd" % 2) % (utc_now.year - 2000), pw_constants.UTF8), # noqa: UP031
604604
),
605605
b"\x05\x05\x03\x03003E11111111111111111B8A\r\n": (
606606
"clock for 0011111111111111",
607607
b"000000C1", # Success ack
608608
b"003F" # msg_id
609609
+ b"1111111111111111" # mac
610-
+ bytes(("%%0%dX" % 2) % utc_now.hour, pw_constants.UTF8)
611-
+ bytes(("%%0%dX" % 2) % utc_now.minute, pw_constants.UTF8)
612-
+ bytes(("%%0%dX" % 2) % utc_now.second, pw_constants.UTF8)
613-
+ bytes(("%%0%dX" % 2) % utc_now.weekday(), pw_constants.UTF8)
610+
+ bytes(("%%0%dX" % 2) % utc_now.hour, pw_constants.UTF8) # noqa: UP031
611+
+ bytes(("%%0%dX" % 2) % utc_now.minute, pw_constants.UTF8) # noqa: UP031
612+
+ bytes(("%%0%dX" % 2) % utc_now.second, pw_constants.UTF8) # noqa: UP031
613+
+ bytes(("%%0%dX" % 2) % utc_now.weekday(), pw_constants.UTF8) # noqa: UP031
614614
+ b"00" # unknown
615615
+ b"0000", # unknown2
616616
),
@@ -619,10 +619,10 @@
619619
b"000000C1", # Success ack
620620
b"003F" # msg_id
621621
+ b"2222222222222222" # mac
622-
+ bytes(("%%0%dX" % 2) % utc_now.hour, pw_constants.UTF8)
623-
+ bytes(("%%0%dX" % 2) % utc_now.minute, pw_constants.UTF8)
624-
+ bytes(("%%0%dX" % 2) % utc_now.second, pw_constants.UTF8)
625-
+ bytes(("%%0%dX" % 2) % utc_now.weekday(), pw_constants.UTF8)
622+
+ bytes(("%%0%dX" % 2) % utc_now.hour, pw_constants.UTF8) # noqa: UP031
623+
+ bytes(("%%0%dX" % 2) % utc_now.minute, pw_constants.UTF8) # noqa: UP031
624+
+ bytes(("%%0%dX" % 2) % utc_now.second, pw_constants.UTF8) # noqa: UP031
625+
+ bytes(("%%0%dX" % 2) % utc_now.weekday(), pw_constants.UTF8) # noqa: UP031
626626
+ b"00" # unknown
627627
+ b"0000", # unknown2
628628
),
@@ -631,10 +631,10 @@
631631
b"000000C1", # Success ack
632632
b"003F" # msg_id
633633
+ b"3333333333333333" # mac
634-
+ bytes(("%%0%dX" % 2) % utc_now.hour, pw_constants.UTF8)
635-
+ bytes(("%%0%dX" % 2) % utc_now.minute, pw_constants.UTF8)
636-
+ bytes(("%%0%dX" % 2) % utc_now.second, pw_constants.UTF8)
637-
+ bytes(("%%0%dX" % 2) % utc_now.weekday(), pw_constants.UTF8)
634+
+ bytes(("%%0%dX" % 2) % utc_now.hour, pw_constants.UTF8) # noqa: UP031
635+
+ bytes(("%%0%dX" % 2) % utc_now.minute, pw_constants.UTF8) # noqa: UP031
636+
+ bytes(("%%0%dX" % 2) % utc_now.second, pw_constants.UTF8) # noqa: UP031
637+
+ bytes(("%%0%dX" % 2) % utc_now.weekday(), pw_constants.UTF8) # noqa: UP031
638638
+ b"00" # unknown
639639
+ b"0000", # unknown2
640640
),
@@ -643,10 +643,10 @@
643643
b"000000C1", # Success ack
644644
b"003F" # msg_id
645645
+ b"4444444444444444" # mac
646-
+ bytes(("%%0%dX" % 2) % utc_now.hour, pw_constants.UTF8)
647-
+ bytes(("%%0%dX" % 2) % utc_now.minute, pw_constants.UTF8)
648-
+ bytes(("%%0%dX" % 2) % utc_now.second, pw_constants.UTF8)
649-
+ bytes(("%%0%dX" % 2) % utc_now.weekday(), pw_constants.UTF8)
646+
+ bytes(("%%0%dX" % 2) % utc_now.hour, pw_constants.UTF8) # noqa: UP031
647+
+ bytes(("%%0%dX" % 2) % utc_now.minute, pw_constants.UTF8) # noqa: UP031
648+
+ bytes(("%%0%dX" % 2) % utc_now.second, pw_constants.UTF8) # noqa: UP031
649+
+ bytes(("%%0%dX" % 2) % utc_now.weekday(), pw_constants.UTF8) # noqa: UP031
650650
+ b"00" # unknown
651651
+ b"0000", # unknown2
652652
),

tests/test_usb.py

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ async def mock_connection(
205205
class MockOsPath:
206206
"""Mock aiofiles.path class."""
207207

208-
async def exists(self, file_or_path: str) -> bool:
208+
async def exists(self, file_or_path: str) -> bool: # noqa: PLR0911
209209
"""Exists folder."""
210210
if file_or_path == "mock_folder_that_exists":
211211
return True
@@ -285,7 +285,6 @@ async def dummy_fn(self, request: pw_requests.PlugwiseRequest, test: bool) -> No
285285
@pytest.mark.asyncio
286286
async def test_sorting_request_messages(self) -> None:
287287
"""Test request message priority sorting."""
288-
289288
node_add_request = pw_requests.NodeAddRequest(
290289
self.dummy_fn, b"1111222233334444", True
291290
)
@@ -329,7 +328,6 @@ async def test_sorting_request_messages(self) -> None:
329328
@pytest.mark.asyncio
330329
async def test_msg_properties(self) -> None:
331330
"""Test message properties."""
332-
333331
# UnixTimestamp
334332
unix_timestamp = pw_msg_properties.UnixTimestamp(
335333
dt(2011, 6, 27, 9, 4, 10, tzinfo=UTC), 8
@@ -585,7 +583,7 @@ async def test_stick_node_discovered_subscription(
585583
)
586584
assert stick.nodes["5555555555555555"].node_info.version == "080007"
587585
assert stick.nodes["5555555555555555"].node_info.model == "Scan"
588-
assert stick.nodes["5555555555555555"].node_info.model_type == None
586+
assert stick.nodes["5555555555555555"].node_info.model_type is None
589587
assert stick.nodes["5555555555555555"].available
590588
assert stick.nodes["5555555555555555"].node_info.is_battery_powered
591589
assert sorted(stick.nodes["5555555555555555"].features) == sorted(
@@ -752,7 +750,7 @@ async def node_init_relay_state(
752750
)
753751

754752
@pytest.mark.asyncio
755-
async def test_node_relay_and_power(self, monkeypatch: pytest.MonkeyPatch) -> None:
753+
async def test_node_relay_and_power(self, monkeypatch: pytest.MonkeyPatch) -> None: # noqa: PLR0915
756754
"""Testing discovery of nodes."""
757755
mock_serial = MockSerial(None)
758756
monkeypatch.setattr(
@@ -954,7 +952,7 @@ async def fake_get_missing_energy_logs(address: int) -> None:
954952
await stick.disconnect()
955953

956954
@freeze_time("2025-04-03 22:00:00")
957-
def test_pulse_collection_consumption(
955+
def test_pulse_collection_consumption( # noqa: PLR0915
958956
self, monkeypatch: pytest.MonkeyPatch
959957
) -> None:
960958
"""Testing pulse collection class."""
@@ -1216,7 +1214,6 @@ def test_pulse_collection_consumption_empty(
12161214
@freeze_time(dt.now())
12171215
def test_pulse_collection_production(self, monkeypatch: pytest.MonkeyPatch) -> None:
12181216
"""Testing pulse collection class."""
1219-
12201217
# Set log hours to 1 week
12211218
monkeypatch.setattr(pw_energy_pulses, "MAX_LOG_HOURS", 168)
12221219

@@ -1290,7 +1287,6 @@ def test_pulse_collection_production(self, monkeypatch: pytest.MonkeyPatch) -> N
12901287
@freeze_time(dt.now())
12911288
def test_log_address_rollover(self, monkeypatch: pytest.MonkeyPatch) -> None:
12921289
"""Test log address rollover."""
1293-
12941290
# Set log hours to 25
12951291
monkeypatch.setattr(pw_energy_pulses, "MAX_LOG_HOURS", 24)
12961292

@@ -1535,7 +1531,7 @@ def os_path_join(self, str_a: str, str_b: str) -> str:
15351531
return f"{str_a}/{str_b}"
15361532

15371533
@pytest.mark.asyncio
1538-
async def test_cache(self, monkeypatch: pytest.MonkeyPatch) -> None:
1534+
async def test_cache(self, monkeypatch: pytest.MonkeyPatch) -> None: # noqa: PLR0915
15391535
"""Test PlugwiseCache class."""
15401536
monkeypatch.setattr(pw_helpers_cache, "os_name", "nt")
15411537
monkeypatch.setattr(pw_helpers_cache, "os_getenv", self.fake_env)
@@ -1791,9 +1787,8 @@ async def test_node_cache(self, monkeypatch: pytest.MonkeyPatch) -> None:
17911787
)
17921788

17931789
@pytest.mark.asyncio
1794-
async def test_base_node(self, monkeypatch: pytest.MonkeyPatch) -> None:
1790+
async def test_base_node(self, monkeypatch: pytest.MonkeyPatch) -> None: # noqa: PLR0915
17951791
"""Testing properties of base node."""
1796-
17971792
mock_stick_controller = MockStickController()
17981793

17991794
async def load_callback(event: pw_api.NodeEvent, mac: str) -> None: # type: ignore[name-defined]
@@ -1907,10 +1902,10 @@ async def load_callback(event: pw_api.NodeEvent, mac: str) -> None: # type: ign
19071902
assert test_node.mac == "1298347650AFBECD"
19081903

19091904
@pytest.mark.asyncio
1910-
async def test_sed_node(self, monkeypatch: pytest.MonkeyPatch) -> None:
1905+
async def test_sed_node(self, monkeypatch: pytest.MonkeyPatch) -> None: # noqa: PLR0915
19111906
"""Testing properties of SED."""
19121907

1913-
def fake_cache(dummy: object, setting: str) -> str | None:
1908+
def fake_cache(dummy: object, setting: str) -> str | None: # noqa: PLR0911
19141909
"""Fake cache retrieval."""
19151910
if setting == pw_node.CACHE_FIRMWARE:
19161911
return "2011-6-27-8-55-44"
@@ -2106,10 +2101,10 @@ async def load_callback(event: pw_api.NodeEvent, mac: str) -> None: # type: ign
21062101
assert test_sed.sleep_duration == 120
21072102

21082103
@pytest.mark.asyncio
2109-
async def test_scan_node(self, monkeypatch: pytest.MonkeyPatch) -> None:
2104+
async def test_scan_node(self, monkeypatch: pytest.MonkeyPatch) -> None: # noqa: PLR0915
21102105
"""Testing properties of scan."""
21112106

2112-
def fake_cache(dummy: object, setting: str) -> str | None:
2107+
def fake_cache(dummy: object, setting: str) -> str | None: # noqa: PLR0911 PLR0912
21132108
"""Fake cache retrieval."""
21142109
if setting == pw_node.CACHE_FIRMWARE:
21152110
return "2011-6-27-8-55-44"
@@ -2301,7 +2296,7 @@ async def load_callback(event: pw_api.NodeEvent, mac: str) -> None: # type: ign
23012296
async def test_switch_node(self, monkeypatch: pytest.MonkeyPatch) -> None:
23022297
"""Testing properties of switch."""
23032298

2304-
def fake_cache(dummy: object, setting: str) -> str | None:
2299+
def fake_cache(dummy: object, setting: str) -> str | None: # noqa: PLR0911
23052300
"""Fake cache retrieval."""
23062301
if setting == pw_node.CACHE_FIRMWARE:
23072302
return "2011-5-13-7-26-54"
@@ -2390,7 +2385,7 @@ async def load_callback(event: pw_api.NodeEvent, mac: str) -> None: # type: ign
23902385
assert not state[pw_api.NodeFeature.AVAILABLE].state
23912386

23922387
@pytest.mark.asyncio
2393-
async def test_node_discovery_and_load(
2388+
async def test_node_discovery_and_load( # noqa: PLR0915
23942389
self, monkeypatch: pytest.MonkeyPatch
23952390
) -> None:
23962391
"""Testing discovery of nodes."""
@@ -2569,7 +2564,7 @@ async def test_node_discovery_and_load(
25692564
)
25702565
assert stick.nodes["5555555555555555"].node_info.version == "080007"
25712566
assert stick.nodes["5555555555555555"].node_info.model == "Scan"
2572-
assert stick.nodes["5555555555555555"].node_info.model_type == None
2567+
assert stick.nodes["5555555555555555"].node_info.model_type is None
25732568
assert stick.nodes["5555555555555555"].available
25742569
assert stick.nodes["5555555555555555"].node_info.is_battery_powered
25752570
assert sorted(stick.nodes["5555555555555555"].features) == sorted(
@@ -2634,7 +2629,7 @@ async def test_node_discovery_and_load(
26342629
)
26352630
assert stick.nodes["8888888888888888"].node_info.version == "070051"
26362631
assert stick.nodes["8888888888888888"].node_info.model == "Switch"
2637-
assert stick.nodes["8888888888888888"].node_info.model_type == None
2632+
assert stick.nodes["8888888888888888"].node_info.model_type is None
26382633
assert stick.nodes["8888888888888888"].available
26392634
assert stick.nodes["8888888888888888"].node_info.is_battery_powered
26402635
assert sorted(stick.nodes["8888888888888888"].features) == sorted(

0 commit comments

Comments
 (0)