-
Notifications
You must be signed in to change notification settings - Fork 1
Replace prefix-only entity search with substring matching via set_search_match_mode #14
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
Changes from all commits
d89c577
974eb3b
74aca3a
96720a0
6f64b2a
30334a4
1cc4846
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -8,7 +8,7 @@ jobs: | |||||
|
|
||||||
| strategy: | ||||||
| matrix: | ||||||
| python-version: ["3.12", "3.13"] | ||||||
| python-version: ["3.13"] | ||||||
|
||||||
| python-version: ["3.13"] | |
| python-version: ["3.12", "3.13"] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,30 @@ | ||
| """The module for the Home Assistant action that is loaded in StreamController.""" | ||
|
|
||
| from typing import List | ||
|
|
||
| import gi | ||
| from GtkHelper.GenerativeUI.ComboRow import ComboRow | ||
| from HomeAssistantPlugin.actions import const | ||
| from src.backend.PluginManager.ActionCore import ActionCore | ||
|
|
||
| gi.require_version('Gtk', '4.0') | ||
| from gi.repository import Gtk | ||
|
|
||
|
|
||
| def set_substring_search(combo_row: ComboRow) -> None: | ||
| """Enable substring search mode on a ComboRow if supported by the installed libadwaita version.""" | ||
| try: | ||
| widget = combo_row.widget | ||
| if hasattr(widget, "set_search_match_mode"): | ||
| widget.set_search_match_mode(Gtk.StringFilterMatchMode.SUBSTRING) | ||
| except AttributeError: | ||
| pass | ||
|
Comment on lines
4
to
+19
|
||
|
|
||
|
|
||
| def requires_initialization(func): | ||
| def wrapper(self, *args, **kwargs): | ||
| if not getattr(self, 'initialized', False): | ||
| return None | ||
| return func(self, *args, **kwargs) | ||
|
|
||
| return wrapper | ||
|
|
||
|
|
||
|
|
@@ -26,7 +39,9 @@ def __init__(self, settings_implementation, track_entity: bool, *args, **kwargs) | |
| self.lm = self.plugin_base.locale_manager | ||
| self.has_configuration = True | ||
| self.track_entity = track_entity | ||
| self._create_ui_elements() | ||
| self.domain_combo = None | ||
| self.entity_combo = None | ||
| self.create_ui_elements() | ||
| self._create_event_assigner() | ||
|
|
||
| def on_ready(self) -> None: | ||
|
|
@@ -55,34 +70,36 @@ def on_remove(self) -> None: | |
| ) | ||
| self.refresh() | ||
|
|
||
| def get_config_rows(self) -> List: | ||
| def get_config_rows(self) -> list: | ||
| """Get the rows to be displayed in the UI.""" | ||
| raise NotImplementedError("Must be implemented by subclasses.") | ||
|
|
||
| def _create_ui_elements(self) -> None: | ||
| def create_ui_elements(self) -> None: | ||
| """Get all entity rows.""" | ||
| self.domain_combo: ComboRow = ComboRow( | ||
| self, const.SETTING_ENTITY_DOMAIN, const.EMPTY_STRING, [], | ||
| const.LABEL_ENTITY_DOMAIN, enable_search=True, | ||
| on_change=self._on_change_domain, can_reset=False, | ||
| on_change=self.on_change_domain, can_reset=False, | ||
| complex_var_name=True | ||
| ) | ||
| set_substring_search(self.domain_combo) | ||
|
|
||
| self.entity_combo: ComboRow = ComboRow( | ||
| self, const.SETTING_ENTITY_ENTITY, const.EMPTY_STRING, [], | ||
| const.LABEL_ENTITY_ENTITY, enable_search=True, | ||
| on_change=self._on_change_entity, can_reset=False, | ||
| on_change=self.on_change_entity, can_reset=False, | ||
| complex_var_name=True | ||
| ) | ||
| set_substring_search(self.entity_combo) | ||
|
|
||
| @requires_initialization | ||
| def _reload(self, *_): | ||
| """Reload the action.""" | ||
| self._set_enabled_disabled() | ||
| self.set_enabled_disabled() | ||
| self.refresh() | ||
|
|
||
| @requires_initialization | ||
| def _on_change_domain(self, _, domain, old_domain): | ||
| def on_change_domain(self, _, domain, old_domain): | ||
| """Execute when the domain is changed.""" | ||
| domain = str(domain) if domain is not None else None | ||
| old_domain = str(old_domain) if old_domain is not None else None | ||
|
|
@@ -97,10 +114,10 @@ def _on_change_domain(self, _, domain, old_domain): | |
| if domain: | ||
| self._load_entities() | ||
|
|
||
| self._set_enabled_disabled() | ||
| self.set_enabled_disabled() | ||
|
|
||
| @requires_initialization | ||
| def _on_change_entity(self, _, entity, old_entity): | ||
| def on_change_entity(self, _, entity, old_entity): | ||
| """Execute when the entity is changed.""" | ||
| entity = str(entity) if entity is not None else None | ||
| old_entity = str(old_entity) if old_entity is not None else None | ||
|
|
@@ -112,7 +129,7 @@ def _on_change_entity(self, _, entity, old_entity): | |
| self.plugin_base.backend.add_tracked_entity(entity, self.refresh) | ||
|
|
||
| self.refresh() | ||
| self._set_enabled_disabled() | ||
| self.set_enabled_disabled() | ||
|
|
||
| @requires_initialization | ||
| def refresh(self, state: dict = None) -> None: | ||
|
|
@@ -156,28 +173,28 @@ def _load_entities(self) -> None: | |
| if entities != self._get_current_entities(): | ||
| self.entity_combo.populate(entities, entity, trigger_callback=False) | ||
|
|
||
| def _get_current_domains(self) -> List[str]: | ||
| def _get_current_domains(self) -> list[str]: | ||
| """Get the domains currently displayed in the domain combo.""" | ||
| return [ | ||
| str(self.domain_combo.get_item_at(i)) | ||
| for i in range(self.domain_combo.get_item_amount()) | ||
| ] | ||
|
|
||
| def _get_current_entities(self) -> List[str]: | ||
| def _get_current_entities(self) -> list[str]: | ||
| """Get the entities currently displayed in the entity combo.""" | ||
| return [ | ||
| str(self.entity_combo.get_item_at(i)) | ||
| for i in range(self.entity_combo.get_item_amount()) | ||
| ] | ||
|
|
||
| @requires_initialization | ||
| def _set_enabled_disabled(self) -> None: | ||
| def set_enabled_disabled(self) -> None: | ||
| """Set the active/inactive state for all rows.""" | ||
| domain = self.settings.get_domain() | ||
| is_domain_set = bool(domain) | ||
| self.entity_combo.set_sensitive(is_domain_set) | ||
|
|
||
| def _get_domains(self) -> List[str]: | ||
| def _get_domains(self) -> list[str]: | ||
| """Get the domains available in Home Assistant.""" | ||
| raise NotImplementedError("Must be implemented by subclasses.") | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pylint workflow also removes Python 3.12 from the matrix. If 3.12 remains a supported runtime, consider keeping it here as well (or documenting the intentional support drop in the PR description).