Skip to content

fix(switch): drop await on sync async_schedule_update_ha_state#36

Open
daboynb wants to merge 1 commit into
Connectlife-LLC:mainfrom
daboynb:fix/switch-await-on-sync-callback
Open

fix(switch): drop await on sync async_schedule_update_ha_state#36
daboynb wants to merge 1 commit into
Connectlife-LLC:mainfrom
daboynb:fix/switch-await-on-sync-callback

Conversation

@daboynb
Copy link
Copy Markdown

@daboynb daboynb commented May 22, 2026

Summary

  • Remove erroneous await on self.async_schedule_update_ha_state(True) at two call sites in switch.py (lines 272 and 474).
  • async_schedule_update_ha_state is a @callback def in HA core (homeassistant/helpers/entity.py:1313-1314) — sync, returns None. Awaiting it raises TypeError: 'NoneType' object can't be awaited.
  • Removing await matches the fire-and-forget semantics implied by the async_schedule_* name. State still propagates correctly because the callback schedules an HA state write internally.

Reproduction

On HA Container 2024.11+, every AC switch state change outside the debounce window logs:

ERROR (SyncWorker_N) [homeassistant] Error doing job: Task exception was never retrieved (task: None)
Traceback (most recent call last):
  File "/config/custom_components/hisense_ac_plugin/switch.py", line 474, in _async_schedule_update
    await self.async_schedule_update_ha_state(True)
TypeError: 'NoneType' object can't be awaited

The same pattern fires from line 272 when device state-change events arrive outside the debounce window.

Test plan

  • Applied to a live HA Container (2025.x, Python 3.14), restarted HA
  • AC switch entities still update state correctly on action and on incoming device events
  • No TypeError / NoneType awaited traceback in HA logs across multiple debounce-window-crossing actions
  • Diff is 2 lines, behavior change limited to removing the erroneous await

Diff

-        await self.async_schedule_update_ha_state(True)
+        self.async_schedule_update_ha_state(True)

(applied at both lines 272 and 474)

async_schedule_update_ha_state is a @callback def in HA core
(homeassistant/helpers/entity.py:1313-1314 on master) — sync, returns
None. Awaiting it raises:

  TypeError: 'NoneType' object can't be awaited

Two call sites in switch.py used `await`:
  - HisenseSwitch._async_schedule_update (line 272)
  - debounce-else branch (line 474)

Removing the `await` matches callback semantics implied by the
`async_schedule_*` name (fire-and-forget schedule, not coroutine).
The state still propagates correctly because the callback schedules
an HA write internally.

Reproduces on HA 2024.11+: every AC switch state change outside the
debounce window logs a TypeError traceback. After the patch the
entity updates without error.
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.

1 participant