-
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Detect unknown source used in trend helpers (#560)
- Loading branch information
Showing
7 changed files
with
124 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""Spook - Not your homie.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""Spook - Not your homie.""" |
71 changes: 71 additions & 0 deletions
71
custom_components/spook/ectoplasms/trend/repairs/unknown_source.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
"""Spook - Not your homie.""" | ||
from __future__ import annotations | ||
|
||
from homeassistant.components import binary_sensor | ||
from homeassistant.const import EVENT_COMPONENT_LOADED | ||
from homeassistant.helpers import entity_registry as er | ||
from homeassistant.helpers.entity_platform import DATA_ENTITY_PLATFORM, EntityPlatform | ||
|
||
from ....const import LOGGER | ||
from ....repairs import AbstractSpookRepair | ||
|
||
|
||
class SpookRepair(AbstractSpookRepair): | ||
"""Spook repair tries to find unknown source entites for trend sensors.""" | ||
|
||
domain = "trend" | ||
repair = "trend_unknown_source" | ||
inspect_events = { | ||
EVENT_COMPONENT_LOADED, | ||
er.EVENT_ENTITY_REGISTRY_UPDATED, | ||
} | ||
inspect_on_reload = "trend" | ||
|
||
_issues: set[str] = set() | ||
|
||
async def async_inspect(self) -> None: | ||
"""Trigger a inspection.""" | ||
LOGGER.debug("Spook is inspecting: %s", self.repair) | ||
|
||
platforms: list[EntityPlatform] | None | ||
if not (platforms := self.hass.data[DATA_ENTITY_PLATFORM].get(self.domain)): | ||
return # Nothing to do. | ||
|
||
entity_ids = { | ||
entity.entity_id for entity in self.entity_registry.entities.values() | ||
}.union(self.hass.states.async_entity_ids()) | ||
|
||
possible_issue_ids: set[str] = set() | ||
for platform in platforms: | ||
# We only care about the binary sensor domain | ||
if platform.domain != binary_sensor.DOMAIN: | ||
continue | ||
|
||
for entity in platform.entities.values(): | ||
possible_issue_ids.add(entity.entity_id) | ||
# pylint: disable-next=protected-access | ||
source = entity._entity_id # noqa: SLF001 | ||
if source not in entity_ids: | ||
self.async_create_issue( | ||
issue_id=entity.entity_id, | ||
translation_placeholders={ | ||
"entity_id": entity.entity_id, | ||
"helper": entity.name, | ||
"source": source, | ||
}, | ||
) | ||
self._issues.add(entity.entity_id) | ||
LOGGER.debug( | ||
"Spook found unknown source entity %s in %s " | ||
"and created an issue for it", | ||
source, | ||
entity.entity_id, | ||
) | ||
else: | ||
self.async_delete_issue(entity.entity_id) | ||
self._issues.add(entity.entity_id) | ||
|
||
# Remove issues that are no longer valid | ||
for issue_id in self._issues - possible_issue_ids: | ||
self.async_delete_issue(issue_id) | ||
self._issues.discard(issue_id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
--- | ||
subject: Enhanced integrations | ||
title: Trend | ||
subtitle: I don't follow trends, trends follow me. π | ||
description: Spook enhances the Home Assistant trend integration by report issues in the repairs dashboard. | ||
date: 2024-01-12T20:41:55+01:00 | ||
--- | ||
|
||
```{image} https://brands.home-assistant.io/trend/logo.png | ||
:alt: The Home Assistant trend logo | ||
:width: 250px | ||
:align: center | ||
``` | ||
|
||
<br><br> | ||
|
||
The trend {term}`helper <helper>` integration show the trend of a numeric value over time. It does so by tracking the state of a source entity, such as a sensor, and calculating the trend based on the difference between the current and previous state. | ||
|
||
## Devices & entities | ||
|
||
Spook does not provide any new devices or entities for this integration. | ||
|
||
## Services | ||
|
||
Spook does not provide service enhancements for this integration. | ||
|
||
## Repairs | ||
|
||
While Spook is floating around in your Home Assistant instance, it will raise repairs issues if it has found something that is not right. | ||
|
||
### Unknown source entity | ||
|
||
Spook inspects all trend sensors created to find source entities they meter that no longer exist. If Spook finds such a case, it will raise a repair issue, informing you about the problematic trend helper and the source entity that is missing. | ||
|
||
To resolve the raised issue, you can either remove the trend helper or restore the referenced source entity. Spook will automatically remove the repair issue once the issue is fixed. | ||
|
||
## Features requests, ideas, and support | ||
|
||
If you have an idea on how to further enhance this integration, for example, by adding a new service, entity, or repairs detection; feel free to [let us know in our discussion forums](https://github.com/frenck/spook/discussions). | ||
|
||
Are you stuck using these new features? Or maybe you've run into a bug? Please check the [](../support) page on where to go for help. |