Support devices that use multiple OTA image types (NodOn SIN-4, Inovelli VZM32-SN)

Aperta
#925 0 commenti 0 reazioni 1 assegnatario Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@TheJulianJES ci sta già lavorando.

Dal 7/10/2026.

Valutazione

Questa issue non è ancora stata valutata.

Descrizione

TL;DR

  • The problem. NodOn SIN-4-* modules and the Inovelli VZM32-SN request two OTA image types (two chips) from one OTA cluster. ZHA has one update entity per cluster, so its installed and latest versions flip between the two images every poll, and every flip rewrites the HA device registry (zigpy/zha#844, home-assistant/core#182381).
  • A zigpy bug. zigpy aborts an install when the device asks for its other image type in the meantime. A test reproducing this is below.
  • The proposal. A quirk lists a device's secondary image types, and each gets its own update entity. The primary entity takes every other image type and follows the newest query. Without a quirk that is exactly today's behaviour, which also keeps devices that change their image type after an upgrade working.
  • Needed underneath. zigpy caches queries per image type and keeps that cache across the re-interview that follows every OTA update. Installs are queued per device and wait for that re-interview.
  • Before zigpy/zigpy#1849 merges. Its new "firmware version changed" detection would re-interview these devices on every alternating query.
  • First step. The zigpy install-abort fix: small, independent, and it fixes failed installs today. zigpy-ota already ships the VZM32 switch image.

Background

Some devices have two chips, each with its own firmware, and send OTA Query Next Image requests for two image types from the same OTA client cluster. zigpy and ZHA hold OTA state per cluster, so the update entity's installed and latest versions flip between the two images every poll (zigpy/zha#844, home-assistant/core#182381). On top of that, zigpy aborts an install when the device queries the other image type mid-install. This issue collects the investigation and proposes a design across zigpy, ZHA and zha-quirks.

Affected devices

Device Image types Version schemes Queried from
NodOn SIN-4-* (manufacturer code 0x128B) antenna (EFR32) 0x00NN, power (STM32) 0x01NN, e.g. SIN-4-RS-20 = 0x0009 / 0x0109 antenna 0x0000030C, power 0x00030103 (independent) ep1 only
Inovelli VZM32-SN (manufacturer code 0x122F) switch 0x0103 (259), mmWave radar module 0x0104 (260) switch 0x01030102, module 0x06030E03 (independent) ep1 only
  • NodOn: the two-chip setup is confirmed by NodOn's own developer in Koenkk/zigbee2mqtt#32405 and by a NodOn support reply quoted in Koenkk/zigbee2mqtt#29293. The OTA current_file_version attribute is unsupported on the SIN-4-RS-20 (and on the SIN-4-FP-21 in the ZHA snapshot), so the OTA queries are the only source of per-chip OTA file versions.

  • Inovelli: the VZM32 has a writable manufacturer attribute 0x0022 (otaImageType, P34) on 0xFC31. Values: 0 = Zigbee image only, 1 = mmWave image only, 2 = alternate between both (the default). Inovelli described the alternating behaviour in zigpy/zigpy#1610. Z2M exposes the attribute; our quirk does not. The module's version can also be read from 0xFC32 / 0x0073 (mmwave_version).

  • No other device families with this pattern turned up in the 975-entry Koenkk/zigbee-OTA index. Models with several image types there are hardware or PID variants.

  • ZHA creates one update entity per OTA client cluster. So devices with an OTA client cluster on two endpoints (Inovelli VZM36, EcoDim, Paulmann 501.34, a TS0002) already get two update entities, though none of them is known to have two modules: …-1-25-firmware_update and …-2-25-firmware_update. Installing through the second one probably does not work:

    • The entity does not pass its endpoint to update_firmware().
    • OTAManager uses the first OTA client cluster on the device (device.find_cluster(...), manager.py#L63-L65) for every reply.
    • The post-install cache clear also uses the first cluster.

    This is inferred from the code, not tested.

Update order. Neither vendor documents a required order or version dependency. Inovelli wrote in zigpy/zigpy#1610 that "each chip gets updated separately (one at a time)". Their Hubitat driver has two independent commands (updateFirmware() and updateMMWaveFirmware() with type: 0x0104) and no guard between them. NodOn publishes no changelog. ZCL R8 §11.14.2 ("Separate OTA Files Upgraded Independently") assumes that "each module can be upgraded independently"; a device whose images really depend on each other is expected to sequence them itself, with Upgrade End REQUIRE_MORE_IMAGE (§11.14.3). The one practical constraint is that a device should not run two installs at once.

Spec note. §11.14.2 says the modules "would operate on separate endpoints". Both devices deviate from that, which is why per-endpoint state mixes the two images.

Spec note on version sources. The OTA client attribute CurrentFileVersion (0x0002) is optional (ZCL R8 Table 11-10, §11.10.3: "The attribute is optional on the client"), so NodOn not supporting it is compliant. The only mandatory client attributes are UpgradeServerID and ImageUpgradeStatus, and neither carries a version. The file version field in Query Next Image is mandatory and "represents the device's current running image version" (§11.13.4.2.4), and "All devices SHALL send in a Query Next Image Request Command periodically" (§11.8.1). So a design cannot rely on the attribute. It has to work from the per-image-type queries, and use the attribute or a quirk-declared version source where a device provides one.

Reports

  • zigpy/zha#844: 22 NodOn relays together flip about 8.6 times per minute, giving roughly 500 device-registry writes per hour. Every observed pair is one antenna-format plus one power-format version (0x00010500 ↔ 0x00000303, 0x0000030d ↔ 0x00030104, …). zigpy/zha#923 only removes the log warning.

  • home-assistant/core#182381: three SIN-4-RS-20 flip from 0x00030104 to 0x0000030d and back within about 5 s, once per poll cycle. The attached diagnostics show the ep1 cached query as image_type: 265 (0x0109, the power image) with current_file_version: 196868 (0x00030104). A frame-level debug log from the reporter confirms the mechanism:

    • Every query from these devices is either image_type: 9 (0x0009, antenna) at current_file_version: 781 (0x0000030d) or image_type: 265 (0x0109, power) at 196868 (0x00030104), both from ep1.
    • The two arrive about 5 s apart each cycle.
    • Each is followed, in the same millisecond, by a DeviceFirmwareInfoUpdatedEvent switching to that image's version.
    • All three devices behave identically.
    • A longer log from the same setup (about 44 hours, three SIN-4-RS-20) shows the same pattern throughout:
      • 3,186 version flips, every one between 0x0000030d and 0x00030104. That is about 24 per device per hour, i.e. two per poll. Each module polls about every 303 s.
      • The power query always followed the antenna query, about 5.1 s later. That held in all 21 pairs of the debug portion, and by timing in all 1,591 pairs of the whole log.
      • The power query is sent in response to zigpy's reply to the antenna query. It arrives a constant 4.97–4.99 s after the APS ack of our NO_IMAGE_AVAILABLE reply, while the gap between the two queries varies with our reply latency.
      • Both queries share the module's ZCL sequence numbers, APS counter and route, and both carry hardware version 0. So one Zigbee stack (the antenna chip) sends both, and the image type is the only thing that tells them apart.
      • zigpy's periodic broadcast Image Notify (every 3.9 h by default) was answered by both modules in all 11 broadcasts: the antenna query about 140 ms after the broadcast, the power query about 5.3–5.4 s after it. Each broadcast also re-aligned the three devices' poll timers. The broadcast's query jitter is 100 only in small networks (it scales with 15 / number of devices), so in larger networks not every device answers every broadcast.
      • After a ZHA start, the entity starts from whichever query was received last. That is almost always the power query, but after a radio watchdog reload in this log, two of the three devices started from the antenna version.
    • current_file_version is not supported. The reporter read the OTA attribute 16 times from the UI, three of them within 0.4–3.2 s after an antenna query. Every read returned UNSUPPORTED_ATTRIBUTE, which matches the SIN-4-FP-21 snapshot. So the OTA queries are the only source of per-chip OTA file versions on these modules (Basic sw_build_id appears to combine both, see step 4), and the cached current_file_version is purely ZHA's mirror of the last query.

    home-assistant/core#160487 shows the same flip incidentally in its logs.

  • zigpy/zha#926: 12 SIN-4-RS-20 on an EZSP stick, the same antenna image_type: 9 / power image_type: 265 queries about 5 s apart every 5 minutes, and the same flipping between 0x0000030d and 0x00030104. It was opened on 2026-10-07; the log-warning flood is covered by zigpy/zha#923, the flipping itself is this issue.

  • zigpy/zigpy#1610 (Inovelli): the VZM32 answers Image Notify with the two image types in turn ("if you send an image_notify, it will respond with type 259 … If you do it again, it responds with 260"). Manually forcing an Image Notify before an install led to a NO_IMAGE_AVAILABLE loop; left alone, automatic updates worked. The install abort below is the likely mechanism; that is an inference, and zigpy's OTA code has changed since 2025.

    • In the same thread, a vendor-side fix was suggested: give both chips one image type and order the images with min/max_current_file_version. Inovelli said they would discuss it with their engineer. That would need new firmware and a single version line across both chips, so it does not help devices already in the field or NodOn.
  • zigpy-ota ships the VZM32 switch image (0x0103 v1.02, zigpy/zigpy-ota#187). So a VZM32 on older switch firmware is offered that update whenever the last query was for 0x0103, and that install can hit the abort below whenever the mmWave module answers.

    • zigpy-ota has no Inovelli 0x0104 image (the missing mmWave image was noted in zigpy/zigpy-ota#162, along with doubts about the image-type switching) and no NodOn images yet. NodOn's own account has submitted them as open zigpy-ota submissions (SIN-4-FP-21 zigpy/zigpy-ota#397 and zigpy/zigpy-ota#398, SIN-4-1-20 zigpy/zigpy-ota#401 and zigpy/zigpy-ota#402, SIN-4-1-21 zigpy/zigpy-ota#403 and zigpy/zigpy-ota#404, SIN-4-2-20 zigpy/zigpy-ota#405 and zigpy/zigpy-ota#406, SIN-4-RS-20 zigpy/zigpy-ota#407 and zigpy/zigpy-ota#408; antenna and power image per model, generated PRs zigpy/zigpy-ota#399 and zigpy/zigpy-ota#400 for the FP-21 pair are open). Until they merge ZHA users are not offered those by default, and once they do, NodOn installs will meet the install-abort bug described below. The flipping happens regardless.
  • Zigbee2MQTT has the same symptoms: Koenkk/zigbee2mqtt#22245, Koenkk/zigbee2mqtt#29293 and Koenkk/zigbee2mqtt#30022.

What happens today

Links are at zigpy b4543ff5d7839b40cf53d0688358603643b315bf and zha 5eb118cc4065221f032221cdcbdfffd383dd139e.

  1. Only the last query is kept.
  2. ZHA follows every query.
    • OtaCurrentFileVersionCache copies each query's version into current_file_version (virtual.py#L462-L484).
    • FirmwareUpdateEntity sets installed_version from both that attribute and the query in OtaImageAvailableEvent, and replaces _compatible_images, latest_version and the release notes with the result for whichever type queried last (update.py#L176-L228).
    • The device firmware version follows the update entity (device.py#L1246-L1262), so every flip also rewrites sw_version in the HA device registry.
    • The mirror also runs during an install. zigpy's Ota cluster ignores queries while ota_in_progress is set, but every received command is still passed on to cluster_command listeners. So the entity's installed version can flip mid-update.
    • async_install picks from the last result (update.py#L239-L283). It can therefore offer or pick the other module's image, or report "Version … is not available".
  3. An install aborts when the device queries the other image type (bug).
    • OTAManager registers query_next_image matchers without field values, so they match any query (manager.py#L79-L120).

    • A query for a different image type fails check_compatibility (ota/init.py#L177). zigpy then replies NO_IMAGE_AVAILABLE and calls _finish(), ending the install (manager.py#L136-L164).

    • Tested at zigpy b4543ff, with the device answering Image Notify with queries for both types: update_firmware() returns NO_IMAGE_AVAILABLE in both orders, even when the matching query came first and was already answered with SUCCESS. Test below.

    • The same matcher is active during the block transfer. A second test (not included here) sends a query for the other type after 2 of 8 image blocks; the transfer stops after the 3rd and update_firmware() returns NO_IMAGE_AVAILABLE.

    • image_block, image_page and upgrade_end don't check the image type or manufacturer either.

    • On a NodOn this is unlikely to be bad luck; it probably happens every time. Both modules answer a broadcast Image Notify, antenna first, and the power query follows about 5 s after zigpy's reply to the antenna query (see Reports). If they answer the install's unicast notify the same way:

      • A power image install sees the antenna query first and is aborted before it starts.
      • An antenna image install starts, and is aborted when the power query arrives 5 s later.
      • With step 1, the antenna query is answered NO_IMAGE_AVAILABLE without ending the install. The power query should then follow about 5 s later and get its image.

      This follows from the code and the observed order; no install has been attempted on these devices.

  4. Other gaps.
    • After a successful install, the whole cluster's cached query and current_file_version are cleared, whichever image was flashed (device.py#L1330-L1342).
    • A second update_firmware() while one is running returns None (device.py#L1308-L1310). ZHA reports that as "Update was not successful: None".
    • Image Notify always uses the QueryJitter payload (manager.py#L310-L323). The payload types with manufacturer code and image type exist but are unused. Using them would not reliably choose a module: per ZCL R8 §11.13.3.3, if a unicast Image Notify has a non-zero payload type, "all other fields SHALL be ignored", and a device receiving a unicast notify "SHALL always send a Query Next Image request" (§11.13.3.4). Only broadcast or multicast notifies are filtered by image type.
    • Upgrade End: zigpy answers every Upgrade End Request with an Upgrade End Response and ends the install with the request's status (manager.py#L291-L308). Per §11.13.9.4, a request with INVALID_IMAGE, REQUIRE_MORE_IMAGE or ABORT should get a Default Response, not an Upgrade End Response. A device that bundles dependent images (§11.14.3) sends REQUIRE_MORE_IMAGE after each file; zigpy would treat that as a failed install. No such device is known yet, so this is only for completeness.
Test for the install abort (drop into zigpy tests/ota/)
"""Probe: a device that queries a second image type during an install."""

from unittest.mock import AsyncMock, patch

import pytest

from tests.conftest import make_app, make_node_desc
from tests.ota.test_ota_manager import make_packet
import zigpy.endpoint
from zigpy.ota import OtaImageWithMetadata
import zigpy.profiles.zha
import zigpy.types as t
from zigpy.zcl import foundation
from zigpy.zcl.clusters.general import Ota
import zigpy.zdo.types as zdo_t


@pytest.mark.parametrize("other_first", [True, False])
@patch("zigpy.ota.manager.MAX_TIME_WITHOUT_PROGRESS", 0.5)
async def test_other_image_type_query_during_install(
    image_with_metadata: OtaImageWithMetadata, other_first: bool
) -> None:
    img = image_with_metadata
    app = make_app({})
    dev = app.add_device(nwk=0x1234, ieee=t.EUI64.convert("00:11:22:33:44:55:66:77"))
    dev.node_desc = make_node_desc(logical_type=zdo_t.LogicalType.Router)
    dev.model = "model1"
    dev.manufacturer = "manufacturer1"
    ep = dev.add_endpoint(1)
    ep.status = zigpy.endpoint.Status.ZDO_INIT
    ep.profile_id = 260
    ep.device_type = zigpy.profiles.zha.DeviceType.PUMP
    ota = ep.add_output_cluster(Ota.cluster_id)

    responses = []
    other_type = img.firmware.header.image_type ^ 0x0100

    def query(image_type):
        dev.application.packet_received(
            make_packet(
                dev,
                ota,
                "query_next_image",
                field_control=Ota.QueryNextImageCommand.FieldControl.HardwareVersion,
                manufacturer_code=img.firmware.header.manufacturer_id,
                image_type=image_type,
                current_file_version=img.firmware.header.file_version - 10,
                hardware_version=1,
            )
        )

    async def send_packet(packet: t.ZigbeePacket):
        if packet.cluster_id != Ota.cluster_id:
            return
        hdr, cmd = ota.deserialize(packet.data.serialize())
        if isinstance(cmd, Ota.ImageNotifyCommand):
            order = (
                [other_type, img.firmware.header.image_type]
                if other_first
                else [img.firmware.header.image_type, other_type]
            )
            for it in order:
                query(it)
        elif isinstance(cmd, Ota.ClientCommandDefs.query_next_image_response.schema):
            responses.append(cmd.status)

    dev.application.send_packet = AsyncMock(side_effect=send_packet)
    status = await dev.update_firmware(img)
    print(f"\nother_first={other_first} status={status!r} query_responses={responses}")

Output at b4543ff:

other_first=True status=<Status.NO_IMAGE_AVAILABLE: 152> query_responses=[<Status.NO_IMAGE_AVAILABLE: 152>, <Status.SUCCESS: 0>]
other_first=False status=<Status.NO_IMAGE_AVAILABLE: 152> query_responses=[<Status.SUCCESS: 0>, <Status.NO_IMAGE_AVAILABLE: 152>]

How others handle it

  • Zigbee2MQTT does not solve it either.
    • Images are matched per query on image type and manufacturer code. All other OTA state (in progress, last checked) is per IEEE, and there is one update entity per device.
    • A manual check or update sends Image Notify and takes whichever module answers first.
    • Koenkk/zigbee2mqtt#31529 tried to key that state per image type and was closed as stale. NodOn's Koenkk/zigbee2mqtt#32405 replaces it and is still open, inactive since late August. The maintainers' replies there were that Z2M "expects 1 device = 1 OTA". Resetting the per-device last-checked time after an update was called fine and generic; some of the rest was considered specific to this device.
  • Z-Wave JS keeps one update entity per node and installs firmware targets one after the other inside a single update. That works because Z-Wave vendors ship one versioned bundle. NodOn and Inovelli release and version their images independently.
  • Other HA integrations with several firmware components per device use one update entity per component: smlight (core + per radio), shelly (main + LoRa add-on), lamarzocco (machine + gateway), reolink (host + per channel). An UpdateEntity has a single installed/latest pair.

Two things the design has to survive

1. A device can change its image type after an upgrade

Some Philips Hue bulbs switch to a different image type once a particular upgrade is applied, and from then on query only the new type.

At the query level, a device that changes type looks exactly like a device with two modules: a second image type shows up. The difference is only that the old type never comes back. Consequences:

  • Update entities should not be created automatically for every image type seen. A Hue bulb would be left with a dead entity for its old type. The cache would also keep that type's last query, so the dead entity could show a stale "update available" forever. Waiting to see whether both types keep recurring is a guess with a delay, and a module that rarely queries would defeat it.
  • A single entity must not lock onto one image type. A locked entity would freeze a Hue bulb on its old type after the change, so it would never see newer updates.
  • Today's behaviour, where the single entity follows the most recent query, is correct for this case. It has to stay the default. (More precisely, today the installed version follows each query through the mirror, while the available images follow the most recently completed lookup. Step 3 below ties both to the query time.)
2. Every successful OTA update and every Reconfigure re-interviews the device, which drops all OTA state
  • After a successful install, Device.update_firmware() calls reinterview() (device.py#L1363). HA's "Reconfigure" does the same.
    • This only happens if the post-OTA read of current_file_version does not raise (device.py#L1344-L1349). A failure status in the result is ignored. But if the read raises, update_firmware raises after a successful flash: no notify, no re-interview, and ZHA reports the update as failed.
  • The re-interview builds a fresh shadow device and swaps it in. The swap carries over only last_seen, relays, LQI/RSSI and group memberships (application.py#L670-L701).
  • It then deletes the old device's rows. ota_query_cache_v15 has a foreign key to endpoints_v15 with ON DELETE CASCADE (schema_v15.sql#L200-L218), so the persisted queries for every image type are gone. The old device object's in-memory queries are not carried over either; the cache refills only as the device queries again.
  • ZHA then rebuilds the device's entities.

Consequences:

  • Entities created from observed image types would disappear on every update or Reconfigure unless the cache is carried over (step 2 below). They would come back only when that type queries again, so updating the antenna image of a NodOn would make the power-image entity vanish for a while.
  • Entities declared by a quirk survive because they are rebuilt from the quirk. Their state starts empty, though: a secondary entity shows no installed or latest version until its image type queries again. A quirk-declared version source restores the installed version right away, e.g. reading the VZM32's 0xFC32 / 0x0073 at init. The latest version still comes from an image lookup, which today needs a cached query. zigpy could build one from the known manufacturer code, image type and that version, so the lookup doesn't have to wait for the device. Such a query has no hardware version, though, and images with hardware-version bounds don't match without one, so those still have to wait for a real query.
  • The cache should survive the swap. _device_reinterviewed should copy the per-image-type query cache to the new device, and re-persist it the way relays already are, except that the flashed image type's entry is dropped if it predates the end of the install. The pre-update query is stale, but the device may already have queried again in answer to the post-OTA notify, and that newer entry should be kept. Dropping the old entry also handles the Hue case naturally. This is the "preserve by default" direction for re-interviews in general.
  • Queued installs race with the re-interview. These follow from reading the code and were not tested.
    • ota_in_progress is reset in update_firmware's finally (device.py#L1325), before the post-OTA attribute read, notify and re-interview. Those can take minutes: a 10 s delay plus up to 10 read retries 10 s apart, then the re-interview itself.
    • If a second install starts in that window, reinterview() sees ota_in_progress and skips, with only a debug log (device.py#L602-L604). If the second install then fails, the first image's re-interview never happens. If it succeeds, its own re-interview covers both.
    • If the second install starts while the re-interview is running, update_firmware doesn't check reinterviewing, and the install runs on the old device object. During the re-interview, app.devices[ieee] already points to the shadow (device.py#L612-L614). Incoming packets therefore go to the shadow, while the old device's OTAManager listeners never see them. The install stalls, or the shadow's own Ota cluster answers the device with NO_IMAGE_AVAILABLE / ABORT.
    • So a per-device install queue has to wait for the whole update_firmware() call, re-interview included. That is not enough on its own: zigpy's device_reinterviewed event makes ZHA rebuild the device in a separate task (gateway.py#L457-L469), so the queue also has to wait for ZHA to finish that rebuild.
    • The queue must be keyed by IEEE at the gateway or application level. It cannot live in an entity or a device object, because both are replaced during the swap. The next install must look up the new device and entity.

Options

A. One update entity per image type, declared by a quirk (proposed)

  • Matches the devices: the images have independent versions and releases, as in §11.14.2.
  • A failed second install only leaves that one entity with an update pending.
  • Users see each module's version and release notes, and can choose what to update.
  • The quirk lists only the secondary image types. Everything else goes to the primary entity, so an image-type change like Hue's keeps working.
  • Survives re-interviews, since the entities come from the quirk rather than from observed queries.
  • Cost: two installs to trigger, and they have to be serialized per device (see above).

B. One entity that installs all images

  • Needs a combined version string and custom version comparison.
  • One click means two transfers, two reboots and two re-interviews in a row. The NodOn antenna image alone took about 71 minutes in a Z2M test.
  • If only the second install fails, the entity is left half-updated, which HA cannot express.
  • Only worth it for a device with a real dependency between images. No such device is known, and such a device would sequence the files itself (§11.14.3).

C. Create entities automatically, per image type seen

  • Leaves dead entities after an image-type change (Hue). Without the cache carry-over from step 2, the entities would also disappear on every OTA update or Reconfigure.
  • As an opt-in quirk flag ("split per image type seen") it would avoid the Hue case. It would still need a designated primary and runtime entity creation in ZHA, and the names would be generic ("Firmware (image type 0x0109)"). A quirk that opts in can just as easily list the types, or a rule, and get proper names.

D. Keep one entity, locked to one image type

  • Stops the flip but makes the second image impossible to update from ZHA, and freezes a device whose image type changes. Not a good default.

Proposed plan

Each step can land on its own.

  1. zigpy: stop aborting installs.
    • Answer a query for a different (manufacturer_code, image_type) with NO_IMAGE_AVAILABLE without ending the install. The stall timer still covers a device that never asks for the right image, but MAX_TIME_WITHOUT_PROGRESS is 30 s and NodOn modules poll on their own only about every 5 minutes (zigpy/zha#844). If the wanted module doesn't answer the Image Notify, a secondary install would time out after 30 s. That is why the retries below matter.
    • Check manufacturer, image type and file version in image_block, image_page and upgrade_end. The spec uses all three to identify the image being transferred (§11.13.6.4 for block requests; §11.13.7.3 and §11.13.9.2 for page and Upgrade End requests). Today _image_block_req serves the active image's bytes for any request (manager.py#L179-L223), and _upgrade_end finishes with whatever status arrives. For a block request with the wrong identity, §11.13.6.5.2 prescribes a Default Response with NO_IMAGE_AVAILABLE.
    • Keep that identity check even with force=True. Today force skips check_compatibility too, so a query for the other image type would be answered SUCCESS with this image's identity (a conforming client then rejects the response as malformed, §11.13.5.5.1) (manager.py#L142-L148).
    • Answer the other module's query with the status only. Today _image_query_req sends NO_IMAGE_AVAILABLE with manufacturer code, image type, file version and image size (manager.py#L151-L158). Per §11.13.5.2.1, "for other (error) status values, only status field SHALL be present", and a client receiving such a response should treat it as malformed (§11.13.5.5.1). The passive handler in Ota._handle_query_next_image already sends status only.
    • Make the right module ask. After answering a query for the other image type, send Image Notify again (with a short backoff) instead of waiting for the device's periodic query. A device that alternates per notify, like the VZM32, then asks for the right type next. Koenkk/zigbee2mqtt#32405 retries for the same reason ("the wrong MCU responds first to imageNotify"). The retries need their own deadline: notify() reschedules the stall timer on every successful send (manager.py#L310-L323), so retrying it unbounded would keep an install pending forever. They should also stop once the transfer has started.
    • Device-specific shortcuts: Inovelli's Hubitat driver starts the module update with zigbee.updateFirmware(manufacturer: 0x122F, type: 0x0104). That suggests Hubitat sends a notify carrying the image type and the switch honours it. This is not verified, and per the spec a unicast notify's image type is ignored. For the VZM32 a quirk could instead set P34 (otaImageType) to 0 (switch) or 1 (mmWave) for the duration of the install, and restore the previous value afterwards, on success and on failure. Left at 0 or 1, the device presumably stops querying the other module.
  2. zigpy: cache queries per image type.
    • Keep a dict[(manufacturer_code, image_type), QueryNextImageCommand] per cluster, each entry with its last-seen time. Keep last_query_cmd as a compatibility property returning the newest entry.
    • The table already has a last_updated column, but loading reads it and throws it away, and both writers stamp it with the write time. Re-saving an old entry would then make it look new. The stored time has to be when the query was received, and the loader has to restore it; otherwise "newest" is unknown after a restart.
    • Also record queries that arrive during an install. Today Ota.handle_cluster_request returns early while ota_in_progress is set, so a module that first shows up mid-install stays unknown until it queries again.
    • Change the appdb unique index to (ieee, endpoint_id, manufacturer_code, image_type). That needs a schema migration; zigpy/zigpy#1852 already adds v16, so coordinate with it.
    • check_cluster_for_ota emits one OtaImageAvailableEvent per cached image type, and the image type becomes a field on the OTA events. The same applies to the periodic check_all_devices_for_ota() that runs 60 s after each broadcast. Today it only sees the newest query, so on these NodOn modules it only ever checks the power image.
    • After an install, clear only the flashed image's entry. OtaQueryCacheClearedEvent and _delete_ota_query_cache_entry (which deletes by ieee and endpoint_id, appdb.py#L777-L781) need the image type for that.
    • Carry the cache over in _device_reinterviewed, minus the flashed image's entry (see above).
    • Carrying the cache over has to merge, not overwrite: discovery sends its own Image Notify, so the shadow may already hold newer entries than the old device.
  3. ZHA: secondary image types get their own entity; the primary takes everything else.
    • FirmwareUpdateEntity gets an image-type filter. The primary entity excludes the quirk-declared secondary types and follows the newest query among all remaining types. With no quirk, that is exactly today's behaviour, which stays correct for devices that change image type.
    • "Newest" has to mean the query's time, not the order in which availability results arrive. check_cluster_for_ota awaits an image lookup (possibly an index download) before emitting its event (ota/init.py#L303-L327), so a slow lookup for an older query can arrive after a newer one. The event should carry the query time, and the entity should ignore anything older than what it shows.
    • The primary entity keeps today's unique ID ({ieee}-{ep}-25-firmware_update), so existing entities are unchanged.
    • Only the primary image feeds the current_file_version mirror, Device.firmware_version and the HA sw_version. Today firmware_version_filter sees whichever image queried last. A primary-only mirror makes that cached value stable. It is fully deterministic only if zigpy's own reads of the attribute also report the primary module, because quirk resolution reads the raw zigpy cache before any ZHA entity exists. On NodOn the attribute is unsupported, so the mirror is the only writer. But zigpy marks the attribute unsupported after each read answered with UNSUPPORTED_ATTRIBUTE, and ota.get() then returns None until the next mirrored query clears the mark. Discovery reads it, so quirk resolution after a re-interview sees no version, and firmware_version_filter takes its allow_missing result for that resolution.
    • The current_file_version attribute itself carries no image type. zigpy reads it during discovery and after an install, and the update entity takes every attribute event as the installed version (update.py#L176-L186). firmware_version_filter reads the raw cache during quirk resolution, before any ZHA entity exists. For a device whose attribute reports a secondary module, the quirk has to be able to say so, and the primary entity must stop trusting the attribute. NodOn doesn't need this, since the attribute is unsupported there (see Reports). For NodOn, which image is primary is therefore purely the quirk's choice; the antenna (Zigbee) image is the natural one, matching the VZM32's switch image. Today HA's sw_version usually shows the power version (it starts from the last query), so this choice changes what existing users see.
    • The primary has to be chosen explicitly. Today Device.async_initialize takes sw_version from the first update entity in platform_entities (device.py#L1246-L1264), which is dict order. FirmwareUpdateEntity.__init__ seeds installed_version from the cached attribute; secondary entities must not.
    • Each secondary type gets its own entity with a stable suffix and a name. HA core's ZHA strings.json has no entity.update section yet. HA's UpdateEntity.title could also name the component, e.g. "mmWave module".
    • Diagnostics: list the cached query per image type, each with its receive time. Today the device diagnostics show a single last_query_cmd per OTA cluster with no time (device.py#L1739-L1757).
      • Use the same ISO 8601 UTC format as the existing last_seen (device.py#L1691).
      • A diagnostics download then answers the open question below about which NodOn modules answer a notify, without a debug log. It also shows how often each module polls.
      • It also shows entries that have gone stale, such as a Hue bulb's old image type.
      • The test snapshot loader restores last_seen from the stored data (tests/common.py#L389). It would have to restore these timestamps the same way, or regenerated snapshots would change on every run.
    • Without a quirk: keep today's single entity. When a cluster alternates between image types (both keep coming back), log once that the device needs a quirk declaration. This only detects; it changes no behaviour.
  4. zha-quirks: declare the secondary images.
    • A dedicated builder method, e.g. .ota_image(image_type=..., translation_key=..., fallback_name=..., version_source=...), lists the secondary types. A rule could replace the list where it is regular: NodOn's power images are all 0x01NN, one rule for all five SIN-4 pairs.
    • zigpy/zha-device-handlers#5410's .adds_entity(...) could add the entity half once step 3 exists. The device-level half (which types the primary excludes, the version source) still needs the builder method.
    • Declare Inovelli VZM32 (0x0104 "mmWave module firmware", version from 0xFC32 / 0x0073, which Koenkk/zigbee2mqtt#31904 shows as 100863491, the module image's file version) and NodOn SIN-4 (0x01NN "Power module firmware"). NodOn's Basic sw_build_id appears to encode both versions as "antenna-power" (3.12.0-3.1.3 in Koenkk/zigbee2mqtt#29293 ↔ 0x0000030C / 0x00030103; 3.0.0-1.4.4 in the ZHA SIN-4-FP-21 snapshot), so it is a candidate version source too. Also expose P34 otaImageType as a config select on VZM32, to match Z2M.
  5. zigpy/ZHA: queue installs per device instead of returning None on ota_in_progress.
    • Key the queue by IEEE at the gateway level.
    • Before the next install, wait for the full update_firmware() (re-interview included) and for ZHA's rebuild. Then target the new device and entity, carrying the endpoint along.
    • The queue should hold the selected image itself rather than re-read it from the rebuilt entity. A new entity fills its list of available images in a background task (on_add schedules check_cluster_for_ota), so it may still be empty, and async_install would fail with "No firmware updates are available".
    • Releasing the queue also requires the previous transfer to have actually stopped. _image_page_req keeps sending blocks in its own task until the page is done, without checking whether the install has already finished (manager.py#L244-L290). After an abort it can keep sending the old image while the next install runs. It should stop once the install is finished.
    • It can build on zigpy/zha#815.
    • Separately in zigpy: update_firmware should refuse to start while a re-interview is running, and reinterview() should not be skipped because a second install started. Defer it instead.
    • OTAManager should use the OTA cluster of the endpoint being updated, not the first one. Its request listeners are device-wide, so it also has to match incoming requests to that endpoint. That also fixes the two-endpoint devices above.
    • The queue needs an end state for every failure: a re-interview that fails (zigpy emits device_reinterview_failure; the old device is kept only when discovery failed, while a failure during the swap may leave partial state), a ZHA rebuild that fails, and a post-OTA read that raises before any re-interview starts. Each should release the queue, bounded by a timeout, rather than block it.
  6. Afterwards: get the NodOn images (submitted by NodOn, still open, see above) and the Inovelli mmWave image into zigpy-ota.

In-flight zigpy PRs this has to be coordinated with

  • zigpy/zigpy#1849 (open) adds a stateless "firmware version changed" check: Ota._maybe_schedule_post_ota_reinterview() re-interviews the device whenever a query's current_file_version differs from the previous query's.
    • It does not look at the image type. On a NodOn or VZM32, every alternating query differs, so it would schedule a re-interview every poll cycle. Each re-interview also rebuilds all of the device's ZHA entities.
    • #1849's new post-OTA confirmation wait (_wait_for_post_ota_confirmation) has the same problem. It snapshots last_query_cmd.current_file_version, which may belong to the other module, and treats any query with a different version as confirmation. So the other module's next routine query would "confirm" the flash at once, and the re-interview would start while the flashed module may still be rebooting.
    • Both comparisons have to be per image type before #1849 merges, independently of the rest of this plan, with the flashed image type's entry as the baseline.
    • With a per-image-type baseline, a device that changes image type after an update done outside zigpy (the Hue case) sends a query for a type with no baseline. #1849 skips first observations, so it would not notice. Treating "a new image type on a cluster that already has entries" as a change would cover that.
    • #1849 also stops clearing the query cache after an install and replaces the fixed post-OTA read/notify/re-interview sequence with a confirmation wait. zigpy/zigpy#1850 / zigpy/zigpy#1851 can defer the re-interview to the device's next check-in.
    • The "clear only the flashed entry" rule (step 2) and the queue's "wait for the re-interview" (step 5) have to be built on whichever flow lands. A re-interview deferred to a check-in must not block the queue indefinitely.
  • zigpy/zigpy#1852 adds schema v16, the natural place for the new cache key (step 2).

Open questions

  • Do both NodOn modules answer a unicast Image Notify (the kind an install sends) the way they answer the broadcast one: antenna after about 140 ms, power about 5 s later (see Reports)? If so, a notify retry in step 1 will always see the antenna query first. Getting the power module to transfer then depends on zigpy answering the antenna query without ending the install (step 1), not on retrying. The power query is only sent after the antenna query has been answered, so ignoring it would probably delay or suppress the power query.
  • Does the VZM32 on current firmware still alternate per Image Notify, as described in zigpy/zigpy#1610?
  • Are any NodOn antenna/power version combinations incompatible with each other? No source mentions one.
  • A concrete Hue model and version where the image type changes would make a good test case for steps 2 and 3.
Lingua principale
Python
Stelle
96
Fork
84
Merge medio
3g 1h
PR unite (30g)
13

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di zigpy/zha

Tutte le issue di zigpy/zha

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.