Remove hourly weather entity from met_eireann (#112449)
parent
ada781025b
commit
3ba1b82723
|
@ -53,17 +53,15 @@ async def async_setup_entry(
|
|||
coordinator = hass.data[DOMAIN][config_entry.entry_id]
|
||||
entity_registry = er.async_get(hass)
|
||||
|
||||
entities = [MetEireannWeather(coordinator, config_entry.data, False)]
|
||||
|
||||
# Add hourly entity to legacy config entries
|
||||
if entity_registry.async_get_entity_id(
|
||||
# Remove hourly entity from legacy config entries
|
||||
if entity_id := entity_registry.async_get_entity_id(
|
||||
WEATHER_DOMAIN,
|
||||
DOMAIN,
|
||||
_calculate_unique_id(config_entry.data, True),
|
||||
):
|
||||
entities.append(MetEireannWeather(coordinator, config_entry.data, True))
|
||||
entity_registry.async_remove(entity_id)
|
||||
|
||||
async_add_entities(entities)
|
||||
async_add_entities([MetEireannWeather(coordinator, config_entry.data)])
|
||||
|
||||
|
||||
def _calculate_unique_id(config: MappingProxyType[str, Any], hourly: bool) -> str:
|
||||
|
@ -93,19 +91,15 @@ class MetEireannWeather(
|
|||
self,
|
||||
coordinator: DataUpdateCoordinator[MetEireannWeatherData],
|
||||
config: MappingProxyType[str, Any],
|
||||
hourly: bool,
|
||||
) -> None:
|
||||
"""Initialise the platform with a data instance and site."""
|
||||
super().__init__(coordinator)
|
||||
self._attr_unique_id = _calculate_unique_id(config, hourly)
|
||||
self._attr_unique_id = _calculate_unique_id(config, False)
|
||||
self._config = config
|
||||
self._hourly = hourly
|
||||
name_appendix = " Hourly" if hourly else ""
|
||||
if (name := self._config.get(CONF_NAME)) is not None:
|
||||
self._attr_name = f"{name}{name_appendix}"
|
||||
self._attr_name = name
|
||||
else:
|
||||
self._attr_name = f"{DEFAULT_NAME}{name_appendix}"
|
||||
self._attr_entity_registry_enabled_default = not hourly
|
||||
self._attr_name = DEFAULT_NAME
|
||||
self._attr_device_info = DeviceInfo(
|
||||
name="Forecast",
|
||||
entry_type=DeviceEntryType.SERVICE,
|
||||
|
@ -182,7 +176,7 @@ class MetEireannWeather(
|
|||
@property
|
||||
def forecast(self) -> list[Forecast]:
|
||||
"""Return the forecast array."""
|
||||
return self._forecast(self._hourly)
|
||||
return self._forecast(False)
|
||||
|
||||
@callback
|
||||
def _async_forecast_daily(self) -> list[Forecast]:
|
||||
|
|
|
@ -45,22 +45,6 @@ async def test_new_config_entry(
|
|||
assert len(er.async_entries_for_config_entry(entity_registry, entry.entry_id)) == 1
|
||||
|
||||
|
||||
async def test_legacy_config_entry(
|
||||
hass: HomeAssistant, entity_registry: er.EntityRegistry, mock_weather
|
||||
) -> None:
|
||||
"""Test the expected entities are created."""
|
||||
entity_registry.async_get_or_create(
|
||||
WEATHER_DOMAIN,
|
||||
DOMAIN,
|
||||
"10-20-hourly",
|
||||
)
|
||||
await setup_config_entry(hass)
|
||||
assert len(hass.states.async_entity_ids("weather")) == 2
|
||||
|
||||
entry = hass.config_entries.async_entries()[0]
|
||||
assert len(er.async_entries_for_config_entry(entity_registry, entry.entry_id)) == 2
|
||||
|
||||
|
||||
async def test_weather(hass: HomeAssistant, mock_weather) -> None:
|
||||
"""Test weather entity."""
|
||||
await setup_config_entry(hass)
|
||||
|
|
Loading…
Reference in New Issue