Repository navigation
Expose Shelly Input components, including on input-only devices - #42
Open
drHouse-gif wants to merge 1 commit into
Open
drHouse-gif wants to merge 1 commit into
drHouse-gif wants to merge 1 commit into
Conversation
Shelly devices report their physical inputs as Input components, and nearly every relay, dimmer and Pro device has at least one. The driver ignored them: no handler, no capability, no dbus path. A device with nothing but inputs, such as an i4, was rejected outright as unsupported. Venus documents a generic input API that is the counterpart of the switchable output API, and gui-v2 and venus-html5-app both implement it, so publishing /GenericInput/<id>/... is enough to get a value into the switching pane. Uses the primary/secondary split this branch introduces, so an Input takes a channel of its own only when no earlier channel already uses its id: switch:0 + input:0 input:0 adds /GenericInput/0/ to the switch channel input:0..3 only four input channels, each its own switch service switch:0 + input:0,1 input:0 attaches, input:1 becomes a channel of its own The new input kind is appended to FUNCTIONAL_HANDLERS, after the kinds whose channels an Input can be added to, so existing channel indices and the settings keyed by them are unchanged. The four Shelly input types map onto the generic input types below. The type comes from the device's own Input.GetConfig and ValidTypes is left with only that one bit set, since the mode is configured on the shelly and not here: switch discrete value indicator, /Value 0 or 1, Labels ["/off", "/on"] analog value indicator with range, /Value from percent, range from range_map count value indicator without range, /Value from counts.total button stateless, so no /Value at all, only /Event A disabled input and a stateless one both report null, published as an invalid value rather than a zero. An input reporting errors raises /Status to fault. An input channel of its own is registered as a switch service, which is where gui-v2 documents the generic input paths, and reuses the input device product id. Not covered, deliberately: - count mode publishes counts.total only; one /Value cannot carry total, xtotal, freq and xfreq at once. - /GenericInput/<id>/Event is in the Venus spec but read by neither gui-v2 nor venus-html5-app, and node-red-contrib-victron has no generic input paths, so button events reach dbus and nothing renders them yet. - an input channel of its own has no CustomName path; the channel config mixin's handler_ainit does not chain to super(), so composing the two needs a change to the mixin that does not belong in this commit. The mock server gains Input components (--input-modes), Input.GetStatus/GetConfig/ SetConfig/Trigger/ResetCounters and a Mock.SetInput test hook. tests/test_input.py covers the four types and the attached case; tests/test_input_only.py covers input-only devices and inputs with no channel to share, in its own module because each Stack starts a driver and the legacy server always binds port 8000.
This was referenced Nov 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rebased onto
master(d8cb65d, v2.21). This replaces #33, whose branch was based onsensor-addon-temperaturerather thanmaster, so its diff showed 13 files and +1122/-47 of which most was upstream's own work. The change itself is 7 files, +524/-4. It also supersedes #32, which it contains, and which no longer applies to v2.21.The mechanism it needed,
register_secondary_handler, is inmastersince v2.21, so this no longer has to target a feature branch. The port adapts to the new handler registry: the kind isgenericinput, appended toFUNCTIONAL_HANDLERSso the persistence contract on channel indices is preserved, and registered in_CHANNEL_TYPE_BY_KINDso the channel is shown as aninputalongsidedigitalinput,temperatureandhumidity.Problem
A device with nothing but
Inputcomponents — an i4, for instance — is rejected outright:Inputhad no handler at all before #32, and the handler it adds there is secondary-only, soit can only ever attach to a channel that already exists for the same id. Three things stood in
the way of a channel of its own:
has_functional_handlerreturns False for a device whose capabilities are all secondaryInputcould not be both "own channel" and "attaches"Your branch solves (2) already, which is why this is built on it.
Solution
Inputgets both handlers, exactly asTemperaturedoes on this branch:@register_secondary_handler('Input')ShellyHandler_input/GenericInput/<id>/to a channel with the same id@register_handler('Input', kind=HANDLER_KIND_INPUT)ShellyHandler_input_channelso the existing rule decides which applies:
switch:0+input:0input:0adds/GenericInput/0/to the switch channelinput:0..3, nothing elseswitch:0+input:0,1input:0attaches,input:1becomes a channel of its ownHANDLER_KIND_INPUTis appended toFUNCTIONAL_HANDLERS, after the kinds an Input can beadded to, so existing channel indices and the settings keyed by them are untouched.
A channel of its own is registered as a
switchservice — that is where gui-v2 documents thegeneric input paths (
src/genericinput.h:com.victronenergy.switch[.suffix]/GenericInput/<channelId>)— and reuses
PRODUCT_ID_INPUT/ "Shelly input device".The type mapping, the null handling and the
Settings/Labelsarray type are as described in#32, so I will not repeat them here.
Not covered — deliberately, and not claimed as supported
countmode publishescounts.totalonly. Shelly also reportscounts.xtotal,freqand
xfreq; one/Valuecannot carry all four, and which to expose is a design question./GenericInput/<id>/Eventhas no consumer. It is in the Venus spec, butgui-v2,venus-html5-appandnode-red-contrib-victronall read nothing from it, so button eventsreach D-Bus and nothing renders them. Only single tap has a defined encoding.
CustomName.ShellyHandler_channel_config_mixin.handler_ainitreturns
Truewithout chaining tosuper(), so composing it with the input handler silentlyskips the path publishing. Making it cooperative is a change to the mixin that affects every
handler using it, which does not belong in this commit. Say the word and I will send it
separately.
mock/mock_shelly_server.py, driven from theofficial Input documentation. I have not held an i4, so the README's tested-device list is not
extended and I am not claiming device-level verification.
Tests
tests/test_input.py(12) — the four types, the value following the device, disabled anderror cases, sharing a channel's service, the event toggle bit
tests/test_input_only.py(5) — an input-only device being supported at all, its channelsregistering their own services, analog and count channels, an input that shares an id still
attaching, and a surplus input taking a channel of its own
Separate modules because each
Stackstarts a driver and the legacy server always bindsport 8000.
Compatibility
Additive. No existing D-Bus path changed or removed, no new dependency, no new source file.
FUNCTIONAL_HANDLERSis appended to, never reordered. Devices with noInputcomponent behaveexactly as before.
Verified on Python 3.12.16 against both:
sensor-addon-temperaturebaselinemake testinstallpasses.The 12.0.0 failure
tests/test_timeouts.py::test_freeze_longer_than_reconnect_loopfails on aioshelly 12.0.0and passes on 14.1.0. It is pre-existing on your branch too — I measured the baseline
above before applying anything. Since
meta-victronenergypinspython3-aioshelly_12.0.0.bbwhile CI installs aioshelly unpinned, the suite is green in CI but not against the version on a
GX. Flagged in #26 as well; happy to open a separate issue if useful.
Verified on v2.21
tests/test_input.pyandtests/test_input_only.py: 17 passed. Hardware, on a GX with 9 real devices: 11 of 19 channel services carried/GenericInput; the two switch-mode inputs published/Valuewith labels, the nine button-mode ones published/Eventonly.Full suite in combination with the other proposals: 119 passed / 1 failed on aioshelly 12.0.0 and 120 passed / 0 failed on 14.1.0, against a pristine v2.21 baseline of 75/4/1 and 76/4/0. The single 12.0.0 failure,
test_timeouts.py::test_freeze_longer_than_reconnect_loop, is pre-existing on unmodified v2.21.