Skip to content

Publish /FirmwareVersion on channel services - #41

Open
drHouse-gif wants to merge 1 commit into
victronenergy:masterfrom
drHouse-gif:feat/firmware-version-v221
Open

drHouse-gif wants to merge 1 commit into
victronenergy:masterfrom
drHouse-gif:feat/firmware-version-v221

Conversation

@drHouse-gif

Copy link
Copy Markdown
Collaborator

Rebased onto master (d8cb65d, v2.21). This replaces #27, whose branch was based on v2.20 and no longer merges cleanly; the change itself is unchanged. One commit: shelly_device.py, mock/mock_shelly_server.py and one new test file, 111 insertions and 5 deletions across 3 files.

Problem

/FirmwareVersion is part of the standard identification path set on a Venus service
(alongside /Serial, /ProductId, /ProductName), but channels on the current path never
published it. Only the legacy websocket path did, at meter.py:92.

The data is already in hand: Shelly.GetDeviceInfo is fetched on every connect and cached
as ShellyDevice.shelly_info, so no extra RPC is needed.

This has been asked for in #9 (referenced, not closed by this PR — the other half of that
report, the Pro 3EM product ID, is already fixed on the current path).

Solution

Thread the firmware version into ShellyChannel the same way shellyModel already is, and
publish it in ainit().

Shelly.GetDeviceInfo reports two fields:

  • ver — e.g. "1.4.4"
  • fw_id — the build string, e.g. "20241011-114455/1.4.4-g6d2a586"

This publishes ver, since that is what the device's own web UI and the Shelly release
notes show, so it is the value a user can compare against. Note the legacy path uses
fw_id; happy to switch to that instead if consistency with meter.py is preferred.

When a device does not report ver at all the path is simply not added, rather than
published as invalid.

Refresh after an over-the-air update

A device that is updated over the air drops its connection and comes back on the same
channel object — reinit() only swaps the callbacks, so ainit() does not run again. The
reported version would therefore stay at the pre-update one indefinitely.

Confirmed by measurement before fixing: with the device changed from 1.4.4 to 9.9.9
behind a reconnect, /FirmwareVersion still read 1.4.4 once the channel was back and
/Connected was 1.

_reinit_channel_and_handlers() already runs right after the reconnect re-read
Shelly.GetDeviceInfo, so the fresh value is picked up there.

Tests

New tests/test_device_info.py:

Test Covers
test_channel_publishes_firmware_version the value matches what the device reports
test_firmware_version_alongside_the_other_identification_paths it is an addition, not a replacement — /Serial, /ProductName, /ShellyModel unaffected
test_firmware_version_follows_the_device_after_a_channel_restart a disable/enable cycle picks up a new version
test_firmware_version_refreshes_on_reconnect the OTA case above

The last one fails with the refresh hook removed (verified by running it that way), so it
guards the actual defect rather than just the happy path.

mock/mock_shelly_server.py gains --firmware-version (default "1.0.0", i.e. unchanged
behaviour for every existing mock invocation) so a version change can be simulated. Both
/shelly and Shelly.GetDeviceInfo report it.

Compatibility

Adds one optional D-Bus path. No path removed or changed, no new dependency, no behaviour
change for existing channels. firmwareVersion is a keyword argument defaulting to None,
so any other caller of ShellyChannel.create() is unaffected.

Verified on Python 3.12.16 against both:

aioshelly Result
14.1.0 (what CI installs, unpinned) 62 passed, 4 xfailed
12.0.0 (what the Venus OS recipe ships) 61 passed, 4 xfailed, 1 failed

Disclosure: a pre-existing failure on aioshelly 12.0.0

tests/test_timeouts.py::test_freeze_longer_than_reconnect_loop fails on aioshelly
12.0.0 and passes on 14.1.0. It is not caused by this change — it reproduces on
unmodified master. Same note as in #26.

No hardware was used — all results are against mock/mock_shelly_server.py. The README's
tested-device list is therefore not extended by this PR.

Verified on v2.21

tests/test_device_info.py: 4 passed. Full suite on this branch is covered by the combined run of all 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.

Shelly.GetDeviceInfo is already fetched on every connect and cached as
ShellyDevice.shelly_info, so the firmware version is in hand before any channel
is created. Until now only the legacy websocket path (meter.py) published it,
so devices on the current path reported no firmware version at all.

Publish the 'ver' field (e.g. "1.4.4"), which is what the device's own web UI
and the Shelly release notes show. 'fw_id' (the build string, which meter.py
uses) is also available if that is preferred for consistency with the legacy
path.

A device updated over the air comes back on the same channel object, so ainit()
does not run again and the value would stay at the pre-update one. Refresh it
from the freshly re-read device info when a channel is reinitialised after a
reconnect.

The mock server gains --firmware-version so a version change can be simulated.
tests/test_device_info.py covers the published value, its coexistence with the
other identification paths, a channel restart and the reconnect refresh; the
last one fails without the refresh.
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