Add search integration#30511
Conversation
|
I've added support for scenes and config entries. When we find a config entry, scene, automation or script (the outputs!), we will no longer further resolve it into subtypes. Because if I query for a device, I don't want to return all devices that share a scene or config entry with the device that I am querying for. It's still possible to pick any of those as an entry point, in which case they will be resolved. So these types are search type only. Support for script/automation should move to a new PR to no longer further complicate this. |
|
This is ready for approval/merging. |
|
The result is not a graph, it only contains all vertices, but missing the edges. We can extend the self.results = defaultdict(set) #vertices
self.edges = defaultdict(set)
# in Searcher class
def search(self, item_type, item_id):
self.results[item_type].add(item_id)
self._to_resolve.add((item_type, item_id))
while self._to_resolve:
search_type, search_id = self._to_resolve.pop()
await getattr(self, f"_resolve_{search_type}")(search_id)
return (self.results, self.edges)
# for example device
def _resolve_device(self, device_id) -> None:
device_entry = self._device_reg.async_get(device_id)
if device_entry is not None:
if device_entry.area_id:
self._add_or_resolve("area", device_entry.area_id)
# add edge
self.edges[("device", device_id)].add(("area", device_entry.area_id))
for config_entry_id in device_entry.config_entries:
self._add_or_resolve("config_entry", config_entry_id)
# add edge
self.edges[("device", device_id)].add(("config_entry", config_entry_id))
for entity_entry in entity_registry.async_entries_for_device(
self._entity_reg, device_id
):
self._add_or_resolve("entity", entity_entry.entity_id)
# add edge
self.edges[("device", device_id)].add(("entity", entity_entry.entity_id)) |
| self.results["entity"] -= self.results["automation"] | ||
|
|
||
| # Remove entry into graph from search results. | ||
| self.results[item_type].remove(item_id) |
There was a problem hiding this comment.
We can keep it in vertices if we return a graph
|
Well I wonder if we should return it as a graph? The user just wants to see related data. It doesn't care much about the relationship maybe? |
|
Nice! Will this gain other ways of searching in the future or is it just for finding related objects? (Wondering if there is a more descriptive name if its just for finding related objects). |
|
@Jc2k for now it's just related items. I'll update the websocket endpoint. |
Description:
Our data is interconnected, making it a graph. This means that we can also search it as a graph. This integration can give you related items based on any node in the graph. Currently implemented areas, devices, entities, config entry, scene. Leaving script/automation for a future PR.
Goal of this integration will be to provide related data in the UI. Example use cases:
Checklist:
tox. Your PR cannot be merged unless tests passIf the code does not interact with devices: