mirror of
https://github.com/home-assistant/core.git
synced 2026-08-03 20:24:55 +02:00
Remove met device cleanup (#177966)
This commit is contained in:
@@ -4,14 +4,8 @@ import logging
|
||||
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
|
||||
from .const import (
|
||||
CONF_TRACK_HOME,
|
||||
DEFAULT_HOME_LATITUDE,
|
||||
DEFAULT_HOME_LONGITUDE,
|
||||
DOMAIN,
|
||||
)
|
||||
from .const import CONF_TRACK_HOME, DEFAULT_HOME_LATITUDE, DEFAULT_HOME_LONGITUDE
|
||||
from .coordinator import MetDataUpdateCoordinator, MetWeatherConfigEntry
|
||||
|
||||
PLATFORMS = [Platform.WEATHER]
|
||||
@@ -49,8 +43,6 @@ async def async_setup_entry(
|
||||
|
||||
await hass.config_entries.async_forward_entry_setups(config_entry, PLATFORMS)
|
||||
|
||||
await cleanup_old_device(hass)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
@@ -59,12 +51,3 @@ async def async_unload_entry(
|
||||
) -> bool:
|
||||
"""Unload a config entry."""
|
||||
return await hass.config_entries.async_unload_platforms(config_entry, PLATFORMS)
|
||||
|
||||
|
||||
async def cleanup_old_device(hass: HomeAssistant) -> None:
|
||||
"""Cleanup device without proper device identifier."""
|
||||
device_reg = dr.async_get(hass)
|
||||
device = device_reg.async_get_device(identifiers={(DOMAIN,)}) # type: ignore[arg-type]
|
||||
if device:
|
||||
_LOGGER.debug("Removing improper device %s", device.name)
|
||||
device_reg.async_remove_device(device.id)
|
||||
|
||||
@@ -10,7 +10,6 @@ from homeassistant.components.met.const import (
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.core_config import async_process_ha_core_config
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
|
||||
from . import init_integration
|
||||
|
||||
@@ -50,30 +49,3 @@ async def test_fail_default_home_entry(
|
||||
"Skip setting up met.no integration; No Home location has been set"
|
||||
in caplog.text
|
||||
)
|
||||
|
||||
|
||||
async def test_removing_incorrect_devices(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
mock_weather,
|
||||
) -> None:
|
||||
"""Test we remove incorrect devices."""
|
||||
entry = await init_integration(hass)
|
||||
|
||||
device_registry.async_get_or_create(
|
||||
config_entry_id=entry.entry_id,
|
||||
name="Forecast_legacy",
|
||||
entry_type=dr.DeviceEntryType.SERVICE,
|
||||
identifiers={(DOMAIN,)},
|
||||
manufacturer="Met.no",
|
||||
model="Forecast",
|
||||
configuration_url="https://www.met.no/en",
|
||||
)
|
||||
|
||||
assert await hass.config_entries.async_reload(entry.entry_id)
|
||||
assert len(hass.config_entries.async_entries(DOMAIN)) == 1
|
||||
|
||||
assert not device_registry.async_get_device(identifiers={(DOMAIN,)})
|
||||
assert device_registry.async_get_device(identifiers={(DOMAIN, entry.entry_id)})
|
||||
assert "Removing improper device Forecast_legacy" in caplog.text
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"""Test Met weather entity."""
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components.met import DOMAIN
|
||||
from homeassistant.components.met.const import DOMAIN
|
||||
from homeassistant.components.weather import (
|
||||
ATTR_CONDITION_CLOUDY,
|
||||
ATTR_WEATHER_DEW_POINT,
|
||||
|
||||
Reference in New Issue
Block a user