diff --git a/homeassistant/components/ipma/manifest.json b/homeassistant/components/ipma/manifest.json index 4fea047e834..0d7df3fcf92 100644 --- a/homeassistant/components/ipma/manifest.json +++ b/homeassistant/components/ipma/manifest.json @@ -6,5 +6,5 @@ "documentation": "https://www.home-assistant.io/integrations/ipma", "iot_class": "cloud_polling", "loggers": ["geopy", "pyipma"], - "requirements": ["pyipma==3.0.6"] + "requirements": ["pyipma==3.0.7"] } diff --git a/homeassistant/components/ipma/sensor.py b/homeassistant/components/ipma/sensor.py index 7f5782f3f89..cb0620ceca0 100644 --- a/homeassistant/components/ipma/sensor.py +++ b/homeassistant/components/ipma/sensor.py @@ -8,6 +8,8 @@ import logging from pyipma.api import IPMA_API from pyipma.location import Location +from pyipma.rcm import RCM +from pyipma.uv import UV from homeassistant.components.sensor import SensorEntity, SensorEntityDescription from homeassistant.config_entries import ConfigEntry @@ -33,19 +35,32 @@ class IPMASensorEntityDescription(SensorEntityDescription, IPMARequiredKeysMixin """Describes IPMA sensor entity.""" -async def async_retrive_rcm(location: Location, api: IPMA_API) -> int | None: +async def async_retrieve_rcm(location: Location, api: IPMA_API) -> int | None: """Retrieve RCM.""" - fire_risk = await location.fire_risk(api) + fire_risk: RCM = await location.fire_risk(api) if fire_risk: return fire_risk.rcm return None +async def async_retrieve_uvi(location: Location, api: IPMA_API) -> int | None: + """Retrieve UV.""" + uv_risk: UV = await location.uv_risk(api) + if uv_risk: + return round(uv_risk.iUv) + return None + + SENSOR_TYPES: tuple[IPMASensorEntityDescription, ...] = ( IPMASensorEntityDescription( key="rcm", translation_key="fire_risk", - value_fn=async_retrive_rcm, + value_fn=async_retrieve_rcm, + ), + IPMASensorEntityDescription( + key="uvi", + translation_key="uv_index", + value_fn=async_retrieve_uvi, ), ) @@ -81,7 +96,7 @@ class IPMASensor(SensorEntity, IPMADevice): @Throttle(MIN_TIME_BETWEEN_UPDATES) async def async_update(self) -> None: - """Update Fire risk.""" + """Update sensors.""" async with asyncio.timeout(10): self._attr_native_value = await self.entity_description.value_fn( self._location, self._api diff --git a/homeassistant/components/ipma/strings.json b/homeassistant/components/ipma/strings.json index b9b672e77d9..ea5e5ff4759 100644 --- a/homeassistant/components/ipma/strings.json +++ b/homeassistant/components/ipma/strings.json @@ -28,6 +28,9 @@ "sensor": { "fire_risk": { "name": "Fire risk" + }, + "uv_index": { + "name": "UV index" } } } diff --git a/requirements_all.txt b/requirements_all.txt index dd549ea51d9..4bb5909b09c 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1764,7 +1764,7 @@ pyinsteon==1.5.1 pyintesishome==1.8.0 # homeassistant.components.ipma -pyipma==3.0.6 +pyipma==3.0.7 # homeassistant.components.ipp pyipp==0.14.4 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index dd81cfb85d6..c4829c59a61 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -1325,7 +1325,7 @@ pyicloud==1.0.0 pyinsteon==1.5.1 # homeassistant.components.ipma -pyipma==3.0.6 +pyipma==3.0.7 # homeassistant.components.ipp pyipp==0.14.4 diff --git a/tests/components/ipma/__init__.py b/tests/components/ipma/__init__.py index 827481c60de..02a61f0b201 100644 --- a/tests/components/ipma/__init__.py +++ b/tests/components/ipma/__init__.py @@ -27,6 +27,14 @@ class MockLocation: ) return RCM("some place", 3, (0, 0)) + async def uv_risk(self, api): + """Mock UV Index.""" + UV = namedtuple( + "UV", + ["idPeriodo", "intervaloHora", "data", "globalIdLocal", "iUv"], + ) + return UV(0, "0", datetime.now(), 0, 5.7) + async def observation(self, api): """Mock Observation.""" Observation = namedtuple( diff --git a/tests/components/ipma/test_sensor.py b/tests/components/ipma/test_sensor.py index cbbad9c590f..d5f6a3ab5bb 100644 --- a/tests/components/ipma/test_sensor.py +++ b/tests/components/ipma/test_sensor.py @@ -10,10 +10,7 @@ from tests.common import MockConfigEntry async def test_ipma_fire_risk_create_sensors(hass): """Test creation of fire risk sensors.""" - with patch( - "pyipma.location.Location.get", - return_value=MockLocation(), - ): + 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) @@ -22,3 +19,17 @@ async def test_ipma_fire_risk_create_sensors(hass): state = hass.states.get("sensor.hometown_fire_risk") assert state.state == "3" + + +async def test_ipma_uv_index_create_sensors(hass): + """Test creation of uv index 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_uv_index") + + assert state.state == "6"