diff --git a/tests/conftest.py b/tests/conftest.py index b9a0f15..14c565a 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,9 +1,88 @@ """Fixtures for tests""" + import pytest +from aioresponses import aioresponses + +from unittest.mock import patch + +import os pytest_plugins = "pytest_homeassistant_custom_component" +API_URL = "https://api.weather.gov" +COUNT_URL = "https://api.weather.gov/alerts/active/count" +ZONE_URL = "https://api.weather.gov/alerts/active?zone=AZZ540,AZC013" +POINT_URL = "https://api.weather.gov/alerts/active?point=123,-456" + +# This fixture enables loading custom integrations in all tests. +# Remove to enable selective use of this fixture @pytest.fixture(autouse=True) def auto_enable_custom_integrations(enable_custom_integrations): + """Enable custom integration tests.""" yield + + +# This fixture is used to prevent HomeAssistant from attempting to create and dismiss persistent +# notifications. These calls would fail without this fixture since the persistent_notification +# integration is never loaded during a test. +@pytest.fixture(name="skip_notifications", autouse=True) +def skip_notifications_fixture(): + """Skip notification calls.""" + with patch("homeassistant.components.persistent_notification.async_create"), patch( + "homeassistant.components.persistent_notification.async_dismiss" + ): + yield + + +@pytest.fixture +def aioclient_mock(): + """Fixture to mock aioclient calls.""" + with aioresponses() as mock_aiohttp: + mock_headers = {"content-type": "content-type: application/geo+json"} + mock_aiohttp.get( + API_URL, + status=200, + headers=mock_headers, + body={}, + ) + + yield mock_aiohttp + + +@pytest.fixture +def mock_aioclient(): + """Fixture to mock aioclient calls.""" + with aioresponses() as m: + yield m + + +def load_fixture(filename): + """Load a fixture.""" + path = os.path.join(os.path.dirname(__file__), "fixtures", filename) + with open(path, encoding="utf-8") as fptr: + return fptr.read() + + +@pytest.fixture(name="mock_api") +def mock_api(mock_aioclient): + """Load the charger data.""" + mock_aioclient.get( + ZONE_URL, + status=200, + body=load_fixture("api.json"), + repeat=True, + ) + mock_aioclient.get( + POINT_URL, + status=200, + body=load_fixture("api.json"), + repeat=True, + ) + mock_aioclient.get( + COUNT_URL, + status=200, + body=load_fixture("count_reply.json"), + repeat=True, + ) + yield mock_aioclient diff --git a/tests/fixtures/api.json b/tests/fixtures/api.json new file mode 100644 index 0000000..df5af7a --- /dev/null +++ b/tests/fixtures/api.json @@ -0,0 +1,158 @@ +{ + "@context": [ + "https://geojson.org/geojson-ld/geojson-context.jsonld", + { + "@version": "1.1", + "wx": "https://api.weather.gov/ontology#", + "@vocab": "https://api.weather.gov/ontology#" + } + ], + "type": "FeatureCollection", + "features": [ + { + "id": "https://api.weather.gov/alerts/urn:oid:2.49.0.1.840.0.505a7220d91b00eb1d75a3fb4f339f825496a522.004.1", + "type": "Feature", + "geometry": null, + "properties": { + "@id": "https://api.weather.gov/alerts/urn:oid:2.49.0.1.840.0.505a7220d91b00eb1d75a3fb4f339f825496a522.004.1", + "@type": "wx:Alert", + "id": "urn:oid:2.49.0.1.840.0.505a7220d91b00eb1d75a3fb4f339f825496a522.004.1", + "areaDesc": "Northwest Valley; Buckeye/Avondale; Deer Valley; Central Phoenix; North Phoenix/Glendale; Scottsdale/Paradise Valley; East Valley; South Mountain/Ahwatukee; Southeast Valley/Queen Creek", + "geocode": { + "SAME": [ + "004013" + ], + "UGC": [ + "AZZ537", + "AZZ540", + "AZZ542", + "AZZ543", + "AZZ544", + "AZZ546", + "AZZ548", + "AZZ550", + "AZZ551" + ] + }, + "affectedZones": [ + "https://api.weather.gov/zones/forecast/AZZ537", + "https://api.weather.gov/zones/forecast/AZZ540", + "https://api.weather.gov/zones/forecast/AZZ542", + "https://api.weather.gov/zones/forecast/AZZ543", + "https://api.weather.gov/zones/forecast/AZZ544", + "https://api.weather.gov/zones/forecast/AZZ546", + "https://api.weather.gov/zones/forecast/AZZ548", + "https://api.weather.gov/zones/forecast/AZZ550", + "https://api.weather.gov/zones/forecast/AZZ551" + ], + "references": [ + { + "@id": "https://api.weather.gov/alerts/urn:oid:2.49.0.1.840.0.2852349b8f25500975c692db29cb2f047ff20a7c.004.2", + "identifier": "urn:oid:2.49.0.1.840.0.2852349b8f25500975c692db29cb2f047ff20a7c.004.2", + "sender": "w-nws.webmaster@noaa.gov", + "sent": "2024-07-18T01:14:00-07:00" + } + ], + "sent": "2024-07-18T12:47:00-07:00", + "effective": "2024-07-18T12:47:00-07:00", + "onset": "2024-07-19T10:00:00-07:00", + "expires": "2024-07-19T03:00:00-07:00", + "ends": "2024-07-20T20:00:00-07:00", + "status": "Actual", + "messageType": "Update", + "category": "Met", + "severity": "Severe", + "certainty": "Likely", + "urgency": "Expected", + "event": "Excessive Heat Warning", + "sender": "w-nws.webmaster@noaa.gov", + "senderName": "NWS Phoenix AZ", + "headline": "Excessive Heat Warning issued July 18 at 12:47PM MST until July 20 at 8:00PM MST by NWS Phoenix AZ", + "description": "* WHAT...Dangerously hot conditions. Afternoon temperatures 112 to\n116 expected. Major Heat Risk. Overexposure can cause heat cramps\nand heat exhaustion to develop and, without intervention, can lead\nto heat stroke.\n\n* WHERE...The Northwest Valley of the Phoenix Metro Area, The East\nValley of the Phoenix Metro Area, Buckeye/Avondale, Deer Valley,\nCentral Phoenix, North Phoenix/Glendale, Scottsdale/Paradise\nValley, South Mountain/Ahwatukee, and Southeast Valley/Queen Creek.\n\n* WHEN...From 10 AM Friday to 8 PM MST Saturday.\n\n* IMPACTS...Heat related illnesses increase significantly during\nextreme heat events.\n\n* ADDITIONAL DETAILS...In Maricopa County, call 2-1-1 to find a free\ncooling center, transportation, water, and more.\nhttps://www.maricopa.gov/heat", + "instruction": "An Excessive Heat Warning means that a period of very hot\ntemperatures, even by local standards, will occur. Actions should be\ntaken to lessen the impact of the extreme heat.\n\nTake extra precautions if you work or spend time outside. When\npossible, reschedule strenuous activities to early morning or\nevening. Know the signs and symptoms of heat exhaustion and heat\nstroke. Wear lightweight and loose-fitting clothing when possible\nand drink plenty of water.\n\nTo reduce risk during outdoor work, the Occupational Safety and\nHealth Administration recommends scheduling frequent rest breaks in\nshaded or air conditioned environments. Anyone overcome by heat\nshould be moved to a cool and shaded location. Heat stroke is an\nemergency! Call 9 1 1.\n\nPublic cooling shelters are available in some areas. Consult county\nofficials for more details.", + "response": "Execute", + "parameters": { + "AWIPSidentifier": [ + "NPWPSR" + ], + "WMOidentifier": [ + "WWUS75 KPSR 181947" + ], + "NWSheadline": [ + "EXCESSIVE HEAT WARNING REMAINS IN EFFECT FROM 10 AM FRIDAY TO 8 PM MST SATURDAY" + ], + "BLOCKCHANNEL": [ + "EAS", + "NWEM", + "CMAS" + ], + "VTEC": [ + "/O.CON.KPSR.EH.W.0006.240719T1700Z-240721T0300Z/" + ], + "eventEndingTime": [ + "2024-07-21T03:00:00+00:00" + ] + } + } + }, + { + "id": "https://api.weather.gov/alerts/urn:oid:2.49.0.1.840.0.32b8fe5b1e8094248fdbb7a32619581ec4e1df14.001.1", + "type": "Feature", + "geometry": null, + "properties": { + "@id": "https://api.weather.gov/alerts/urn:oid:2.49.0.1.840.0.32b8fe5b1e8094248fdbb7a32619581ec4e1df14.001.1", + "@type": "wx:Alert", + "id": "urn:oid:2.49.0.1.840.0.32b8fe5b1e8094248fdbb7a32619581ec4e1df14.001.1", + "areaDesc": "Maricopa, AZ", + "geocode": { + "SAME": [ + "004013" + ], + "UGC": [ + "AZC013" + ] + }, + "affectedZones": [ + "https://api.weather.gov/zones/county/AZC013" + ], + "references": [], + "sent": "2024-07-18T08:13:00-07:00", + "effective": "2024-07-18T08:13:00-07:00", + "onset": "2024-07-18T08:13:00-07:00", + "expires": "2024-07-19T21:00:00-07:00", + "ends": null, + "status": "Actual", + "messageType": "Alert", + "category": "Met", + "severity": "Unknown", + "certainty": "Unknown", + "urgency": "Unknown", + "event": "Air Quality Alert", + "sender": "w-nws.webmaster@noaa.gov", + "senderName": "NWS Phoenix AZ", + "headline": "Air Quality Alert issued July 18 at 8:13AM MST by NWS Phoenix AZ", + "description": "AQAPSR\n\nThe Arizona Department of Environmental Quality (ADEQ) has issued an\nOzone High Pollution Advisory for the Phoenix Metro Area through\nFriday.\n\nThis means that forecast weather conditions combined with existing\nozone levels are expected to result in local maximum 8-hour ozone\nconcentrations that pose a health risk. Adverse health effects\nincrease as air quality deteriorates.\n\nOzone is an air contaminant which can cause breathing difficulties\nfor children, older adults, as well as persons with respiratory\nproblems. A decrease in physical activity is recommended.\n\nYou are urged to car pool, telecommute or use mass transit.\nThe use of gasoline-powered equipment should be reduced or done late\nin the day.\n\nFor details on this High Pollution Advisory, visit the ADEQ internet\nsite at www.azdeq.gov/forecast/phoenix or call 602-771-2300.", + "instruction": null, + "response": "Monitor", + "parameters": { + "AWIPSidentifier": [ + "AQAPSR" + ], + "WMOidentifier": [ + "AEUS75 KPSR 181513" + ], + "NWSheadline": [ + "OZONE HIGH POLLUTION ADVISORY FOR MARICOPA COUNTY INCLUDING THE PHOENIX METRO AREA THROUGH FRIDAY" + ], + "BLOCKCHANNEL": [ + "EAS", + "NWEM", + "CMAS" + ] + } + } + } + ], + "title": "Current watches, warnings, and advisories for 33.25 N, 112.30 W", + "updated": "2024-07-18T19:50:06+00:00" +} \ No newline at end of file diff --git a/tests/fixtures/count_reply.json b/tests/fixtures/count_reply.json new file mode 100644 index 0000000..a9a72fa --- /dev/null +++ b/tests/fixtures/count_reply.json @@ -0,0 +1,793 @@ +{ + "total": 278, + "land": 137, + "marine": 141, + "regions": { + "AL": 111, + "AT": 5, + "GL": 1, + "GM": 1, + "PA": 23 + }, + "areas": { + "AM": 5, + "AR": 1, + "AZ": 6, + "CA": 16, + "CO": 4, + "FL": 3, + "GA": 4, + "GM": 1, + "HI": 1, + "IA": 12, + "ID": 11, + "IL": 40, + "IN": 5, + "LA": 1, + "LS": 1, + "MD": 1, + "ME": 1, + "MI": 2, + "MO": 18, + "MT": 3, + "NC": 1, + "NE": 3, + "NM": 2, + "NV": 3, + "NY": 1, + "OK": 2, + "OR": 10, + "PK": 111, + "PR": 2, + "PZ": 23, + "SC": 1, + "SD": 3, + "TX": 5, + "UT": 1, + "VI": 2, + "WA": 12, + "WI": 6, + "WY": 2 + }, + "zones": { + "AMZ610": 1, + "AMZ711": 1, + "AMZ712": 1, + "AMZ716": 1, + "AMZ723": 1, + "AMZ733": 1, + "AMZ741": 1, + "ARC145": 1, + "ARC147": 1, + "AZC012": 2, + "AZC013": 3, + "AZC015": 1, + "AZC021": 1, + "AZC027": 1, + "AZZ002": 1, + "AZZ003": 1, + "AZZ036": 1, + "AZZ530": 1, + "AZZ531": 1, + "AZZ532": 1, + "AZZ533": 1, + "AZZ534": 1, + "AZZ535": 1, + "AZZ536": 1, + "AZZ537": 1, + "AZZ538": 1, + "AZZ539": 1, + "AZZ540": 1, + "AZZ541": 1, + "AZZ542": 1, + "AZZ543": 1, + "AZZ544": 1, + "AZZ545": 1, + "AZZ546": 1, + "AZZ548": 1, + "AZZ549": 1, + "AZZ550": 1, + "AZZ551": 1, + "AZZ552": 1, + "AZZ553": 1, + "AZZ554": 1, + "AZZ555": 1, + "AZZ559": 1, + "CAC001": 2, + "CAC013": 2, + "CAC019": 1, + "CAC025": 1, + "CAC027": 1, + "CAC029": 2, + "CAC031": 1, + "CAC037": 2, + "CAC039": 1, + "CAC041": 2, + "CAC043": 1, + "CAC047": 1, + "CAC053": 1, + "CAC055": 2, + "CAC065": 5, + "CAC069": 1, + "CAC071": 6, + "CAC073": 3, + "CAC075": 1, + "CAC079": 2, + "CAC081": 1, + "CAC083": 1, + "CAC085": 2, + "CAC097": 2, + "CAC107": 1, + "CAC111": 2, + "CAZ006": 1, + "CAZ038": 1, + "CAZ048": 1, + "CAZ050": 1, + "CAZ055": 1, + "CAZ056": 1, + "CAZ058": 1, + "CAZ060": 1, + "CAZ061": 1, + "CAZ062": 1, + "CAZ065": 1, + "CAZ300": 1, + "CAZ301": 1, + "CAZ302": 1, + "CAZ303": 1, + "CAZ304": 1, + "CAZ305": 1, + "CAZ306": 1, + "CAZ307": 1, + "CAZ308": 1, + "CAZ309": 1, + "CAZ310": 1, + "CAZ311": 1, + "CAZ312": 1, + "CAZ313": 1, + "CAZ314": 1, + "CAZ315": 1, + "CAZ316": 1, + "CAZ317": 1, + "CAZ318": 1, + "CAZ319": 1, + "CAZ320": 1, + "CAZ321": 1, + "CAZ324": 1, + "CAZ325": 1, + "CAZ332": 1, + "CAZ337": 1, + "CAZ338": 1, + "CAZ339": 1, + "CAZ342": 1, + "CAZ343": 1, + "CAZ344": 1, + "CAZ345": 1, + "CAZ353": 1, + "CAZ369": 1, + "CAZ370": 1, + "CAZ375": 1, + "CAZ376": 1, + "CAZ377": 1, + "CAZ378": 1, + "CAZ379": 1, + "CAZ380": 1, + "CAZ381": 1, + "CAZ382": 1, + "CAZ383": 1, + "CAZ503": 1, + "CAZ504": 1, + "CAZ506": 2, + "CAZ508": 1, + "CAZ510": 1, + "CAZ513": 1, + "CAZ514": 1, + "CAZ515": 1, + "CAZ517": 1, + "CAZ518": 1, + "CAZ522": 1, + "CAZ523": 1, + "CAZ524": 1, + "CAZ525": 1, + "CAZ526": 1, + "CAZ527": 1, + "CAZ560": 1, + "CAZ561": 1, + "CAZ562": 1, + "CAZ563": 1, + "CAZ564": 1, + "CAZ565": 1, + "CAZ566": 1, + "CAZ567": 1, + "CAZ568": 1, + "CAZ569": 1, + "CAZ570": 1, + "COC001": 1, + "COC005": 1, + "COC013": 1, + "COC014": 1, + "COC031": 1, + "COC035": 1, + "COC059": 1, + "COC069": 1, + "COC095": 1, + "COC123": 1, + "COC125": 2, + "COZ090": 1, + "FLC011": 1, + "FLC021": 1, + "FLC043": 1, + "FLC051": 1, + "FLC085": 1, + "FLC086": 1, + "FLC087": 2, + "FLC099": 1, + "FLZ063": 1, + "FLZ066": 1, + "FLZ067": 1, + "FLZ068": 1, + "FLZ069": 1, + "FLZ070": 1, + "FLZ071": 1, + "FLZ072": 1, + "FLZ073": 1, + "FLZ074": 1, + "FLZ075": 1, + "FLZ076": 1, + "FLZ077": 1, + "FLZ078": 1, + "FLZ168": 1, + "FLZ172": 1, + "FLZ173": 1, + "FLZ174": 1, + "FLZ264": 1, + "GAC007": 1, + "GAC081": 1, + "GAC099": 1, + "GAC139": 1, + "GAC177": 1, + "GAC201": 1, + "GAC273": 1, + "GAC315": 1, + "GAC321": 1, + "GAZ023": 1, + "GAZ106": 1, + "GAZ108": 1, + "GAZ124": 1, + "GAZ126": 1, + "GAZ127": 1, + "GMZ530": 1, + "HIC001": 1, + "HIC003": 1, + "HIC007": 1, + "HIC009": 1, + "HIZ001": 1, + "HIZ003": 1, + "HIZ006": 1, + "HIZ007": 1, + "HIZ009": 1, + "HIZ016": 1, + "HIZ017": 1, + "HIZ018": 1, + "HIZ023": 1, + "HIZ026": 1, + "HIZ029": 1, + "HIZ030": 1, + "HIZ031": 1, + "HIZ032": 1, + "HIZ033": 1, + "HIZ034": 1, + "HIZ035": 1, + "HIZ037": 1, + "HIZ038": 1, + "HIZ039": 1, + "HIZ040": 1, + "HIZ041": 1, + "HIZ042": 1, + "HIZ043": 1, + "HIZ044": 1, + "HIZ045": 1, + "HIZ046": 1, + "HIZ047": 1, + "HIZ048": 1, + "HIZ049": 1, + "HIZ050": 1, + "HIZ051": 1, + "HIZ052": 1, + "HIZ053": 1, + "HIZ054": 1, + "IAC045": 2, + "IAC057": 3, + "IAC061": 1, + "IAC097": 1, + "IAC111": 2, + "IAC115": 3, + "IAC139": 3, + "IAC163": 3, + "IDC001": 1, + "IDC003": 1, + "IDC009": 4, + "IDC017": 2, + "IDC021": 2, + "IDC027": 1, + "IDC035": 1, + "IDC039": 1, + "IDC043": 1, + "IDC045": 1, + "IDC047": 1, + "IDC049": 1, + "IDC053": 1, + "IDC055": 4, + "IDC057": 4, + "IDC061": 2, + "IDC069": 4, + "IDC073": 2, + "IDC075": 1, + "IDC079": 2, + "IDC083": 1, + "IDC087": 1, + "IDZ001": 2, + "IDZ002": 2, + "IDZ003": 2, + "IDZ004": 2, + "IDZ005": 1, + "IDZ006": 1, + "IDZ007": 1, + "IDZ008": 1, + "IDZ012": 1, + "IDZ014": 1, + "IDZ015": 1, + "IDZ016": 1, + "IDZ026": 2, + "IDZ027": 2, + "IDZ029": 1, + "IDZ030": 1, + "IDZ033": 1, + "ILC001": 4, + "ILC003": 2, + "ILC009": 1, + "ILC013": 3, + "ILC015": 1, + "ILC017": 1, + "ILC025": 1, + "ILC057": 1, + "ILC061": 1, + "ILC067": 3, + "ILC071": 3, + "ILC073": 2, + "ILC077": 2, + "ILC083": 2, + "ILC085": 1, + "ILC097": 2, + "ILC119": 1, + "ILC125": 1, + "ILC131": 3, + "ILC133": 1, + "ILC137": 1, + "ILC149": 3, + "ILC157": 1, + "ILC159": 1, + "ILC161": 7, + "ILC163": 1, + "ILC169": 1, + "ILC181": 1, + "ILC195": 3, + "ILC201": 5, + "INC015": 1, + "INC039": 1, + "INC073": 1, + "INC089": 1, + "INC111": 1, + "INC127": 1, + "INC131": 2, + "INC181": 1, + "LAC011": 1, + "LAC019": 1, + "LSZ140": 1, + "MDC031": 1, + "MEC009": 1, + "MEC029": 1, + "MEZ029": 1, + "MEZ030": 1, + "MIC023": 1, + "MIC093": 1, + "MIC149": 1, + "MOC031": 1, + "MOC045": 2, + "MOC099": 1, + "MOC111": 2, + "MOC113": 2, + "MOC127": 3, + "MOC157": 2, + "MOC163": 2, + "MOC173": 1, + "MOC183": 2, + "MOC186": 1, + "MOC189": 1, + "MOC201": 2, + "MTC029": 2, + "MTC031": 1, + "MTC039": 1, + "MTC047": 1, + "MTC053": 1, + "MTC061": 1, + "MTC063": 2, + "MTC077": 1, + "MTC081": 1, + "MTC089": 2, + "MTZ001": 1, + "MTZ002": 1, + "MTZ003": 1, + "MTZ004": 1, + "MTZ005": 1, + "MTZ043": 1, + "NCC001": 1, + "NCC037": 1, + "NCC057": 1, + "NCC063": 1, + "NCC065": 1, + "NCC069": 1, + "NCC085": 1, + "NCC101": 1, + "NCC105": 1, + "NCC123": 1, + "NCC125": 1, + "NCC127": 1, + "NCC135": 1, + "NCC151": 1, + "NCC167": 1, + "NCC183": 1, + "NCC191": 1, + "NCC195": 1, + "NEC027": 2, + "NEC071": 1, + "NEC089": 1, + "NEC183": 1, + "NEZ010": 1, + "NEZ028": 1, + "NEZ029": 1, + "NMC001": 1, + "NMC007": 1, + "NMC027": 1, + "NMC028": 1, + "NMC033": 1, + "NMC035": 1, + "NMC039": 1, + "NMC043": 1, + "NMC047": 1, + "NMC049": 1, + "NMC053": 1, + "NMC055": 1, + "NMC057": 1, + "NMC061": 1, + "NMZ211": 1, + "NMZ212": 1, + "NMZ214": 1, + "NMZ215": 1, + "NMZ222": 1, + "NMZ223": 1, + "NMZ224": 1, + "NMZ226": 1, + "NMZ229": 1, + "NMZ414": 1, + "NMZ415": 1, + "NMZ416": 1, + "NVC003": 2, + "NVC013": 1, + "NVC023": 1, + "NVZ016": 1, + "NVZ017": 1, + "NVZ020": 1, + "NVZ021": 1, + "NVZ022": 1, + "NVZ030": 1, + "NYC103": 1, + "NYZ081": 1, + "OKC017": 1, + "OKC027": 1, + "OKC037": 1, + "OKC051": 1, + "OKC081": 1, + "OKC083": 1, + "OKC087": 1, + "OKC109": 1, + "OKC113": 1, + "OKC131": 1, + "OKC143": 1, + "OKC145": 1, + "OKZ019": 1, + "OKZ024": 1, + "OKZ025": 1, + "OKZ026": 1, + "OKZ027": 1, + "OKZ028": 1, + "OKZ029": 1, + "OKZ054": 1, + "OKZ060": 1, + "OKZ061": 1, + "OKZ064": 1, + "OKZ067": 1, + "ORC001": 3, + "ORC013": 2, + "ORC017": 1, + "ORC021": 2, + "ORC023": 4, + "ORC025": 3, + "ORC031": 2, + "ORC045": 3, + "ORC049": 2, + "ORC055": 2, + "ORC059": 2, + "ORC061": 2, + "ORC063": 1, + "ORC065": 2, + "ORC069": 3, + "ORZ041": 1, + "ORZ044": 1, + "ORZ049": 1, + "ORZ050": 1, + "ORZ061": 1, + "ORZ062": 1, + "ORZ063": 1, + "ORZ064": 1, + "ORZ111": 1, + "ORZ112": 1, + "ORZ115": 1, + "ORZ117": 1, + "ORZ118": 1, + "ORZ120": 1, + "ORZ121": 1, + "ORZ122": 1, + "ORZ502": 1, + "ORZ503": 1, + "ORZ505": 1, + "ORZ506": 1, + "ORZ507": 1, + "ORZ508": 1, + "ORZ510": 1, + "ORZ511": 1, + "ORZ642": 1, + "ORZ644": 1, + "PKZ012": 1, + "PKZ013": 1, + "PKZ642": 1, + "PKZ643": 1, + "PKZ644": 3, + "PKZ651": 3, + "PKZ652": 1, + "PKZ661": 1, + "PKZ662": 3, + "PKZ663": 2, + "PKZ758": 1, + "PKZ765": 1, + "PKZ766": 3, + "PKZ767": 3, + "PKZ770": 3, + "PKZ772": 2, + "PKZ774": 1, + "PKZ775": 3, + "PKZ776": 3, + "PKZ777": 2, + "PKZ778": 3, + "PKZ780": 3, + "PKZ781": 3, + "PKZ782": 3, + "PKZ783": 3, + "PKZ785": 3, + "PKZ787": 2, + "PKZ803": 1, + "PKZ805": 1, + "PKZ806": 4, + "PKZ807": 3, + "PKZ809": 3, + "PKZ810": 3, + "PKZ811": 2, + "PKZ812": 2, + "PKZ816": 3, + "PKZ817": 3, + "PKZ850": 3, + "PKZ851": 6, + "PKZ853": 3, + "PKZ854": 5, + "PKZ856": 4, + "PKZ857": 2, + "PKZ858": 2, + "PKZ859": 2, + "PRC003": 1, + "PRC005": 1, + "PRC011": 1, + "PRC013": 1, + "PRC015": 2, + "PRC017": 1, + "PRC021": 1, + "PRC023": 1, + "PRC027": 1, + "PRC031": 1, + "PRC033": 1, + "PRC051": 1, + "PRC054": 1, + "PRC055": 1, + "PRC057": 2, + "PRC059": 1, + "PRC061": 1, + "PRC065": 1, + "PRC067": 1, + "PRC069": 1, + "PRC071": 1, + "PRC075": 1, + "PRC079": 1, + "PRC091": 1, + "PRC095": 2, + "PRC097": 1, + "PRC099": 1, + "PRC109": 2, + "PRC111": 1, + "PRC113": 1, + "PRC115": 1, + "PRC117": 1, + "PRC123": 1, + "PRC125": 1, + "PRC127": 1, + "PRC133": 1, + "PRC135": 1, + "PRC137": 1, + "PRC139": 1, + "PRC143": 1, + "PRC145": 1, + "PRC151": 2, + "PRC153": 1, + "PRZ001": 1, + "PRZ003": 1, + "PRZ005": 1, + "PRZ007": 1, + "PRZ008": 1, + "PRZ010": 1, + "PRZ011": 1, + "PZZ131": 1, + "PZZ132": 1, + "PZZ251": 1, + "PZZ252": 1, + "PZZ253": 1, + "PZZ271": 1, + "PZZ272": 1, + "PZZ273": 1, + "PZZ356": 1, + "PZZ376": 1, + "PZZ455": 1, + "PZZ470": 1, + "PZZ475": 1, + "PZZ540": 2, + "PZZ545": 1, + "PZZ560": 1, + "PZZ565": 1, + "PZZ570": 2, + "PZZ571": 2, + "PZZ575": 2, + "PZZ576": 1, + "PZZ645": 2, + "PZZ650": 2, + "PZZ670": 3, + "PZZ673": 3, + "PZZ676": 2, + "SCC091": 1, + "SCZ009": 1, + "SDC055": 1, + "SDC067": 1, + "SDC071": 1, + "SDC125": 1, + "SDC135": 2, + "SDZ032": 1, + "SDZ043": 1, + "TXC005": 2, + "TXC073": 1, + "TXC085": 1, + "TXC113": 1, + "TXC121": 1, + "TXC139": 1, + "TXC187": 1, + "TXC213": 1, + "TXC221": 1, + "TXC225": 1, + "TXC231": 1, + "TXC251": 1, + "TXC257": 1, + "TXC347": 1, + "TXC351": 1, + "TXC361": 1, + "TXC367": 1, + "TXC373": 1, + "TXC397": 1, + "TXC439": 1, + "TXC455": 1, + "TXC457": 1, + "TXC497": 1, + "TXZ102": 1, + "TXZ103": 1, + "TXZ104": 1, + "TXZ105": 1, + "TXZ117": 1, + "TXZ118": 1, + "TXZ119": 1, + "TXZ120": 1, + "TXZ121": 1, + "TXZ131": 1, + "TXZ133": 1, + "TXZ134": 1, + "TXZ135": 1, + "UTC021": 1, + "UTC025": 1, + "UTC053": 1, + "UTZ123": 1, + "UTZ124": 1, + "VIC010": 2, + "VIC020": 1, + "VIC030": 1, + "VIZ001": 1, + "VIZ002": 2, + "WAC001": 2, + "WAC003": 4, + "WAC005": 1, + "WAC007": 5, + "WAC013": 1, + "WAC017": 3, + "WAC019": 2, + "WAC021": 1, + "WAC023": 4, + "WAC025": 2, + "WAC037": 3, + "WAC039": 2, + "WAC043": 2, + "WAC047": 6, + "WAC051": 2, + "WAC063": 4, + "WAC065": 2, + "WAC071": 1, + "WAC075": 2, + "WAC077": 2, + "WAZ024": 1, + "WAZ026": 1, + "WAZ027": 1, + "WAZ028": 1, + "WAZ029": 1, + "WAZ030": 1, + "WAZ031": 2, + "WAZ032": 2, + "WAZ033": 2, + "WAZ034": 2, + "WAZ035": 2, + "WAZ036": 2, + "WAZ037": 2, + "WAZ038": 2, + "WAZ041": 2, + "WAZ043": 2, + "WAZ044": 2, + "WAZ047": 2, + "WAZ048": 1, + "WAZ049": 2, + "WAZ205": 1, + "WAZ206": 1, + "WAZ207": 1, + "WAZ209": 1, + "WAZ210": 1, + "WAZ521": 1, + "WAZ523": 1, + "WAZ696": 1, + "WAZ697": 1, + "WAZ698": 1, + "WAZ704": 1, + "WAZ705": 1, + "WIC027": 1, + "WIC045": 2, + "WIC055": 2, + "WIC105": 3, + "WYC013": 1, + "WYC023": 1, + "WYC029": 1, + "WYC033": 1, + "WYC035": 1, + "WYC039": 1, + "WYZ001": 1, + "WYZ012": 1, + "WYZ013": 1, + "WYZ199": 1 + } +} \ No newline at end of file diff --git a/tests/test_config_flow.py b/tests/test_config_flow.py index aa28d24..b1bca2e 100644 --- a/tests/test_config_flow.py +++ b/tests/test_config_flow.py @@ -1,13 +1,15 @@ """Test for config flow""" -from tests.const import CONFIG_DATA + from unittest.mock import patch + import pytest from homeassistant import config_entries, data_entry_flow, setup from homeassistant.const import CONF_NAME -from pytest_homeassistant_custom_component.common import MockConfigEntry from homeassistant.data_entry_flow import FlowResult, FlowResultType +from pytest_homeassistant_custom_component.common import MockConfigEntry from custom_components.nws_alerts.const import CONF_ZONE_ID, DOMAIN +from tests.const import CONFIG_DATA pytestmark = pytest.mark.asyncio diff --git a/tests/test_init.py b/tests/test_init.py index d40fb74..201cbb7 100644 --- a/tests/test_init.py +++ b/tests/test_init.py @@ -1,9 +1,10 @@ """Tests for init.""" -import pytest + from unittest.mock import patch -from homeassistant.const import CONF_NAME +import pytest from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN +from homeassistant.const import CONF_NAME from homeassistant.helpers.entity_registry import async_get from homeassistant.setup import async_setup_component from pytest_homeassistant_custom_component.common import MockConfigEntry diff --git a/tests/test_sensor.py b/tests/test_sensor.py index acb412e..89fe92a 100644 --- a/tests/test_sensor.py +++ b/tests/test_sensor.py @@ -1,8 +1,9 @@ """Test NWS Alerts Sensors""" + import pytest -from pytest_homeassistant_custom_component.common import MockConfigEntry -from homeassistant.util import slugify from homeassistant.helpers import entity_registry as er +from homeassistant.util import slugify +from pytest_homeassistant_custom_component.common import MockConfigEntry from custom_components.nws_alerts.const import DOMAIN from tests.const import CONFIG_DATA, CONFIG_DATA_2, CONFIG_DATA_BAD @@ -13,7 +14,7 @@ NWS_SENSOR_2 = "sensor.nws_alerts_yaml" -async def test_sensor(hass): +async def test_sensor(hass, mock_api): entry = MockConfigEntry( domain=DOMAIN, title="NWS Alerts", @@ -27,6 +28,38 @@ async def test_sensor(hass): assert "nws_alerts" in hass.config.components state = hass.states.get(NWS_SENSOR) assert state + assert state.state == "2" + assert state.attributes["alerts"] == [ + { + "event": "Excessive Heat Warning", + "id": "7681487b-41c6-0308-1a00-3cade72982c1", + "url": "https://api.weather.gov/alerts/urn:oid:2.49.0.1.840.0.505a7220d91b00eb1d75a3fb4f339f825496a522.004.1", + "headline": "EXCESSIVE HEAT WARNING REMAINS IN EFFECT FROM 10 AM FRIDAY TO 8 PM MST SATURDAY", + "type": "Update", + "status": "Actual", + "severity": "Severe", + "certainty": "Likely", + "onset": "2024-07-19T10:00:00-07:00", + "expires": "2024-07-19T03:00:00-07:00", + "description": "* WHAT...Dangerously hot conditions. Afternoon temperatures 112 to\n116 expected. Major Heat Risk. Overexposure can cause heat cramps\nand heat exhaustion to develop and, without intervention, can lead\nto heat stroke.\n\n* WHERE...The Northwest Valley of the Phoenix Metro Area, The East\nValley of the Phoenix Metro Area, Buckeye/Avondale, Deer Valley,\nCentral Phoenix, North Phoenix/Glendale, Scottsdale/Paradise\nValley, South Mountain/Ahwatukee, and Southeast Valley/Queen Creek.\n\n* WHEN...From 10 AM Friday to 8 PM MST Saturday.\n\n* IMPACTS...Heat related illnesses increase significantly during\nextreme heat events.\n\n* ADDITIONAL DETAILS...In Maricopa County, call 2-1-1 to find a free\ncooling center, transportation, water, and more.\nhttps://www.maricopa.gov/heat", + "instruction": "An Excessive Heat Warning means that a period of very hot\ntemperatures, even by local standards, will occur. Actions should be\ntaken to lessen the impact of the extreme heat.\n\nTake extra precautions if you work or spend time outside. When\npossible, reschedule strenuous activities to early morning or\nevening. Know the signs and symptoms of heat exhaustion and heat\nstroke. Wear lightweight and loose-fitting clothing when possible\nand drink plenty of water.\n\nTo reduce risk during outdoor work, the Occupational Safety and\nHealth Administration recommends scheduling frequent rest breaks in\nshaded or air conditioned environments. Anyone overcome by heat\nshould be moved to a cool and shaded location. Heat stroke is an\nemergency! Call 9 1 1.\n\nPublic cooling shelters are available in some areas. Consult county\nofficials for more details.", + }, + { + "event": "Air Quality Alert", + "id": "cbc5f830-921d-10c7-b447-e9bc1b744965", + "url": "https://api.weather.gov/alerts/urn:oid:2.49.0.1.840.0.32b8fe5b1e8094248fdbb7a32619581ec4e1df14.001.1", + "headline": "OZONE HIGH POLLUTION ADVISORY FOR MARICOPA COUNTY INCLUDING THE PHOENIX METRO AREA THROUGH FRIDAY", + "type": "Alert", + "status": "Actual", + "severity": "Unknown", + "certainty": "Unknown", + "onset": "2024-07-18T08:13:00-07:00", + "expires": "2024-07-19T21:00:00-07:00", + "description": "AQAPSR\n\nThe Arizona Department of Environmental Quality (ADEQ) has issued an\nOzone High Pollution Advisory for the Phoenix Metro Area through\nFriday.\n\nThis means that forecast weather conditions combined with existing\nozone levels are expected to result in local maximum 8-hour ozone\nconcentrations that pose a health risk. Adverse health effects\nincrease as air quality deteriorates.\n\nOzone is an air contaminant which can cause breathing difficulties\nfor children, older adults, as well as persons with respiratory\nproblems. A decrease in physical activity is recommended.\n\nYou are urged to car pool, telecommute or use mass transit.\nThe use of gasoline-powered equipment should be reduced or done late\nin the day.\n\nFor details on this High Pollution Advisory, visit the ADEQ internet\nsite at www.azdeq.gov/forecast/phoenix or call 602-771-2300.", + "instruction": None, + }, + ] + assert state.attributes["alerts"][0]["id"] == "7681487b-41c6-0308-1a00-3cade72982c1" entity_registry = er.async_get(hass) entity = entity_registry.async_get(NWS_SENSOR) assert entity.unique_id == f"{slugify(entry.title)}_{entry.entry_id}"