Skip to content

Commit

Permalink
change name, add test
Browse files Browse the repository at this point in the history
  • Loading branch information
dgomes committed Dec 26, 2024
1 parent 7ead86c commit da357d0
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
4 changes: 2 additions & 2 deletions homeassistant/components/ipma/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
),
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/ipma/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
"uv_index": {
"name": "UV index"
},
"warning": {
"name": "Warning",
"weather_alert": {
"name": "Weather Alert",
"state": {
"red": "Red",
"yellow": "Yellow",
Expand Down
15 changes: 15 additions & 0 deletions tests/components/ipma/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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))
Expand Down
14 changes: 14 additions & 0 deletions tests/components/ipma/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit da357d0

Please sign in to comment.