-
-
Notifications
You must be signed in to change notification settings - Fork 45
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 utility meter helpers (#558)
- Loading branch information
Showing
7 changed files
with
125 additions
and
1 deletion.
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.""" |
1 change: 1 addition & 0 deletions
1
custom_components/spook/ectoplasms/utility_meter/repairs/__init__.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 @@ | ||
"""Spook - Not your homie.""" |
71 changes: 71 additions & 0 deletions
71
custom_components/spook/ectoplasms/utility_meter/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 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 utility meters.""" | ||
|
||
domain = "utility_meter" | ||
repair = "utility_meter_unknown_source" | ||
inspect_events = { | ||
EVENT_COMPONENT_LOADED, | ||
er.EVENT_ENTITY_REGISTRY_UPDATED, | ||
} | ||
inspect_on_reload = "utility_meter" | ||
|
||
_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 sensor domain | ||
if platform.domain != sensor.DOMAIN: | ||
continue | ||
|
||
for entity in platform.entities.values(): | ||
possible_issue_ids.add(entity.entity_id) | ||
# pylint: disable-next=protected-access | ||
source = entity._sensor_source_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: Utility meter | ||
subtitle: Help you to get scared of your utility bills before they arrive. | ||
description: Spook enhances the Home Assistant utility meter integration by report issues in the repairs dashboard. | ||
date: 2024-01-12T20:41:55+01:00 | ||
--- | ||
|
||
```{image} https://brands.home-assistant.io/utility_meter/logo.png | ||
:alt: The Home Assistant utility meter logo | ||
:width: 250px | ||
:align: center | ||
``` | ||
|
||
<br><br> | ||
|
||
The utility meter {term}`helper <helper>` integration can track the consumption of utilities, such as electricity, gas, or water. It does so by tracking the state of a source entity, such as a smart meter, and calculating the usage 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 utility meters 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 utility meter and the source entity that is missing. | ||
|
||
To resolve the raised issue, you can either remove the utility meter 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. |