review: address Opus code-review findings on this branch
- config_flow: the #192 port-rescue made the "every port refused" fast-fail permanently unreachable (PREFERRED_PROBE_PORTS is always non-empty and always rescued), so removed the dead branch instead of leaving it as misleading dead code. A dead host now fails via the handshake loop's own error, which carries the real per-port reason. - oven._has_option: added the is_stub_rep carve-out cooktop.py's identical per-token exists_fn already has on the same kind of href, so a not-yet sub-polled /mode/vs/0 doesn't permanently exclude energy_saving/ cooktop_on_alert before their first real fetch lands. - airconditioner.ENERGY_METER_LEGACY: build via dataclasses.replace() like its ENERGY_METER_GENERIC sibling, instead of hand-copying href/poll_tier (which would silently drift if common.ENERGY_METER ever gains a field). - Fixed two stale comments: is_legacy_board()'s docstring still listed Volume among tokens needing legacy-only gating, though 'beep' now applies unconditionally across board generations; and common.py's UNIVERSAL invariant comment didn't mention that airconditioner also now excludes ENERGY_METER from the wholesale bundle. - #191 (CAC token): added the fixture/golden/capability-test coverage the AVT token in the same branch got, including an honestly-documented list of the ten hrefs this board generation doesn't cover yet. - fridge.cooler_temperature_setpoint: dropped the hardcoded "N °C" state labels -- the resource's own unit field isn't necessarily Celsius on a different model reporting the same href, and the options themselves are already read live via options_field, so a static per-value label risked asserting the wrong unit for a future device sharing this capability. - airconditioner._legacy_cumulative_power_kwh: parse with float (matching common.wh_to_kwh's own numeric parsing) instead of this module's integer-only _int, so a decimal-formatted reading doesn't raise. - test_config_flow: the port-rescue test bound the real 49154 directly, which could collide with an actually-running service on some machine; now monkeypatches PREFERRED_PROBE_PORTS to an OS-assigned port instead. - oven.py: consolidated six byte-for-byte-identical single-token options write_fns (lamp/sound/fast_preheat/natural_steam/energy_saving/ cooktop_on_alert) into one _option_switch_write(prefix) factory. 845 tests passing (up from 841 -- 4 new CAC coverage tests).
This commit is contained in:
11 files changed
+1129
-117
No files matched your search
@@ -106,35 +106,44 @@ def test_find_live_ports_detects_silent_port(socket_enabled) -> None:
|
||||
|
||||
|
||||
def test_find_live_ports_rescues_preferred_ports_the_sweep_missed(
|
||||
socket_enabled,
|
||||
socket_enabled, monkeypatch,
|
||||
) -> None:
|
||||
"""Issue #192: a segregated VLAN made the ICMP-based sweep call three
|
||||
closed ports live while missing the one port (49154, a historically
|
||||
confirmed DTLS port) that nmap showed as genuinely open|filtered. The
|
||||
sweep's verdict on a preferred port shouldn't be trusted blindly --
|
||||
it must always come back as a candidate even if the sweep marked it
|
||||
dead, so the config flow gets a real handshake attempt against it."""
|
||||
closed ports live while missing the one port (a historically confirmed
|
||||
DTLS port) that nmap showed as genuinely open|filtered. The sweep's
|
||||
verdict on a preferred port shouldn't be trusted blindly -- it must
|
||||
always come back as a candidate even if the sweep marked it dead, so the
|
||||
config flow gets a real handshake attempt against it.
|
||||
|
||||
Uses an OS-assigned port monkeypatched into PREFERRED_PROBE_PORTS rather
|
||||
than the real 49154/49155, so this doesn't depend on those specific
|
||||
system ports being free on whatever machine runs the suite.
|
||||
"""
|
||||
import socket
|
||||
|
||||
from custom_components.localthings import config_flow
|
||||
from custom_components.localthings.config_flow import _find_live_ports
|
||||
|
||||
# Bind and immediately close a socket on 49154 so loopback refuses
|
||||
# datagrams to it -- standing in for the sweep wrongly ruling out a
|
||||
# port we have strong prior evidence for.
|
||||
# Bind an OS-assigned port and immediately close it, same technique
|
||||
# test_find_live_ports_detects_silent_port uses for its "closed" ports --
|
||||
# once closed, loopback refuses datagrams to it, standing in for the
|
||||
# sweep wrongly ruling out a port we have strong prior evidence for.
|
||||
reserved = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
reserved.bind(('127.0.0.1', 49154))
|
||||
reserved.bind(('127.0.0.1', 0))
|
||||
preferred_port = reserved.getsockname()[1]
|
||||
reserved.close()
|
||||
monkeypatch.setattr(config_flow, 'PREFERRED_PROBE_PORTS', [preferred_port])
|
||||
|
||||
live_sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
live_sock.bind(('127.0.0.1', 0))
|
||||
live_port = live_sock.getsockname()[1]
|
||||
|
||||
try:
|
||||
result = _find_live_ports('127.0.0.1', [49154, live_port], 0.8)
|
||||
result = _find_live_ports('127.0.0.1', [preferred_port, live_port], 0.8)
|
||||
finally:
|
||||
live_sock.close()
|
||||
|
||||
assert set(result) == {49154, live_port}
|
||||
assert set(result) == {preferred_port, live_port}
|
||||
|
||||
|
||||
async def test_probe_uses_discovered_low_port(hass: HomeAssistant, monkeypatch) -> None:
|
||||
|
||||
Reference in new issue
Block a user