Skip to content

πŸ› fix(mqtt): fall back to installed tag in HASS latest_version template (#491)#492

Open
scttbnsn wants to merge 1 commit into
mainfrom
fix/491-hass-latest-version
Open

πŸ› fix(mqtt): fall back to installed tag in HASS latest_version template (#491)#492
scttbnsn wants to merge 1 commit into
mainfrom
fix/491-hass-latest-version

Conversation

@scttbnsn

@scttbnsn scttbnsn commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

What

Fixes the Home Assistant update.dd_container_* entities showing "Unknown" for the "Newest version" attribute (and the entity state as a whole) on containers that are up to date, reported over MQTT + HASS discovery.

Root cause

The HASS discovery latest_version template was:

{% if value_json.update_kind_kind == "digest" %}{{ value_json.result_digest[:15] }}{% else %}{{ value_json.result_tag }}{% endif %}

When a container has no pending update, container.result is absent, so the flattened MQTT state payload carries no result_tag / result_digest. Both branches of the template then render an empty string. Home Assistant silently discards an empty latest_version render, so the "Newest version" attribute never gets set β€” and because HA blanks the whole update.* entity state when either the installed or latest version is missing, the entity reads Unknown forever instead of resolving to "up to date".

Fix

Fall back to the installed image tag (image_tag_value) in both branches when no update result is present, and guard the digest slice so a digest-kind report that somehow carries no digest doesn't trip HA's Undefined[:15] Jinja error:

{% if value_json.update_kind_kind == "digest" %}{{ value_json.result_digest[:15] if value_json.result_digest else value_json.image_tag_value }}{% else %}{{ value_json.result_tag if value_json.result_tag else value_json.image_tag_value }}{% endif %}

Now an up-to-date container reports latest == installed, which HA renders as "up to date".

Tests

  • Mqtt.test.ts β€” new payload-contract test that builds real containers through the model pipeline and locks the flattened-payload shape the template depends on: an up-to-date container carries image_tag_value but no result_* keys (exactly the case that used to render empty); a tag update carries result_tag; a digest update carries result_digest.
  • Hass.test.ts β€” the existing HA-discovery-payload assertion is updated to pin the new latest_version_template string, so a future "simplification" can't silently regress this.

Note on the reporter's "0 messages"

The issue log also shows 0 most recent received messages on the state topic dd/container/local/homeassistant, which would independently blank both Installed and Newest. That half isn't reproducible from the source β€” mustTrigger passes for a plain up-to-date container and trigger() publishes a retained state payload on every container event regardless of update status. Confirming it needs the reporter's debug-level logs (the Publish container result to … line). This PR fixes the template bug that is reproducible and real; the state-delivery question is being followed up on the issue.

Fixes #491

πŸ› Fixed

  • Updated the Home Assistant MQTT discovery template for update.dd_container_* so up-to-date containers no longer render Unknown for installed/newest version fields.
  • Added a fallback to image_tag_value when no update result is present.
  • Guarded the digest slice so missing result_digest no longer causes template errors.

πŸ”§ Changed

  • Adjusted the Home Assistant discovery payload test to match the new template behavior.

  • Added MQTT payload contract coverage for up-to-date, tag-update, and digest-update cases.

  • Verify the flattened MQTT payload shape still matches all existing Home Assistant discovery consumers.

  • Confirm the latest_version_template behavior with both tag-based and digest-based updates in Home Assistant.

…te (#491)

The Home Assistant MQTT discovery latest_version template rendered an empty
string for any container with no pending update (no `result` in the flattened
state payload, so no `result_tag`/`result_digest`). HA silently discards an
empty template render, leaving "Newest version" unset β€” and because HA blanks
the whole `update.*` entity state when either version is missing, the entity
read "Unknown" forever instead of resolving to "up to date".

The template now falls back to `image_tag_value` (the installed tag) in both
the digest and tag branches, and guards the digest slice with
`if value_json.result_digest` so a digest-kind report carrying no digest no
longer trips HA's `Undefined[:15]` slice error.

- βœ… test(mqtt): lock the flattened-payload contract the template reads
  (up-to-date β†’ image_tag_value + no result_*; tag/digest β†’ matching result_*)
- βœ… test(mqtt): pin the new latest_version_template string in the HA discovery payload

Fixes: #491
@vercel

vercel Bot commented Jul 7, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
drydock-website Ready Ready Preview, Comment Jul 7, 2026 2:50am
drydockdemo-website Ready Ready Preview, Comment Jul 7, 2026 2:50am

@coderabbitai

coderabbitai Bot commented Jul 7, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. πŸŽ‰

ℹ️ Recent review info
βš™οΈ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 76215711-b966-49ad-93d3-2668a955a1b9

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 68a5c2d and b5a9e00.

β›” Files ignored due to path filters (1)
  • CHANGELOG.md is excluded by !CHANGELOG.md
πŸ“’ Files selected for processing (3)
  • app/triggers/providers/mqtt/Hass.test.ts
  • app/triggers/providers/mqtt/Hass.ts
  • app/triggers/providers/mqtt/Mqtt.test.ts

πŸ“ Walkthrough

Walkthrough

Modifies the Home Assistant MQTT discovery latest_version_template in Hass.ts to fall back to image_tag_value when result_tag or result_digest are absent, and guards result_digest slicing with a presence check, addressing "Unknown" values in Home Assistant update entities. Updates the corresponding test expectation in Hass.test.ts. Adds a new regression test in Mqtt.test.ts, importing validate, verifying flattened MQTT payload field presence/absence across current, tag-update, and digest-update container states.

Changes

Area Change
Hass.ts Updated latest_version_template Jinja logic with fallback to image_tag_value; expanded comments
Hass.test.ts Updated expected value_template string to match new fallback logic
Mqtt.test.ts Added validate import; new regression test for flattened payload shape (issue #491)

Sequence Diagram(s)

Not applicable β€” changes are template logic and test assertions, not runtime call flows.

Related Issues: #491

Related PRs: None identified.

Suggested labels: bug, mqtt, home-assistant

Suggested reviewers: None identified.

Review note: result_digest[:15] slicing is now guarded but confirm Jinja [:15] doesn't throw on None/undefined β€” verify with {% if value_json.result_digest %} truthiness rather than presence-only check, since empty string would still fall through to fallback incorrectly if that's not intended.

Poem:
A rabbit sniffs the MQTT wire,
finds "Unknown" where updates should transpire.
Now image_tag_value steps in to save the day,
when tag and digest have wandered away.
Hop, test, confirm β€” no more entities in disarray. πŸ‡

πŸš₯ Pre-merge checks | βœ… 2
βœ… Passed checks (2 passed)
Check name Status Explanation
Linked Issues check βœ… Passed The MQTT HASS discovery template now falls back to image_tag_value and guards digest slicing, matching the up-to-date and update-available cases in #491.
Out of Scope Changes check βœ… Passed All changed files stay within the MQTT Home Assistant discovery fix and its regression tests; no unrelated code changes are evident.
✨ Finishing Touches
πŸ“ Generate docstrings
  • Create stacked PR
  • Commit on current branch
πŸ§ͺ Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/491-hass-latest-version

Comment @coderabbitai help to get the list of available commands.

scttbnsn added a commit that referenced this pull request Jul 7, 2026
…te (#491)

Forward-port of b5a9e00 (PR #492, 1.5.1 line) onto dev/v1.6.

The Home Assistant MQTT discovery latest_version template rendered an empty
string for any container with no pending update (no `result` in the flattened
state payload, so no `result_tag`/`result_digest`). HA silently discards an
empty template render, leaving "Newest version" unset β€” and because HA blanks
the whole `update.*` entity state when either version is missing, the entity
read "Unknown" forever instead of resolving to "up to date".

The template now falls back to `image_tag_value` (the installed tag) in both
the digest and tag branches, and guards the digest slice with
`if value_json.result_digest` so a digest-kind report carrying no digest no
longer trips HA's `Undefined[:15]` slice error.

CHANGELOG entry intentionally omitted β€” it lives on the 1.5.1 line; the fix
ships there first, so v1.6 inherits it without a duplicate changelog note.

Fixes: #491
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.

update.dd_container entitites in HA not updated by MQTT+HASS

1 participant