Repository: alandtse/alexa_media_player

Issue #2256: RuntimeError: Detected that custom integration 'alexa_media' calls async_write_ha_state
Created: 2024-05-07T15:20:52Z
IMPORTANT: Please search the issues, including closed issues, and the FAQ before opening a new issue. The template is mandatory; failure to use it will result in issue closure.
Describe the bug
Received this error today, not sure what caused it, I just found it in the logs. I am not aware of anything failing. I have only just updated HA and the integration to latest levels (yesterday).
Logger: homeassistant
Source: helpers/frame.py:203
First occurred: 15:44:20 (1 occurrences)
Last logged: 15:44:20

Error doing job: Future exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/alexa_media/sensor.py", line 433, in _trigger_event
    self.hass.bus.async_fire(
  File "/usr/src/homeassistant/homeassistant/core.py", line 1508, in async_fire
    self._hass.verify_event_loop_thread("async_fire")
  File "/usr/src/homeassistant/homeassistant/core.py", line 440, in verify_event_loop_thread
    frame.report(
  File "/usr/src/homeassistant/homeassistant/helpers/frame.py", line 162, in report
    _report_integration(what, integration_frame, level, error_if_integration)
  File "/usr/src/homeassistant/homeassistant/helpers/frame.py", line 203, in _report_integration
    raise RuntimeError(
RuntimeError: Detected that custom integration 'alexa_media' calls async_fire from a thread at custom_components/alexa_media/sensor.py, line 433: self.hass.bus.async_fire(. Please report it to the author of the 'alexa_media' custom integration.

To Reproduce
Cannot reproduce.
Expected behavior

Screenshots

System details

Home-assistant (version): 2024.5.2
alexa_media (version from const.py or HA startup): 4.10.0
alexapy (version from pip show alexapy or HA startup): 1.27.10
Amazon 2FA is enabled (y/n). <!---We will not debug login issues if unanswered--->: YES

Logs
Please provide logs.
Additional context

Duplicate issue #2274: Alexa Media Player Errors in the Log file
Created: 2024-06-01T05:57:58Z
IMPORTANT: Please search the issues, including closed issues, and the FAQ before opening a new issue. The template is mandatory; failure to use it will result in issue closure.
I have latest HA version and Latest Alexa Media Player.
When Alexa Media starts playing the notification, an error below appeared in the logs, although notification and radio station play still works.
Thank you very much for the correction.
To Reproduce


Go to '...'
Click on '....'
Scroll down to '....'
See error

Expected behavior
No Errors in the logs.
Screenshots

System details

Home-assistant (version):  	core-2024.5.5
alexa_media (version from const.py or HA startup):  4.10.0
alexapy (version from pip show alexapy or HA startup): 1.27.10
Amazon 2FA is enabled (y/n). <!---We will not debug login issues if unanswered--->:  yes

Logs
2024-06-01 07:32:17.669 INFO (MainThread) [homeassistant.components.automation.alexa_play_bathroom_radio_when_presence_detected] Alexa -> Play Bathroom Radio when Presence detected: Choose at step 1: default: Executing step call service
2024-06-01 07:32:17.671 INFO (MainThread) [homeassistant.components.automation.alexa_play_bathroom_radio_when_presence_detected] Alexa -> Play Bathroom Radio when Presence detected: Choose at step 1: default: Executing step delay 0:00:08
2024-06-01 07:32:24.415 WARNING (SyncWorker_57) [homeassistant.helpers.frame] Detected that custom integration 'alexa_media' calls async_write_ha_state from a thread at custom_components/alexa_media/switch.py, line 217: self.async_write_ha_state(), please report it to the author of the 'alexa_media' custom integration
2024-06-01 07:32:24.422 WARNING (SyncWorker_21) [homeassistant.helpers.frame] Detected that custom integration 'alexa_media' calls async_write_ha_state from a thread at custom_components/alexa_media/switch.py, line 217: self.async_write_ha_state(), please report it to the author of the 'alexa_media' custom integration
2024-06-01 07:32:24.426 ERROR (SyncWorker_57) [homeassistant.util.logging] Exception in _handle_event when dispatching 'alexa_media_r**d@y': ({'queue_state': {'dopplerId': {'deviceSerialNumber': 'd606acd1e2f94dbfaf63afee54b53246', 'deviceType': 'AP1F6KUH00ZPY'}, 'changeType': 'STATUS_CHANGED', 'playBackOrder': 'NORMAL', 'loopMode': 'NORMAL', 'trackOrderChanged': False, 'destinationUserId': 'A1I4R6938V5HQB'}},)
Traceback (most recent call last):
File "/config/custom_components/alexa_media/switch.py", line 217, in _handle_event
self.async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1008, in async_write_ha_state
self.hass.verify_event_loop_thread("async_write_ha_state")
File "/usr/src/homeassistant/homeassistant/core.py", line 440, in verify_event_loop_thread
frame.report(
File "/usr/src/homeassistant/homeassistant/helpers/frame.py", line 162, in report
_report_integration(what, integration_frame, level, error_if_integration)
File "/usr/src/homeassistant/homeassistant/helpers/frame.py", line 203, in _report_integration
raise RuntimeError(
RuntimeError: Detected that custom integration 'alexa_media' calls async_write_ha_state from a thread at custom_components/alexa_media/switch.py, line 217: self.async_write_ha_state(). Please report it to the author of the 'alexa_media' custom integration.
2024-06-01 07:32:24.433 ERROR (SyncWorker_21) [homeassistant.util.logging] Exception in _handle_event when dispatching 'alexa_media_r**d@y': ({'queue_state': {'dopplerId': {'deviceSerialNumber': 'd606acd1e2f94dbfaf63afee54b53246', 'deviceType': 'AP1F6KUH00ZPY'}, 'changeType': 'STATUS_CHANGED', 'playBackOrder': 'NORMAL', 'loopMode': 'NORMAL', 'trackOrderChanged': False, 'destinationUserId': 'A1I4R6938V5HQB'}},)
Traceback (most recent call last):
File "/config/custom_components/alexa_media/switch.py", line 217, in _handle_event
self.async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1008, in async_write_ha_state
self.hass.verify_event_loop_thread("async_write_ha_state")
File "/usr/src/homeassistant/homeassistant/core.py", line 440, in verify_event_loop_thread
frame.report(
File "/usr/src/homeassistant/homeassistant/helpers/frame.py", line 162, in report
_report_integration(what, integration_frame, level, error_if_integration)
File "/usr/src/homeassistant/homeassistant/helpers/frame.py", line 203, in _report_integration
raise RuntimeError(
RuntimeError: Detected that custom integration 'alexa_media' calls async_write_ha_state from a thread at custom_components/alexa_media/switch.py, line 217: self.async_write_ha_state(). Please report it to the author of the 'alexa_media' custom integration.
2024-06-01 07:32:25.674 INFO (MainThread) [homeassistant.components.automation.alexa_play_bathroom_radio_when_presence_detected] Alexa -> Play Bathroom Radio when Presence detected: Choose at step 1: default: Executing step call service
2024-06-01 07:32:25.676 INFO (MainThread) [homeassistant.components.automation.alexa_play_bathroom_radio_when_presence_detected] Alexa -> Play Bathroom Radio when Presence detected: Choose at step 1: default: Executing step wait for trigger
2024-06-01 07:32:25.676 INFO (MainThread) [homeassistant.components.automation.alexa_play_bathroom_radio_when_presence_detected] Alexa -> Play Bathroom Radio when Presence detected: Choose at step 1: default: Initialized trigger
2024-06-01 07:32:28.527 WARNING (SyncWorker_0) [homeassistant.helpers.frame] Detected that custom integration 'alexa_media' calls async_write_ha_state from a thread at custom_components/alexa_media/switch.py, line 217: self.async_write_ha_state(), please report it to the author of the 'alexa_media' custom integration
2024-06-01 07:32:28.536 WARNING (SyncWorker_53) [homeassistant.helpers.frame] Detected that custom integration 'alexa_media' calls async_write_ha_state from a thread at custom_components/alexa_media/switch.py, line 217: self.async_write_ha_state(), please report it to the author of the 'alexa_media' custom integration
2024-06-01 07:32:28.541 ERROR (SyncWorker_53) [homeassistant.util.logging] Exception in _handle_event when dispatching 'alexa_media_r**d@y': ({'queue_state': {'dopplerId': {'deviceSerialNumber': 'd606acd1e2f94dbfaf63afee54b53246', 'deviceType': 'AP1F6KUH00ZPY''}, 'changeType': 'NEW_QUEUE', 'playBackOrder': 'NORMAL', 'loopMode': 'NORMAL', 'trackOrderChanged': False, 'destinationUserId': 'A1I4R6938V5HQB'}},)
Traceback (most recent call last):
File "/config/custom_components/alexa_media/switch.py", line 217, in _handle_event
self.async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1008, in async_write_ha_state
self.hass.verify_event_loop_thread("async_write_ha_state")
File "/usr/src/homeassistant/homeassistant/core.py", line 440, in verify_event_loop_thread
frame.report(
File "/usr/src/homeassistant/homeassistant/helpers/frame.py", line 162, in report
_report_integration(what, integration_frame, level, error_if_integration)
File "/usr/src/homeassistant/homeassistant/helpers/frame.py", line 203, in _report_integration
raise RuntimeError(
RuntimeError: Detected that custom integration 'alexa_media' calls async_write_ha_state from a thread at custom_components/alexa_media/switch.py, line 217: self.async_write_ha_state(). Please report it to the author of the 'alexa_media' custom integration.
2024-06-01 07:32:28.542 ERROR (SyncWorker_0) [homeassistant.util.logging] Exception in _handle_event when dispatching 'alexa_media_r**d@y': ({'queue_state': {'dopplerId': {'deviceSerialNumber': 'd606acd1e2f94dbfaf63afee54b53246', 'deviceType': 'AP1F6KUH00ZPY'}, 'changeType': 'NEW_QUEUE', 'playBackOrder': 'NORMAL', 'loopMode': 'NORMAL', 'trackOrderChanged': False, 'destinationUserId': 'A1I4R6938V5HQB'}},)
Traceback (most recent call last):
File "/config/custom_components/alexa_media/switch.py", line 217, in _handle_event
self.async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1008, in async_write_ha_state
self.hass.verify_event_loop_thread("async_write_ha_state")
File "/usr/src/homeassistant/homeassistant/core.py", line 440, in verify_event_loop_thread
frame.report(
File "/usr/src/homeassistant/homeassistant/helpers/frame.py", line 162, in report
_report_integration(what, integration_frame, level, error_if_integration)
File "/usr/src/homeassistant/homeassistant/helpers/frame.py", line 203, in _report_integration
raise RuntimeError(
RuntimeError: Detected that custom integration 'alexa_media' calls async_write_ha_state from a thread at custom_components/alexa_media/switch.py, line 217: self.async_write_ha_state(). Please report it to the author of the 'alexa_media' custom integration.

Closing comment (2024-06-08T04:56:12Z): Dupe of #2256