diff --git a/homeassistant/components/accuweather/__init__.py b/homeassistant/components/accuweather/__init__.py index 4a015728d6f..c7943d15bd0 100644 --- a/homeassistant/components/accuweather/__init__.py +++ b/homeassistant/components/accuweather/__init__.py @@ -10,9 +10,11 @@ from aiohttp import ClientSession from aiohttp.client_exceptions import ClientConnectorError from async_timeout import timeout +from homeassistant.components.sensor import DOMAIN as SENSOR_PLATFORM from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_API_KEY, CONF_NAME, Platform from homeassistant.core import HomeAssistant +from homeassistant.helpers import entity_registry as er from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.device_registry import DeviceEntryType from homeassistant.helpers.entity import DeviceInfo @@ -48,6 +50,14 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) + # Remove ozone sensors from registry if they exist + ent_reg = er.async_get(hass) + for day in range(0, 5): + unique_id = f"{coordinator.location_key}-ozone-{day}" + if entity_id := ent_reg.async_get_entity_id(SENSOR_PLATFORM, DOMAIN, unique_id): + _LOGGER.debug("Removing ozone sensor entity %s", entity_id) + ent_reg.async_remove(entity_id) + return True diff --git a/homeassistant/components/accuweather/sensor.py b/homeassistant/components/accuweather/sensor.py index 4d58919947e..737150d4ee0 100644 --- a/homeassistant/components/accuweather/sensor.py +++ b/homeassistant/components/accuweather/sensor.py @@ -103,14 +103,6 @@ FORECAST_SENSOR_TYPES: tuple[AccuWeatherSensorDescription, ...] = ( value_fn=lambda data: cast(int, data[ATTR_VALUE]), attr_fn=lambda data: {ATTR_LEVEL: data[ATTR_CATEGORY]}, ), - AccuWeatherSensorDescription( - key="Ozone", - icon="mdi:vector-triangle", - name="Ozone", - entity_registry_enabled_default=False, - value_fn=lambda data: cast(int, data[ATTR_VALUE]), - attr_fn=lambda data: {ATTR_LEVEL: data[ATTR_CATEGORY]}, - ), AccuWeatherSensorDescription( key="Ragweed", icon="mdi:sprout", diff --git a/homeassistant/components/accuweather/weather.py b/homeassistant/components/accuweather/weather.py index 76a5d62a107..0ef729b9b69 100644 --- a/homeassistant/components/accuweather/weather.py +++ b/homeassistant/components/accuweather/weather.py @@ -109,16 +109,6 @@ class AccuWeatherEntity( """Return the visibility.""" return cast(float, self.coordinator.data["Visibility"][API_METRIC]["Value"]) - @property - def ozone(self) -> int | None: - """Return the ozone level.""" - # We only have ozone data for certain locations and only in the forecast data. - if self.coordinator.forecast and self.coordinator.data[ATTR_FORECAST][0].get( - "Ozone" - ): - return cast(int, self.coordinator.data[ATTR_FORECAST][0]["Ozone"]["Value"]) - return None - @property def forecast(self) -> list[Forecast] | None: """Return the forecast array.""" diff --git a/tests/components/accuweather/test_init.py b/tests/components/accuweather/test_init.py index 2b6f5132745..7123d5ef817 100644 --- a/tests/components/accuweather/test_init.py +++ b/tests/components/accuweather/test_init.py @@ -5,9 +5,11 @@ from unittest.mock import patch from accuweather import ApiError from homeassistant.components.accuweather.const import DOMAIN +from homeassistant.components.sensor import DOMAIN as SENSOR_PLATFORM from homeassistant.config_entries import ConfigEntryState from homeassistant.const import STATE_UNAVAILABLE from homeassistant.core import HomeAssistant +from homeassistant.helpers import entity_registry as er from homeassistant.util.dt import utcnow from . import init_integration @@ -113,3 +115,21 @@ async def test_update_interval_forecast(hass: HomeAssistant) -> None: assert mock_current.call_count == 1 assert mock_forecast.call_count == 1 + + +async def test_remove_ozone_sensors(hass: HomeAssistant) -> None: + """Test remove ozone sensors from registry.""" + registry = er.async_get(hass) + + registry.async_get_or_create( + SENSOR_PLATFORM, + DOMAIN, + "0123456-ozone-0", + suggested_object_id="home_ozone_0d", + disabled_by=None, + ) + + await init_integration(hass) + + entry = registry.async_get("sensor.home_ozone_0d") + assert entry is None diff --git a/tests/components/accuweather/test_sensor.py b/tests/components/accuweather/test_sensor.py index 29f698ca52a..323b3ae495d 100644 --- a/tests/components/accuweather/test_sensor.py +++ b/tests/components/accuweather/test_sensor.py @@ -305,13 +305,6 @@ async def test_sensor_enabled_without_forecast(hass: HomeAssistant) -> None: suggested_object_id="home_mold_pollen_0d", disabled_by=None, ) - registry.async_get_or_create( - SENSOR_DOMAIN, - DOMAIN, - "0123456-ozone-0", - suggested_object_id="home_ozone_0d", - disabled_by=None, - ) registry.async_get_or_create( SENSOR_DOMAIN, DOMAIN, @@ -529,18 +522,6 @@ async def test_sensor_enabled_without_forecast(hass: HomeAssistant) -> None: assert entry assert entry.unique_id == "0123456-mold-0" - state = hass.states.get("sensor.home_ozone_0d") - assert state - assert state.state == "32" - assert state.attributes.get(ATTR_ATTRIBUTION) == ATTRIBUTION - assert state.attributes.get("level") == "Good" - assert state.attributes.get(ATTR_ICON) == "mdi:vector-triangle" - assert state.attributes.get(ATTR_STATE_CLASS) is None - - entry = registry.async_get("sensor.home_ozone_0d") - assert entry - assert entry.unique_id == "0123456-ozone-0" - state = hass.states.get("sensor.home_ragweed_pollen_0d") assert state assert state.state == "0" diff --git a/tests/components/accuweather/test_weather.py b/tests/components/accuweather/test_weather.py index 66826f82d17..ab4faf73c81 100644 --- a/tests/components/accuweather/test_weather.py +++ b/tests/components/accuweather/test_weather.py @@ -14,7 +14,6 @@ from homeassistant.components.weather import ( ATTR_FORECAST_WIND_BEARING, ATTR_FORECAST_WIND_SPEED, ATTR_WEATHER_HUMIDITY, - ATTR_WEATHER_OZONE, ATTR_WEATHER_PRESSURE, ATTR_WEATHER_TEMPERATURE, ATTR_WEATHER_VISIBILITY, @@ -46,7 +45,6 @@ async def test_weather_without_forecast(hass: HomeAssistant) -> None: assert state.state == "sunny" assert not state.attributes.get(ATTR_FORECAST) assert state.attributes.get(ATTR_WEATHER_HUMIDITY) == 67 - assert not state.attributes.get(ATTR_WEATHER_OZONE) assert state.attributes.get(ATTR_WEATHER_PRESSURE) == 1012.0 assert state.attributes.get(ATTR_WEATHER_TEMPERATURE) == 22.6 assert state.attributes.get(ATTR_WEATHER_VISIBILITY) == 16.1 @@ -68,7 +66,6 @@ async def test_weather_with_forecast(hass: HomeAssistant) -> None: assert state assert state.state == "sunny" assert state.attributes.get(ATTR_WEATHER_HUMIDITY) == 67 - assert state.attributes.get(ATTR_WEATHER_OZONE) == 32 assert state.attributes.get(ATTR_WEATHER_PRESSURE) == 1012.0 assert state.attributes.get(ATTR_WEATHER_TEMPERATURE) == 22.6 assert state.attributes.get(ATTR_WEATHER_VISIBILITY) == 16.1