Skip to content

Commit 572be1c

Browse files
committed
fix: streamline testing commands and improve code readability
1 parent 721536c commit 572be1c

6 files changed

Lines changed: 19 additions & 16 deletions

File tree

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,15 @@ fix: lint-fix format
6666

6767
# Testing
6868
test:
69-
$(PYTEST)
69+
$(PYTEST) tests/
7070

7171
test-cov:
72-
$(PYTEST) --cov=custom_components/unifi_network_rules --cov-report=term-missing --cov-report=html
72+
$(PYTEST) tests/ --cov=custom_components/unifi_network_rules --cov-report=term-missing --cov-report=html
7373
@echo ""
7474
@echo "Coverage report generated: htmlcov/index.html"
7575

7676
test-watch:
77-
$(PYTEST) --watch
77+
$(PYTEST) tests/ --watch
7878

7979
# Combined checks (mirrors CI)
8080
check: lint test

custom_components/unifi_network_rules/coordination/auth_manager.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,11 @@ def __init__(self, hass: HomeAssistant, api: UDMAPI) -> None:
4545
self._ha_initiated_operations: dict[str, float] = {}
4646

4747
def register_ha_initiated_operation(
48-
self, rule_id: str, entity_id: str, change_type: str = "modified",
49-
timeout: int = HA_INITIATED_OPERATION_TIMEOUT_SECONDS
48+
self,
49+
rule_id: str,
50+
entity_id: str,
51+
change_type: str = "modified",
52+
timeout: int = HA_INITIATED_OPERATION_TIMEOUT_SECONDS,
5053
) -> None:
5154
"""Register that a rule change was initiated from HA.
5255

custom_components/unifi_network_rules/coordination/coordinator.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,11 @@ def __init__(
137137

138138
# Backward compatibility methods - delegate to auth manager
139139
def register_ha_initiated_operation(
140-
self, rule_id: str, entity_id: str, change_type: str = "modified",
141-
timeout: int = HA_INITIATED_OPERATION_TIMEOUT_SECONDS
140+
self,
141+
rule_id: str,
142+
entity_id: str,
143+
change_type: str = "modified",
144+
timeout: int = HA_INITIATED_OPERATION_TIMEOUT_SECONDS,
142145
) -> None:
143146
"""Register that a rule change was initiated from HA."""
144147
self.auth_manager.register_ha_initiated_operation(rule_id, entity_id, change_type, timeout)

custom_components/unifi_network_rules/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@
1515
"aiounifi>=87.0.0",
1616
"orjson>=3.8.0"
1717
],
18-
"version": "4.3.0"
18+
"version": "4.4.0"
1919
}

custom_components/unifi_network_rules/switches/base.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
from ..const import DOMAIN, MANUFACTURER, SWITCH_DELAYED_VERIFICATION_SLEEP_SECONDS
1919
from ..coordinator import UnifiRuleUpdateCoordinator
20-
2120
from ..helpers.rule import (
2221
get_object_id,
2322
get_rule_enabled,
@@ -547,9 +546,7 @@ async def handle_operation_complete(future):
547546
# if the change was confirmed by the trigger system (which consumes the
548547
# HA-initiated operation flag). If not, it forces a refresh.
549548
async def delayed_verification():
550-
await asyncio.sleep(
551-
SWITCH_DELAYED_VERIFICATION_SLEEP_SECONDS
552-
) # Wait for smart polling update
549+
await asyncio.sleep(SWITCH_DELAYED_VERIFICATION_SLEEP_SECONDS) # Wait for smart polling update
553550
if self.coordinator.check_and_consume_ha_initiated_operation(self._rule_id):
554551
# If the flag was still present, it means the trigger system
555552
# did NOT get a change event. We must refresh.
@@ -655,7 +652,9 @@ async def led_toggle_wrapper(device, state):
655652
# Add the completion callback
656653
future.add_done_callback(lambda f: self.hass.async_create_task(handle_operation_complete(f)))
657654

658-
LOGGER.debug("Successfully queued toggle operation for rule %s with target state: %s", self._rule_id, enable)
655+
LOGGER.debug(
656+
"Successfully queued toggle operation for rule %s with target state: %s", self._rule_id, enable
657+
)
659658
except Exception as err:
660659
LOGGER.error("Failed to queue toggle operation for rule %s: %s", self._rule_id, err)
661660
# Remove from pending operations if queueing failed

tests/test_api.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111
@pytest.fixture
1212
def api() -> UDMAPI:
1313
"""Return a UDMAPI instance with mocked controller and queue."""
14-
with patch(
15-
"custom_components.unifi_network_rules.udm.api.ApiOperationQueue"
16-
) as mock_queue_class:
14+
with patch("custom_components.unifi_network_rules.udm.api.ApiOperationQueue") as mock_queue_class:
1715
# Create a mock queue that doesn't start background tasks
1816
mock_queue = AsyncMock()
1917
mock_queue.stop = AsyncMock()

0 commit comments

Comments
 (0)