Add duration and toggle setting types to YAML nodes #134
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/yaml-settings"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
YN-15. Two new endpoint types, both a
ctrl::SettingEndpointon onectrl::PreferencesStoreper node.toggleis an Enablement setting (0 to 1,defaulta YAML bool, true by default).durationis a Duration setting in whole seconds in YAML (0 to 6553,min <= default <= max,defaultrequired), sent in deciseconds. The store's NVS namespace is the node label cut to 15 characters and keys ares<index>, so renaming a setting keeps its value; the README says so, and that changing the index or the first 15 characters of the label loses it. Settings take nopin,binds,disabled_modesorfailsafe.enabled_by: <label>on aswitchortouchnames atoggleon the same node. The generator emits a one-line predicate function reading it and sets it on every bind whose source is that input.ctrl::Bindgainsbool (*enabled)() = nullptr: while the predicate returns false the bind skips its action (no toggle, no follow) but still tracks the source, so a latching switch flipped while disabled does not toggle on re-enabling. The check sits inOnOffStrategy::onSourcebeside the mode check. The input itself still reports to the bus, as the hand-written nodes' touch pads do; only the local action is skipped, which on a YAML node is the bind.holdonoccupancynow takes an integer or the label of adurationon the same node, and thensetHoldDs(setting.value())runs at the top ofloop. Cross-node references, and labels of the wrong type, are rejected.Schema regenerated (
holdis integer-or-string,enabled_by, per-type setting fields) and README gains the rows and a Settings section. The C3 fixture has a duration driving the PIR hold and the S3 fixture a toggle gating the touch pad's binds, so CI compiles both.Tested: Python 75 (was 61) and native 616, none skipped locally. Native tests show a closed gate ignores a fresh press and an open one acts, and that a latching switch flipped while gated does not toggle on re-enabling; moving the check back before the tracking fails the second. A Python test shows the gate is set only on binds whose source has
enabled_by. All three fixtures andpio runbuild.enabled_by is inert for every generated node, not just binds. The generator never calls setOnPress (grep scripts/yaml_node.py), and BinaryInput::pressed returns before the predicate unless onPress_ is set. The PR body undersells this. nodes/README.md says "The input is disabled while the toggle is off", which is false: events still broadcast and binds still fire. Either gate emission/binds in the runtime, or drop enabled_by from this PR and the README until it does something.
Two minor ones:
lib/node-runtime/src/bind.cpp:92: the gate skips the whole onSource call, so
sourceOngoes stale while the toggle is off. For a latching switch (ToggleOnChange) flipped while disabled, the first report after re-enabling seessourceOn != event.onand toggles the light. A Follow bind has the same lag. If that is not intended, move the gate into OnOffStrategy::onSource so it still updatessourceOnbut skips the action. If you want it as is, ignore this.