Repository navigation
Publish /FirmwareVersion on channel services - #41
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.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.
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 #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.pyand one new test file, 111 insertions and 5 deletions across 3 files.Problem
/FirmwareVersionis part of the standard identification path set on a Venus service(alongside
/Serial,/ProductId,/ProductName), but channels on the current path neverpublished it. Only the legacy websocket path did, at
meter.py:92.The data is already in hand:
Shelly.GetDeviceInfois fetched on every connect and cachedas
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
ShellyChannelthe same wayshellyModelalready is, andpublish it in
ainit().Shelly.GetDeviceInforeports 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 releasenotes 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 withmeter.pyis preferred.When a device does not report
verat all the path is simply not added, rather thanpublished 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, soainit()does not run again. Thereported version would therefore stay at the pre-update one indefinitely.
Confirmed by measurement before fixing: with the device changed from
1.4.4to9.9.9behind a reconnect,
/FirmwareVersionstill read1.4.4once the channel was back and/Connectedwas 1._reinit_channel_and_handlers()already runs right after the reconnect re-readShelly.GetDeviceInfo, so the fresh value is picked up there.Tests
New
tests/test_device_info.py:test_channel_publishes_firmware_versiontest_firmware_version_alongside_the_other_identification_paths/Serial,/ProductName,/ShellyModelunaffectedtest_firmware_version_follows_the_device_after_a_channel_restarttest_firmware_version_refreshes_on_reconnectThe 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.pygains--firmware-version(default"1.0.0", i.e. unchangedbehaviour for every existing mock invocation) so a version change can be simulated. Both
/shellyandShelly.GetDeviceInforeport it.Compatibility
Adds one optional D-Bus path. No path removed or changed, no new dependency, no behaviour
change for existing channels.
firmwareVersionis a keyword argument defaulting toNone,so any other caller of
ShellyChannel.create()is unaffected.Verified on Python 3.12.16 against both:
Disclosure: a pre-existing failure on aioshelly 12.0.0
tests/test_timeouts.py::test_freeze_longer_than_reconnect_loopfails on aioshelly12.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'stested-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.