Conversation
Code 325 = NetworkConfig/LANConfig (disasm MsgSetNetworkLANConfig + live). set_network(ip=, netmask=, gateway=, dns1=, dns2=, dhcp=, hostname=, mtu=, confirm=True) read-modify-writes the LANConfig: only the given fields change, MacAddress and the rest are preserved. Verified live on MTF45-4G_AF: - reversible DNS2 change with IP/mask/gateway preserved; - a DHCP<->static switch (static -> DHCP=1 -> back to static 10.216.128.149), re-finding the camera via anjoy.discovery between steps. Changing ip/netmask/gateway or enabling dhcp can move the camera, so the docstring warns to reconnect at / discover the new address; confirm-gated. const.CFG_LAN="325". Tests: field change + preservation, only-given-fields, confirm gate. Docs updated.
PR Summary by QodoAdd confirmed LAN network configuration setter
AI Description
Diagram
High-Level Assessment
Files changed (4)
|
Code Review by Qodo
1. Rapid network edits overwrite each other
|
| """ | ||
| if not confirm: | ||
| raise AnjoyError("set_network changes the camera address; pass confirm=True") | ||
| return self._rmw_section("LANConfig", const.CFG_LAN, { |
There was a problem hiding this comment.
1. Rapid network edits overwrite each other 🐞 Bug ≡ Correctness
set_network passes a complete snapshot of LANConfig through _rmw_section, even though set_config_section acknowledges before the previous asynchronous write appears in get_config(). If callers make two edits back-to-back, the second read can retrieve the pre-first-write section and resend its stale values alongside the second field, reverting the first edit and any concurrent LAN changes.
Agent Prompt
## Issue description
`set_network` read-modify-writes the complete `LANConfig` element, so a subsequent call can read stale configuration before an earlier asynchronous write is persisted and then restore the old values.
## Fix Focus Areas
- anjoy/comm.py[613-618]
- tests/test_comm.py[725-735]
## Recommended Fix
Build a `LANConfig` element containing only the non-`None` attributes supplied by the caller and pass it directly to `set_config_section`, relying on the device's documented partial-section merge behavior. Add a test showing that separate consecutive field updates do not include or overwrite unspecified attributes.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
What
Wired network config over code 325 =
NetworkConfig/LANConfig(disasmMsgSetNetworkLANConfig, confirmed live on an MTF45-4G_AF).set_network(ip=, netmask=, gateway=, dns1=, dns2=, dhcp=, hostname=, mtu=, confirm=True)— read-modify-write of the<LANConfig>element: only the given fields change;MacAddressand everything else are preserved.dhcpis a bool.Verified live
DHCP=1→ back to static10.216.128.149), re-finding the camera viaanjoy.discoverybetween steps. On this network there is no DHCP server, so the camera kept its IP under DHCP and stayed reachable throughout.Safety
Changing
ip/netmask/gatewayor enablingdhcpcan move the camera to a different address, so the docstring warns to reconnect at (ordiscover()) the new IP;confirm=True-gated.Changes
anjoy/comm.py:set_network(RMW over_rmw_section).anjoy/const.py:CFG_LAN="325".tests/test_comm.py: field change + preservation, only-given-fields, confirm gate (97 tests pass).docs/devices.md: the 325 code + the DHCP↔static verification.