Skip to content

fix: get_plugin_config() is synchronous in all AppDaemon >= 4.5.0#201

Closed
roopesh wants to merge 1 commit intoxaf:mainfrom
roopesh:fix/get-plugin-config-sync-ad-4-5
Closed

fix: get_plugin_config() is synchronous in all AppDaemon >= 4.5.0#201
roopesh wants to merge 1 commit intoxaf:mainfrom
roopesh:fix/get-plugin-config-sync-ad-4-5

Conversation

@roopesh
Copy link

@roopesh roopesh commented Mar 16, 2026

Problem

gateway.py has a version-guard that decides whether to await get_plugin_config() or call it synchronously:

async_removed = (ad_version >= (0, 17, 0) and ad_version < (0, 17, 2)) or \
    (ad_version >= (4, 5, 0) and ad_version < (4, 5, 3))

The upper bound < (4, 5, 3) was written with the assumption that AppDaemon would restore the async variant in 4.5.3. That never happened — get_plugin_config() has remained synchronous in every release from 4.5.0 onwards.

As a result, any AppDaemon version >= 4.5.3 (e.g. 4.5.12, shipped with HA add-on v0.17.12) hits the else branch and calls:

mqtt_plugin_cfg = await self.get_plugin_config(namespace=cfg.mqtt_namespace)

await-ing a plain (non-awaitable) return value raises a TypeError, crashing the gateway during initialize() and preventing the IQ panel integration from ever starting. This is the root cause of the failures reported in #197.

Fix

Remove the upper bound so that all AppDaemon >= 4.5.0 is treated as synchronous:

# Before
async_removed = (ad_version >= (0, 17, 0) and ad_version < (0, 17, 2)) or \
    (ad_version >= (4, 5, 0) and ad_version < (4, 5, 3))

# After
async_removed = (ad_version >= (0, 17, 0) and ad_version < (0, 17, 2)) or \
    (ad_version >= (4, 5, 0))

Tested

Verified on HA add-on v0.17.12 (AppDaemon 4.5.12): gateway initializes successfully, connects to the IQ Panel, and entities are published via MQTT discovery as expected.

Fixes #197

The upper bound `< (4, 5, 3)` assumed that AppDaemon would restore the
async variant of get_plugin_config() in 4.5.3, but it has remained
synchronous in every release from 4.5.0 onwards.

Any AppDaemon version >= 4.5.3 (e.g. 4.5.12, shipped with HA add-on
v0.17.12) hit the else branch and called:

    mqtt_plugin_cfg = await self.get_plugin_config(namespace=...)

Awaiting a plain (non-awaitable) return value raises a TypeError,
crashing the gateway during initialize() and preventing the IQ panel
integration from starting.

Fix by removing the upper bound so all AD >= 4.5.0 is treated as sync.

Fixes xaf#197

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@xaf
Copy link
Owner

xaf commented Mar 17, 2026

@roopesh I thought the change was already merged to revert in 4.5.3 at the time I patched this - did they revert the change?

Also, I think you'll need to fix the tests for this to work.

@roopesh
Copy link
Author

roopesh commented Mar 17, 2026

I guess so? I know I had been unable to update AppDaemon for a long time. I finally asked Claude to figure it out and this is what they came up with - and I was able to update AppDaemon finally. Are you on the latest AppDaemon?

@xaf
Copy link
Owner

xaf commented Mar 17, 2026

I am on 4.5.13 and it seems to be working fine:

/usr/src/app $ python3 -m appdaemon -v
__main__.py 4.5.13
/usr/src/app $

@roopesh
Copy link
Author

roopesh commented Mar 17, 2026

Hm I'm on the HA App of AppDaemon, which is 0.18.1, which seems to be AppDaemon 4.5.13 as well. 🤷🏽‍♂️. Are you running AppDaemon standalone or another image?

@xaf
Copy link
Owner

xaf commented Mar 17, 2026

I am running the acockburn/appdaemon:latest docker image, as well as the home assistant official docker image.

I just quickly checked:
https://github.com/AppDaemon/appdaemon/blob/d491a58115c5baece5f902ec477c75dfd5366e2c/appdaemon/adapi.py#L943

This function is still async so this is not the issue!

@roopesh
Copy link
Author

roopesh commented Mar 17, 2026

I have no idea why this works for me 🤷🏽‍♂️ - i had rolled back AppDaemon at least 3x because it kept breaking on me. Oh well! I'll pull the PR back.

@roopesh roopesh closed this Mar 17, 2026
@roopesh roopesh deleted the fix/get-plugin-config-sync-ad-4-5 branch March 17, 2026 01:25
@xaf
Copy link
Owner

xaf commented Mar 17, 2026

@roopesh the other surprising aspect is that your fix also does not touch the part about the Add-On version, so it means your change is actually a no-op for you since you only touch the standalone appdaemon version, not the add-on one!

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.

MQTT plugin not loading in Home Assistant AppDaemon add-on v0.17.12

2 participants