diff --git a/homeassistant/components/ipma/sensor.py b/homeassistant/components/ipma/sensor.py index 031ac68342dad5..911ad9f5d409d1 100644 --- a/homeassistant/components/ipma/sensor.py +++ b/homeassistant/components/ipma/sensor.py @@ -69,8 +69,8 @@ async def async_retrieve_warning(location: Location, api: IPMA_API) -> int | Non value_fn=async_retrieve_uvi, ), IPMASensorEntityDescription( - key="warning", - translation_key="warning", + key="alert", + translation_key="weather_alert", value_fn=async_retrieve_warning, value_extractor=lambda data: data.awarenessLevelID if data else "green", ), diff --git a/homeassistant/components/ipma/strings.json b/homeassistant/components/ipma/strings.json index b4e21765822368..ff9c23dd7ca5d6 100644 --- a/homeassistant/components/ipma/strings.json +++ b/homeassistant/components/ipma/strings.json @@ -32,8 +32,8 @@ "uv_index": { "name": "UV index" }, - "warning": { - "name": "Warning", + "weather_alert": { + "name": "Weather Alert", "state": { "red": "Red", "yellow": "Yellow", diff --git a/tests/components/ipma/__init__.py b/tests/components/ipma/__init__.py index ab5998c922f20f..031ff3c31d45b3 100644 --- a/tests/components/ipma/__init__.py +++ b/tests/components/ipma/__init__.py @@ -6,6 +6,7 @@ from pyipma.observation import Observation from pyipma.rcm import RCM from pyipma.uv import UV +from pyipma.warnings import Warning from homeassistant.const import CONF_LATITUDE, CONF_LONGITUDE, CONF_MODE, CONF_NAME @@ -20,6 +21,20 @@ class MockLocation: """Mock Location from pyipma.""" + async def warnings(self, api): + """Mock Warnings.""" + return [ + Warning( + text="Na costa Sul, ondas de sueste com 2 a 2,5 metros, em especial " + "no barlavento.", + awarenessTypeName="Agitação Marítima", + idAreaAviso="FAR", + startTime=datetime(2024, 12, 26, 12, 24), + awarenessLevelID="yellow", + endTime=datetime(2024, 12, 28, 6, 0), + ) + ] + async def fire_risk(self, api): """Mock Fire Risk.""" return RCM("some place", 3, (0, 0)) diff --git a/tests/components/ipma/test_sensor.py b/tests/components/ipma/test_sensor.py index adff8206add267..0c2d4df4c4e1eb 100644 --- a/tests/components/ipma/test_sensor.py +++ b/tests/components/ipma/test_sensor.py @@ -35,3 +35,17 @@ async def test_ipma_uv_index_create_sensors(hass: HomeAssistant) -> None: state = hass.states.get("sensor.hometown_uv_index") assert state.state == "6" + + +async def test_ipma_warning_create_sensors(hass: HomeAssistant) -> None: + """Test creation of warning sensors.""" + + with patch("pyipma.location.Location.get", return_value=MockLocation()): + entry = MockConfigEntry(domain="ipma", data=ENTRY_CONFIG) + entry.add_to_hass(hass) + await hass.config_entries.async_setup(entry.entry_id) + await hass.async_block_till_done() + + state = hass.states.get("sensor.hometown_weather_alert") + + assert state.state == "yellow"