mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Allow Fronius devices to be deleted (#106141)
This commit is contained in:
parent
235914c63a
commit
46d63ad7ba
@ -65,6 +65,13 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
return unload_ok
|
return unload_ok
|
||||||
|
|
||||||
|
|
||||||
|
async def async_remove_config_entry_device(
|
||||||
|
hass: HomeAssistant, config_entry: ConfigEntry, device_entry: dr.DeviceEntry
|
||||||
|
) -> bool:
|
||||||
|
"""Remove a config entry from a device."""
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
class FroniusSolarNet:
|
class FroniusSolarNet:
|
||||||
"""The FroniusSolarNet class routes received values to sensor entities."""
|
"""The FroniusSolarNet class routes received values to sensor entities."""
|
||||||
|
|
||||||
|
@ -125,3 +125,17 @@ async def enable_all_entities(hass, freezer, config_entry_id, time_till_next_upd
|
|||||||
freezer.tick(time_till_next_update)
|
freezer.tick(time_till_next_update)
|
||||||
async_fire_time_changed(hass)
|
async_fire_time_changed(hass)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
|
||||||
|
async def remove_device(ws_client, device_id, config_entry_id):
|
||||||
|
"""Remove config entry from a device."""
|
||||||
|
await ws_client.send_json(
|
||||||
|
{
|
||||||
|
"id": 5,
|
||||||
|
"type": "config/device_registry/remove_config_entry",
|
||||||
|
"config_entry_id": config_entry_id,
|
||||||
|
"device_id": device_id,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
response = await ws_client.receive_json()
|
||||||
|
return response["success"]
|
||||||
|
@ -7,13 +7,15 @@ from pyfronius import FroniusError
|
|||||||
from homeassistant.components.fronius.const import DOMAIN, SOLAR_NET_RESCAN_TIMER
|
from homeassistant.components.fronius.const import DOMAIN, SOLAR_NET_RESCAN_TIMER
|
||||||
from homeassistant.config_entries import ConfigEntryState
|
from homeassistant.config_entries import ConfigEntryState
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import device_registry as dr
|
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||||
|
from homeassistant.setup import async_setup_component
|
||||||
from homeassistant.util import dt as dt_util
|
from homeassistant.util import dt as dt_util
|
||||||
|
|
||||||
from . import mock_responses, setup_fronius_integration
|
from . import mock_responses, remove_device, setup_fronius_integration
|
||||||
|
|
||||||
from tests.common import async_fire_time_changed
|
from tests.common import async_fire_time_changed
|
||||||
from tests.test_util.aiohttp import AiohttpClientMocker
|
from tests.test_util.aiohttp import AiohttpClientMocker
|
||||||
|
from tests.typing import WebSocketGenerator
|
||||||
|
|
||||||
|
|
||||||
async def test_unload_config_entry(
|
async def test_unload_config_entry(
|
||||||
@ -138,3 +140,29 @@ async def test_inverter_rescan_interruption(
|
|||||||
len(dr.async_entries_for_config_entry(device_registry, config_entry.entry_id))
|
len(dr.async_entries_for_config_entry(device_registry, config_entry.entry_id))
|
||||||
== 2
|
== 2
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
async def test_device_remove_devices(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
aioclient_mock: AiohttpClientMocker,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
|
hass_ws_client: WebSocketGenerator,
|
||||||
|
) -> None:
|
||||||
|
"""Test we can remove a device."""
|
||||||
|
assert await async_setup_component(hass, "config", {})
|
||||||
|
|
||||||
|
mock_responses(aioclient_mock, fixture_set="gen24_storage")
|
||||||
|
config_entry = await setup_fronius_integration(
|
||||||
|
hass, is_logger=False, unique_id="12345678"
|
||||||
|
)
|
||||||
|
|
||||||
|
inverter_1 = device_registry.async_get_device(identifiers={(DOMAIN, "12345678")})
|
||||||
|
assert (
|
||||||
|
await remove_device(
|
||||||
|
await hass_ws_client(hass), inverter_1.id, config_entry.entry_id
|
||||||
|
)
|
||||||
|
is True
|
||||||
|
)
|
||||||
|
|
||||||
|
assert not device_registry.async_get_device(identifiers={(DOMAIN, "12345678")})
|
||||||
|
@ -370,6 +370,7 @@ async def test_gen24(
|
|||||||
async def test_gen24_storage(
|
async def test_gen24_storage(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
aioclient_mock: AiohttpClientMocker,
|
aioclient_mock: AiohttpClientMocker,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
freezer: FrozenDateTimeFactory,
|
freezer: FrozenDateTimeFactory,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test Fronius Gen24 inverter with BYD battery and Ohmpilot entities."""
|
"""Test Fronius Gen24 inverter with BYD battery and Ohmpilot entities."""
|
||||||
@ -465,8 +466,6 @@ async def test_gen24_storage(
|
|||||||
assert_state("sensor.byd_battery_box_premium_hv_dc_voltage", 0.0)
|
assert_state("sensor.byd_battery_box_premium_hv_dc_voltage", 0.0)
|
||||||
|
|
||||||
# Devices
|
# Devices
|
||||||
device_registry = dr.async_get(hass)
|
|
||||||
|
|
||||||
solar_net = device_registry.async_get_device(
|
solar_net = device_registry.async_get_device(
|
||||||
identifiers={(DOMAIN, "solar_net_12345678")}
|
identifiers={(DOMAIN, "solar_net_12345678")}
|
||||||
)
|
)
|
||||||
@ -501,6 +500,7 @@ async def test_gen24_storage(
|
|||||||
async def test_primo_s0(
|
async def test_primo_s0(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
aioclient_mock: AiohttpClientMocker,
|
aioclient_mock: AiohttpClientMocker,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
freezer: FrozenDateTimeFactory,
|
freezer: FrozenDateTimeFactory,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test Fronius Primo dual inverter with S0 meter entities."""
|
"""Test Fronius Primo dual inverter with S0 meter entities."""
|
||||||
@ -573,8 +573,6 @@ async def test_primo_s0(
|
|||||||
assert_state("sensor.solarnet_energy_year", 11128933.25)
|
assert_state("sensor.solarnet_energy_year", 11128933.25)
|
||||||
|
|
||||||
# Devices
|
# Devices
|
||||||
device_registry = dr.async_get(hass)
|
|
||||||
|
|
||||||
solar_net = device_registry.async_get_device(
|
solar_net = device_registry.async_get_device(
|
||||||
identifiers={(DOMAIN, "solar_net_123.4567890")}
|
identifiers={(DOMAIN, "solar_net_123.4567890")}
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user