Skip to content

Fix set_state dropping False, 0, and None values#2594

Open
Ten0 wants to merge 1 commit intoAppDaemon:devfrom
Ten0:fix_set_state
Open

Fix set_state dropping False, 0, and None values#2594
Ten0 wants to merge 1 commit intoAppDaemon:devfrom
Ten0:fix_set_state

Conversation

@Ten0
Copy link
Copy Markdown
Contributor

@Ten0 Ten0 commented Apr 11, 2026

Fixes #2531
Fixes #2464
Fixes #2492

Two bugs caused set_state (and other POST calls) to lose attribute values:

  1. remove_literals used equality (==) to filter values, so 0 and 0.0 were removed alongside False (because 0 == False in Python). Fixed by switching to identity comparison (is).

  2. clean_http_kwargs was applied globally to all HTTP methods, stripping False, None, and converting True to "true" even in POST JSON bodies where these are valid values. Replaced with a new self-contained clean_http_params_for_urlencode applied only to GET/DELETE query parameters; POST bodies are now passed transparently through the session's convert_json serializer. Removed the now-unused clean_kwargs function.

Also:

  • Removed redundant clean_kwargs + remove_literals from websocket path; convert_json handles datetime serialization.
  • Performance tracking now computes actual payload size per HTTP method.

I have tested this on my own HomeAssistant instance, and this does indeed solve the issue and it seems my home finally works properly without triggering exceptions on 4.5 with that change, so I might finally update from 4.4 once this is released. 🎉

Fixes AppDaemon#2531
Fixes AppDaemon#2464
Fixes AppDaemon#2492

Two bugs caused set_state (and other POST calls) to lose attribute
values:

1. remove_literals used equality (==) to filter values, so 0 and 0.0
   were removed alongside False (because 0 == False in Python).
   Fixed by switching to identity comparison (is).

2. clean_http_kwargs was applied globally to all HTTP methods, stripping
   False, None, and converting True to "true" even in POST JSON bodies
   where these are valid values. Replaced with a new self-contained
   clean_http_params_for_urlencode applied only to GET/DELETE query
   parameters; POST bodies are now passed transparently through the
   session's convert_json serializer. Removed the now-unused
   clean_kwargs function.

Also:
- Removed redundant clean_kwargs + remove_literals from websocket path;
  convert_json handles datetime serialization.
- Performance tracking now computes actual payload size per HTTP method.
@jsl12 jsl12 closed this Apr 11, 2026
@jsl12 jsl12 reopened this Apr 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants