mirror of
https://github.com/home-assistant/core.git
synced 2025-07-20 19:57:07 +00:00
Clear statistics on entry removal in ista EcoTrend integration (#143433)
This commit is contained in:
parent
c654936a91
commit
ccd1a08aca
@ -6,6 +6,7 @@ import logging
|
||||
|
||||
from pyecotrend_ista import PyEcotrendIsta
|
||||
|
||||
from homeassistant.components.recorder import get_instance
|
||||
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
@ -37,3 +38,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: IstaConfigEntry) -> bool
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: IstaConfigEntry) -> bool:
|
||||
"""Unload a config entry."""
|
||||
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
|
||||
|
||||
async def async_remove_entry(hass: HomeAssistant, entry: IstaConfigEntry) -> None:
|
||||
"""Handle removal of an entry."""
|
||||
statistic_ids = [f"{DOMAIN}:{name}" for name in entry.options.values()]
|
||||
get_instance(hass).async_clear_statistics(statistic_ids)
|
||||
|
@ -84,3 +84,61 @@ async def test_statistics_import(
|
||||
assert stats[statistic_id] == snapshot(name=f"{statistic_id}_3months")
|
||||
|
||||
assert len(stats[statistic_id]) == 3
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("recorder_mock", "mock_ista")
|
||||
async def test_remove(
|
||||
hass: HomeAssistant,
|
||||
ista_config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test remove config entry and clear statistics."""
|
||||
ista_config_entry.add_to_hass(hass)
|
||||
await hass.config_entries.async_setup(ista_config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert ista_config_entry.state is ConfigEntryState.LOADED
|
||||
await async_wait_recording_done(hass)
|
||||
|
||||
assert await hass.async_add_executor_job(
|
||||
statistics_during_period,
|
||||
hass,
|
||||
datetime.datetime.fromtimestamp(0, tz=datetime.UTC),
|
||||
None,
|
||||
{"ista_ecotrend:bahnhofsstr_1a_heating"},
|
||||
"month",
|
||||
None,
|
||||
{"state", "sum"},
|
||||
)
|
||||
|
||||
assert await hass.config_entries.async_unload(ista_config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert ista_config_entry.state is ConfigEntryState.NOT_LOADED
|
||||
await async_wait_recording_done(hass)
|
||||
|
||||
assert await hass.async_add_executor_job(
|
||||
statistics_during_period,
|
||||
hass,
|
||||
datetime.datetime.fromtimestamp(0, tz=datetime.UTC),
|
||||
None,
|
||||
{"ista_ecotrend:bahnhofsstr_1a_heating"},
|
||||
"month",
|
||||
None,
|
||||
{"state", "sum"},
|
||||
)
|
||||
|
||||
assert await hass.config_entries.async_remove(ista_config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
await async_wait_recording_done(hass)
|
||||
|
||||
assert not await hass.async_add_executor_job(
|
||||
statistics_during_period,
|
||||
hass,
|
||||
datetime.datetime.fromtimestamp(0, tz=datetime.UTC),
|
||||
None,
|
||||
{"ista_ecotrend:bahnhofsstr_1a_heating"},
|
||||
"month",
|
||||
None,
|
||||
{"state", "sum"},
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user