HomeAssistantPlugin icon indicating copy to clipboard operation
HomeAssistantPlugin copied to clipboard

fix(switch): drop await on sync async_schedule_update_ha_state

Open daboynb opened this issue 6 months ago • 0 comments

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

  • [x] Applied to a live HA Container (2025.x, Python 3.14), restarted HA
  • [x] AC switch entities still update state correctly on action and on incoming device events
  • [x] No TypeError / NoneType awaited traceback in HA logs across multiple debounce-window-crossing actions
  • [x] 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)

daboynb avatar May 22 '26 07:05 daboynb