Conversation
Co-authored-by: gensyn <36128035+gensyn@users.noreply.github.com>
…acts Co-authored-by: gensyn <36128035+gensyn@users.noreply.github.com>
|
@copilot This ia great but does not fix most of the errors users are having. Most crashes seem to stem from GTK related issues. Have a deeper look for likely causes, please. |
…age and list builders Co-authored-by: gensyn <36128035+gensyn@users.noreply.github.com>
Investigated the codebase more deeply. The GTK crashes stem from three causes: 1. Thread safety (primary cause of GTK crashes) — Commit 2. Null pointer in 3. |
|
@copilot The current version crashes for me with the following error: |
…hanged Co-authored-by: gensyn <36128035+gensyn@users.noreply.github.com>
... The Fixed in |
Fixes multiple causes of StreamController crashes when using the Home Assistant Plugin.
Changes
Nonevalue sorting fixes_load_domainsand_load_entitiesinBaseCorewould crash withTypeError: '<' not supported between instances of 'NoneType' and 'str'when the backend returnedNoneentries in the domains list, or when no entity was configured (causingNoneto be appended before sorting)._load_domains: FilterNonevalues from the domains list before sorting._load_entities: Guard the append withentity is not None, and filterNonevalues from the entities list before sorting._load_actions(perform_action.py): Guard the append withaction is not Noneand filterNonevalues, consistent with the above fixes._load_attributes(text_action.py): Guard the append withattribute is not None, consistent with the above fixes.GTK thread safety
The WebSocket runs in a background daemon thread. Its callbacks (
_on_connect,_on_disconnect,_on_event_message) directly invoked action methods that manipulate GTK widgets (e.g.populate(),set_sensitive(),set_media()), violating GTK's requirement that all UI operations run on the main thread. This was the primary cause of non-deterministic GTK crashes.home_assistant_backend.py: Addedfrom gi.repository import GLiband replaced all direct callback invocations from the WebSocket background thread withGLib.idle_add().Null guard in
_on_event_messageWhen HA sends an event for an entity that has been removed (or during a race condition on reload),
entity_settingscould beNone, causing anAttributeError. Additionally,self._entities[domain]could raiseKeyErrorif the domain was no longer present.home_assistant_backend.py: Changedself._entities[domain]subscript access to.get(domain, {})and added an earlyreturnwhenentity_settings is None.Fix
gtk_list_tile_splitfatal GTK4 assertion_load_domains()and_load_entities()unconditionally calledpopulate()onComboRow(backed byGtkDropDown) on every invocation. Sinceon_ready()is registered as a backend reconnect callback and fired viaGLib.idle_add()for every action on every reconnect,populate()could be called while the user had a dropdown popup open. GTK4'sGtkListItemManagerfires a fatal assertion (gtk_list_tile_split: assertion failed: (n_items < tile->n_items)) and aborts the process when its backing model is modified while the dropdown is visible.base_core.py: Added_get_current_domains()and_get_current_entities()helpers (following the same pattern asShowText._get_current_attributes()), and equality guards in_load_domains()and_load_entities()to skippopulate()when the list has not changed.Other
.gitignore: Added__pycache__/and*.pycentries.Tests
test_load_domains_with_none_in_domainsandtest_load_entities_with_none_entityfor theNone-in-list sorting fix._on_connect,_on_disconnect, and_on_event_messageto patchGLib.idle_addwithside_effect=lambda f, *args: f(*args)so existing callback assertions remain valid.test_on_event_message_unknown_entity_no_new_stateandtest_on_event_message_unknown_entity_with_new_statefor the nullentity_settingsguard.test_load_actions_none_actionandtest_load_attributes_none_attributefor the newNoneguards.test_load_domains_*andtest_load_entities_*to configureget_item_amounton the mock so the equality guard is exercised; addedtest_load_domains_no_update_neededandtest_load_entities_no_update_neededto verifypopulate()is not called when the list is already correct.Original prompt
This section details on the original issue you should resolve
<issue_title>Stream Controller crashing with Home Assistant Plugin</issue_title>
<issue_description>Hi,
I just installed StreamController with your Home Assistant Plugin. Some times it works, but after 3-5 interactions StreamController crashes. It happens in different situations. As I thought it is a StreamController issue I contacted them, who told me it may be a problem with his plugin. And there is a problem with a TypeError.
Would you like to have a look at it?
Here is part of the SC.log: