Skip to content

Typed config setters: set_title, set_maintenance - #11

Merged
widgetii merged 2 commits into
masterfrom
typed-config-setters
Sep 22, 2026
Merged

widgetii merged 2 commits into
masterfrom
typed-config-setters

Conversation

@widgetii

Copy link
Copy Markdown
Member

What

First typed wrappers over set_config_section (PR #10) — one thin method per config section, both captured from AjDevTools batch dialogs and verified live on an MTF45-4G_AF with a set-then-restore round-trip.

  • set_title(title, confirm=True) — code 525 = MediaConfig/Video/Overlay. Read-modify-write of the current <Overlay>: only <TitleOverlay>'s title changes, so position/font/timestamp and any user-OSD lines are preserved. Title is hex-encoded (TitleUtf8 = UTF-8 hex, legacy Title = GB2312 hex).
  • set_maintenance(enable, day=7, time="HH:MM:SS", confirm=True) — code 228 = SystemConfig/MaintainConfig (scheduled auto-reboot; day=7 = every day, per the vendor UI).

Notes from the live captures

  • SET is applied asynchronously (already handled in set_config_section); both were verified by reading the change back after a pause and then restoring the original.
  • The device stores config attributes multiline and normalizes some values (e.g. Time" 2: 0: 0"), so read-backs use a multiline-aware matcher.

Changes

  • anjoy/comm.py: set_title (RMW), set_maintenance.
  • anjoy/const.py: CFG_MAINTAIN = "228".
  • tests/test_comm.py: frame assertions, confirm gates, RMW round-trip preserving siblings, no-<Overlay> error path (77 tests pass).
  • docs/devices.md: the two confirmed codes + the multiline read-back note.

More section setters (time/language/encode/motion/AI/platform) follow as their codes are confirmed live.

Thin wrappers over set_config_section (SYSTEM_CONFIG_SET_MESSAGE), both
captured from AjDevTools batch dialogs and verified live on MTF45-4G_AF with a
set-then-restore round-trip:

- set_title(title, confirm=True): code 525 = MediaConfig/Video/Overlay.
  Read-modify-write of the current <Overlay> — only <TitleOverlay>'s title
  changes, so position/font/timestamp/user-OSD lines are preserved. The title
  is hex-encoded (TitleUtf8 = UTF-8 hex, legacy Title = GB2312 hex).
- set_maintenance(enable, day=7, time, confirm=True): code 228 =
  SystemConfig/MaintainConfig (scheduled auto-reboot; day=7 = every day).

const.CFG_MAINTAIN = "228". Tests: frame assertions, confirm gates, the RMW
round-trip preserving sibling overlays, and the no-<Overlay> error path.
Docs: the two confirmed codes + the multiline read-back note.
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

Add typed setters for camera titles and maintenance schedules

✨ Enhancement 🧪 Tests 📝 Documentation 🕐 10-20 Minutes

Grey Divider

AI Description

• Adds typed setters for OSD titles and scheduled camera maintenance.
• Preserves overlay settings through read-modify-write updates and dual-charset title encoding.
• Enforces explicit confirmation and tests framing, preservation, and failure paths.
Diagram

graph TD
  U["API Caller"] --> T["set_title"] --> G["Full Config"] --> O["Overlay RMW"] --> S["Section Writer"] --> D["Camera Device"]
  U --> M["set_maintenance"] --> S
Loading
High-Level Assessment

The current approach is appropriate: thin typed wrappers retain the proven generic section writer, while read-modify-write avoids destroying unrelated overlay configuration. Exposing only the generic writer or replacing the entire overlay section would provide less safety and weaker API guidance.

Files changed (4) +111 / -0

Enhancement (1) +44 / -0
comm.pyAdd typed title and maintenance configuration setters +44/-0

Add typed title and maintenance configuration setters

• Adds confirmation-gated setters for OSD titles and scheduled auto-reboots. Title changes download and parse the current Overlay section, update UTF-8 and legacy GB2312 title fields, preserve sibling settings, and delegate the write to set_config_section.

anjoy/comm.py

Tests (1) +51 / -0
test_comm.pyCover typed setter frames, safeguards, and preservation +51/-0

Cover typed setter frames, safeguards, and preservation

• Tests maintenance frame generation and both confirmation gates. Adds a title round-trip test proving sibling overlay preservation and coverage for missing Overlay configuration.

tests/test_comm.py

Documentation (1) +15 / -0
devices.mdDocument confirmed configuration codes and typed setters +15/-0

Document confirmed configuration codes and typed setters

• Documents overlay and maintenance section codes, setter behavior, live round-trip verification, and the device's multiline, space-padded configuration read-back format.

docs/devices.md

Other (1) +1 / -0
const.pyDefine the maintenance configuration section code +1/-0

Define the maintenance configuration section code

• Adds CFG_MAINTAIN with confirmed protocol code 228 for SystemConfig/MaintainConfig writes.

anjoy/const.py

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Sep 22, 2026

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Remediation recommended

1. UTF-8-only camera titles are rejected ✓ Resolved 🐞 Bug ≡ Correctness
Description
set_title calls title.encode("gb2312") before inspecting the downloaded ``, so it rejects text
outside the legacy charset even when no Title attribute needs updating. Configurations containing
only TitleUtf8 hit this guard for emoji or other UTF-8-only text, although the later code stores
that field as ASCII hex and only touches the legacy field when present.
Code

anjoy/comm.py[R434-437]

+        try:
+            title.encode("gb2312")            # device charset for the legacy field
+        except UnicodeEncodeError as e:
+            raise AnjoyError(f"title is not GB2312-encodable: {title!r}") from e
Evidence
The captured device format documents a TitleOverlay containing only TitleUtf8, while the
implementation rejects non-GB2312 text before reading that configuration. The eventual wire body
remains GB2312-safe because UTF-8 title bytes are represented as hexadecimal ASCII, and legacy
GB2312 encoding is otherwise conditional on Title being present.

anjoy/comm.py[422-448]
docs/devices.md[114-122]
docs/devices.md[135-137]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`set_title` unconditionally requires every title to be GB2312-encodable, even when the device configuration has no legacy `Title` attribute and only needs the UTF-8 hexadecimal representation.
## Fix Focus Areas
- anjoy/comm.py[434-448]
- tests/test_comm.py[455-472]
## Recommended Fix
Remove the upfront GB2312 encoding check. Always update `TitleUtf8`, and perform GB2312 validation and encoding only inside the branch where an existing legacy `Title` attribute must also be updated; add coverage for a UTF-8-only overlay and a title outside GB2312.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Tip of the day
💡 Did you know, you can route each action level your way: inline, summary, both, or drop

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

Comment thread anjoy/comm.py Outdated
The upfront GB2312 guard rejected titles outside the legacy charset (e.g.
emoji) even when the device config has no legacy Title attribute and only needs
TitleUtf8 (which is stored as hex of the UTF-8 bytes and is always
representable). Always set TitleUtf8; validate/encode GB2312 only inside the
branch that updates an existing legacy Title. Add tests: a UTF-8-only overlay
accepts a non-GB2312 title; a title outside GB2312 raises only when a legacy
Title must also be updated.
@widgetii

Copy link
Copy Markdown
Member Author

Addressed in 372dca9: removed the upfront GB2312 guard. set_title now always sets TitleUtf8 (hex of the UTF-8 bytes, always representable) and validates/encodes GB2312 only inside the branch that updates an existing legacy Title. Added tests for a UTF-8-only overlay (accepts an emoji title) and for a non-GB2312 title with a legacy Title present (raises).

@widgetii
widgetii merged commit af53c46 into master Sep 22, 2026
6 checks passed
@widgetii
widgetii deleted the typed-config-setters branch September 22, 2026 16:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant