Skip to content

Commit e51c606

Browse files
committed
fix: remove orphaned "Balance" entity left over from the 0.3.0 sensor split
0.3.0 replaced the single "Balance" sensor with separate "You Owe"/"You Are Owed" sensors, but Home Assistant doesn't automatically remove entities an integration stops creating - anyone who upgraded was left with a permanently-unavailable "Balance" entity in their entity registry. async_setup_entry now removes it if present. Also updated images/dash.png to show the current two-sensor dashboard.
1 parent 23b7de7 commit e51c606

3 files changed

Lines changed: 24 additions & 2 deletions

File tree

custom_components/splitwise/__init__.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88
from homeassistant.config_entries import ConfigEntry
99
from homeassistant.const import CONF_PLATFORM, Platform
1010
from homeassistant.core import HomeAssistant
11-
from homeassistant.helpers import config_entry_oauth2_flow, issue_registry as ir
11+
from homeassistant.helpers import (
12+
config_entry_oauth2_flow,
13+
entity_registry as er,
14+
issue_registry as ir,
15+
)
1216
from homeassistant.helpers.typing import ConfigType
1317
from splitwise import Splitwise
1418

@@ -42,6 +46,8 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
4246

4347
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
4448
"""Set up Splitwise from a config entry."""
49+
_async_remove_stale_entities(hass, entry)
50+
4551
implementation = (
4652
await config_entry_oauth2_flow.async_get_config_entry_implementation(
4753
hass, entry
@@ -64,6 +70,22 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
6470
return True
6571

6672

73+
def _async_remove_stale_entities(hass: HomeAssistant, entry: ConfigEntry) -> None:
74+
"""Remove entities from unique_ids no longer created by this integration.
75+
76+
0.3.0 replaced the single "Balance" sensor (unique_id "<entry_id>_balance")
77+
with separate "You Owe"/"You Are Owed" sensors. Home Assistant doesn't
78+
remove entities an integration stops creating on its own, so anyone
79+
upgrading would otherwise be left with a permanently-unavailable orphan.
80+
"""
81+
ent_reg = er.async_get(hass)
82+
stale_unique_id = f"{entry.entry_id}_balance"
83+
if entity_id := ent_reg.async_get_entity_id(
84+
Platform.SENSOR, DOMAIN, stale_unique_id
85+
):
86+
ent_reg.async_remove(entity_id)
87+
88+
6789
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
6890
"""Unload a Splitwise config entry."""
6991
unloaded = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)

custom_components/splitwise/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88
"iot_class": "cloud_polling",
99
"issue_tracker": "https://github.com/sriramsv/custom_component_splitwise/issues",
1010
"requirements": ["splitwise==3.0.0"],
11-
"version": "0.3.2"
11+
"version": "0.3.3"
1212
}

images/dash.png

7.57 KB
Loading

0 commit comments

Comments
 (0)