Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error - Unable to serialize to JSON: Object of type coroutine is not JSON serializable #302

Closed
danielmihalache1983 opened this issue Aug 26, 2019 · 13 comments · Fixed by #314
Labels
bug Something isn't working

Comments

@danielmihalache1983
Copy link

danielmihalache1983 commented Aug 26, 2019

Hi, I`m not sure this is alexa_media related but it looks like so.
I get this error:
Version 2.0

ERROR (MainThread) [homeassistant.components.websocket_api.http.connection.1827548752] Unable to serialize to JSON: Object of type coroutine is not JSON serializable {'id': 2, 'type': 'event', 'event': {'event_type': 'state_changed', 'data': {'entity_id': 'media_player.daniel_s_echo_dot', 'old_state': <state media_player.daniel_s_echo_dot=standby; is_volume_muted=False, media_content_type=standby, media_position_updated_at=2019-08-25T23:11:45.106361+03:00, source=Ugreen-Bluetooth05, source_list=['Local Speaker'], available=True, last_called=True, friendly_name=Daniel's Echo Dot, supported_features=56253 @ 2019-08-26T10:25:47.559961+03:00>, 'new_state': <state media_player.daniel_s_echo_dot=standby; is_volume_muted=False, media_content_type=standby, media_position_updated_at=2019-08-25T23:11:45.106361+03:00, source=<coroutine object AlexaClient._get_source at 0x72b620c0>, source_list=<coroutine object AlexaClient._get_source_list at 0x6f0efd68>, available=True, last_called=True, friendly_name=Daniel's Echo Dot, supported_features=56253 @ 2019-08-26T10:25:47.559961+03:00>}, 'origin': 'LOCAL', 'time_fired': datetime.datetime(2019, 8, 26, 8, 1, 49, 181128, tzinfo=<UTC>), 'context': {'id': '715f4156742e4a23beb612ccf57fdf5e', 'parent_id': None, 'user_id': None}}}

@alandtse
Copy link
Owner

Need more log context to know but initially we don't actually use the websocket_api component so I don't think it's coming from us. It is referencing an event we are publishing though.

Are you selecting a media source when this happens?

@danielmihalache1983
Copy link
Author

danielmihalache1983 commented Aug 26, 2019

Error occurs multiple times through out the day when I actually am not home. So I wasn`t selecting media source.
Another occurrence is like so:
2019-08-26 11:01:51 WARNING (Recorder) [homeassistant.components.recorder] State is not JSON serializable: <state media_player.daniel_s_echo_dot=standby; is_volume_muted=False, media_content_type=standby, media_position_updated_at=2019-08-25T23:11:45.106361+03:00, source=<coroutine object AlexaClient._get_source at 0x72b620c0>, source_list=<coroutine object AlexaClient._get_source_list at 0x6f0efd68>, available=True, last_called=True, friendly_name=Daniel's Echo Dot, supported_features=56253 @ 2019-08-26T10:25:47.559961+03:00>

And most of the occurrences are like:
2019-08-26 12:59:35 ERROR (MainThread) [homeassistant.components.http.view] Unable to serialize to JSON: Object of type coroutine is not JSON serializable
and then is the complete homeassistant entities json.
the relevant part is this:
<state media_player.this_device=standby; is_volume_muted=False, media_content_type=standby, media_position_updated_at=2019-08-25T23:11:44.572081+03:00, source=Local Speaker, source_list=['Local Speaker'], available=True, last_called=False, friendly_name=This Device, supported_features=56253 @ 2019-08-25T23:11:22.535554+03:00>, <state media_player.daniel_s_echo_dot=standby; is_volume_muted=False, media_content_type=standby, media_position_updated_at=2019-08-25T23:11:45.106361+03:00, source=<coroutine object AlexaClient._get_source at 0x72b620c0>, source_list=<coroutine object AlexaClient._get_source_list at 0x6f0efd68>, available=True, last_called=True, friendly_name=Daniel's Echo Dot, supported_features=56253 @ 2019-08-26T10:25:47.559961+03:00>, <state media_player.daniel_s_alexa_apps=unavailable; friendly_name=Daniel's Alexa Apps, supported_features=56253 @ 2019-08-25T23:11:22.546134+03:00>, <state switch.this_device_shuffle_switch=off; friendly_name=This Device shuffle switch @ 2019-08-25T23:11:39.823039+03:00>, <state switch.daniel_s_alexa_apps_repeat_switch=off;

@danielmihalache1983
Copy link
Author

The worst part is that homeassistant lovelace interface hangs on "loading data" screen.
I had to ssh and manually restart homeassistant.
I disabled alexa_media for now, trying to figure out who triggered the "loading data" screen hang.

@alandtse
Copy link
Owner

Do you have debugging enabled for the component? That may help to determine if the component is having the issue.

If disabling alexa_media doesn't help, the json error you're seeing looks related to the Recorder so it may be that the recorder is crashing because of the malformed data and is causing the issue too.

@danielmihalache1983
Copy link
Author

No I don`t have debugging enabled. Could you link to somewhere how can I enable?

Anyway, this bit of info
source_list=<coroutine object AlexaClient._get_source_list at 0x6f0efd68>
isn`t generated by alexa_media component?

@alandtse
Copy link
Owner

Yes, the event is generated by alexa_media. Not clear though that the alexa_media component is actually crashing. It looks like HA may have a bug in homeassistant.components.http.view and homeassistant.components.recorder where it's not properly catching for components that may create malformed events and thus crashes. I'd suggest opening an issue there too.

Regardless, there is a bug in our state generation and I've fixed it in #303. Can you please manually replace the file and let me know if the issue is resolved?

@danielmihalache1983
Copy link
Author

Done, will get back with updates.

@danielmihalache1983
Copy link
Author

I get this
2019-08-27 20:52:04 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved Traceback (most recent call last): File "/config/custom_components/alexa_media/media_player.py", line 199, in _handle_event await self.async_schedule_update_ha_state() TypeError: object NoneType can't be used in 'await' expression

@alandtse
Copy link
Owner

Oops. Ok, can you please delete the await from line 199 in the media_player. Should look like:

Before:

                    await self.async_schedule_update_ha_state()

After:

                    self.async_schedule_update_ha_state()

@danielmihalache1983
Copy link
Author

yea. this seems to work now.
while monitoring the logs I also noticed this
2019-08-27 21:31:51 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved Traceback (most recent call last): File "/usr/local/lib/python3.7/site-packages/alexapy/alexawebsocket.py", line 135, in process_messages await self.on_message(cast(bytes, msg.data)) File "/usr/local/lib/python3.7/site-packages/alexapy/alexawebsocket.py", line 217, in on_message await self.msg_callback(message_obj) File "/config/custom_components/alexa_media/__init__.py", line 590, in ws_handler serial) File "/config/custom_components/alexa_media/__init__.py", line 465, in update_bluetooth_state for b_state in bluetooth['bluetoothStates']: KeyError: 'bluetoothStates'

@alandtse
Copy link
Owner

Ok, this is a different bug and I'll open up a new issue to address. I'll have a new question for you in the new issue. Can you please go answer it there?

@danielmihalache1983
Copy link
Author

Sure, will do that once I get back home. Thanks for fixing the issue.

alandtse added a commit that referenced this issue Aug 30, 2019
 fix(media_player): set await for async source functions
@alandtse alandtse mentioned this issue Aug 30, 2019
@skynet01
Copy link

Nice, I finally figured out why my lovelace hangs :) So awesome you were able to fix it so fast, thanks alandtse!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants