Comwatt Integration for HomeAssistant
Find a file
Mateo Greil ba727d9f05
All checks were successful
Validate / validate-hacs (push) Has been skipped
Validate / validate-hassfest (push) Has been skipped
Validate / lint-ruff (push) Successful in 7s
Validate / test-pytest (push) Successful in 1m45s
Validate / type-check-mypy (push) Successful in 1m48s
🗑️ Remove stale devices when they disappear from Comwatt
## Summary
Closes [MateoGreil/homeassistant-comwatt#22](https://github.com/MateoGreil/homeassistant-comwatt/issues/22).

When a device is deleted on the Comwatt side, its entities and the device itself currently stay in HA's registries forever. This PR adds a prune pass that runs after `async_config_entry_first_refresh` succeeds: walk the entity registry and device registry for this config entry and drop anything whose unique_id / identifier is no longer present in the fresh topology snapshot.

The prune only runs at setup (HA startup and integration reload), so a transient API hiccup during normal polling can never accidentally remove a real device — the first-refresh has to succeed, which means the topology we compare against is reliable.

Device removal uses `async_update_device(remove_config_entry_id=...)` so HA removes the device only if no other integration still references it.

## Test plan
- [x] New `test_setup_prunes_stale_entities_and_devices` in `test_init.py`: seeds a stale device + entity, runs setup with an API response that doesn't mention them, asserts they've been removed.
- [x] `pytest tests/` — 25 passed.
- [ ] Hands-on: on your HA, add a device in Comwatt app, reload the integration, confirm the new entities appear. Then remove that device from the Comwatt app, reload the integration, confirm the entity and device disappear from Settings → Devices & services → Comwatt.

Reviewed-on: #17
2026-04-25 17:36:10 +02:00
.github 🔧 Make ruff CI job portable across Forgejo and GitHub 2026-04-24 14:11:05 +00:00
custom_components/comwatt 🗑️ Remove stale devices when they disappear from Comwatt 2026-04-25 17:36:10 +02:00
tests 🗑️ Remove stale devices when they disappear from Comwatt 2026-04-25 17:36:10 +02:00
.gitignore Initial commit 2023-07-08 17:25:26 +02:00
hacs.json 🚨 Add hacs.json 2023-11-06 11:26:09 +01:00
info.md 📝 Add info.md 2024-03-01 16:45:52 +01:00
mypy.ini 🔧 Add mypy type-check CI job 2026-04-24 13:10:22 +00:00
pyproject.toml 🐛 Fix NameError in AutoProductionRate sensor 2026-04-24 13:43:19 +00:00
pytest.ini Add pytest infrastructure 2026-04-24 12:38:04 +00:00
README-fr.md 📝 Link to comwatt gen 3 integration (#48) 2026-01-23 16:57:22 +01:00
README.md 📝 Link to comwatt gen 3 integration (#48) 2026-01-23 16:57:22 +01:00
requirements-test.txt Add pytest infrastructure 2026-04-24 12:38:04 +00:00

GitHub Release GitHub Activity License hacs BuyMeCoffee

Comwatt Logo HomeAssistant Logo

Comwatt Integration for Home Assistant

Control your Comwatt energy monitoring system via the Comwatt API with Home Assistant. This integration work only with Comwatt Gen 4 (energy.comwatt.com). If you use go.comwatt.com, you need to use the ComwattIndepbox integration

Lire en Français

Disclaimer

This Comwatt Integration for Home Assistant is not affiliated with, endorsed by, or in any way officially connected to Comwatt or its parent company. The integration is provided as-is and is not guaranteed to be suitable for any particular purpose. The use of this integration is at your own risk, and the author(s) of this integration will not be liable for any damages arising from the use or misuse of this integration.

Installation

  1. Install this integration using HACS by adding this repository or manually copy the files to your Home Assistant installation.
  2. Restart Home Assistant to load the integration.

Configuration

After installation, search and add component Comwatt in Home Assistant integrations page.

Or click Configuration

Usage

Once the integration is set up and configured, you will have access to sensors representing energy consumption and power consumption from your Comwatt devices. These entities can be added to your Home Assistant dashboard for monitoring and automation purposes.

Features

This integration can handle :

  • Power consumption of device
  • Energy consumption of device
  • Power consumption of network in/out
  • Energy consumption of network in/out
  • Switch capacity of device

Contributions

Contributions and feedback are welcome! If you encounter any issues, have suggestions for improvement, or would like to contribute new features, please open an issue or submit a pull request on the GitHub repository.

If you find this integration useful, consider supporting the development by adding a star !