|
23 | 23 | import pytest |
24 | 24 |
|
25 | 25 | from homeassistant import config_entries |
| 26 | +from homeassistant.components.openaq.config_flow import OpenAQLocationFlowData |
26 | 27 | from homeassistant.components.openaq.const import ( |
27 | 28 | CONF_LIMIT, |
28 | 29 | CONF_LOCATION_ID, |
@@ -265,6 +266,38 @@ async def test_location_subentry_map_flow_sorts_by_sensor_count_before_distance( |
265 | 266 | ] |
266 | 267 |
|
267 | 268 |
|
| 269 | +async def test_location_subentry_map_flow_labels_unknown_distance( |
| 270 | + hass: HomeAssistant, |
| 271 | + mock_openaq_client: AsyncMock, |
| 272 | + mock_config_entry: MockConfigEntry, |
| 273 | +) -> None: |
| 274 | + """Test map search labels locations with invalid distances.""" |
| 275 | + mock_config_entry.add_to_hass(hass) |
| 276 | + mock_openaq_client.locations.list.return_value = make_response( |
| 277 | + [make_location(location_id=9999, distance=True)] |
| 278 | + ) |
| 279 | + result = await hass.config_entries.subentries.async_init( |
| 280 | + (mock_config_entry.entry_id, "location"), |
| 281 | + context={"source": config_entries.SOURCE_USER}, |
| 282 | + ) |
| 283 | + |
| 284 | + result = await hass.config_entries.subentries.async_configure( |
| 285 | + result["flow_id"], |
| 286 | + { |
| 287 | + ATTR_LOCATION: {ATTR_LATITUDE: 35.1, ATTR_LONGITUDE: -106.6}, |
| 288 | + CONF_RADIUS: 5000, |
| 289 | + CONF_LIMIT: 10, |
| 290 | + }, |
| 291 | + ) |
| 292 | + |
| 293 | + assert _get_select_options(result) == [ |
| 294 | + SelectOptionDict( |
| 295 | + value="9999", |
| 296 | + label="Del Norte, Albuquerque - 1 sensor: PM2.5 - unknown distance", |
| 297 | + ) |
| 298 | + ] |
| 299 | + |
| 300 | + |
268 | 301 | async def test_location_subentry_map_flow_limits_to_top_five_locations( |
269 | 302 | hass: HomeAssistant, |
270 | 303 | mock_openaq_client: AsyncMock, |
@@ -465,6 +498,41 @@ async def test_location_subentry_invalid_map_location_id( |
465 | 498 | assert result["errors"] == {"base": "no_locations_found"} |
466 | 499 |
|
467 | 500 |
|
| 501 | +async def test_location_subentry_invalid_map_sensors( |
| 502 | + hass: HomeAssistant, |
| 503 | + mock_openaq_client: AsyncMock, |
| 504 | + mock_config_entry: MockConfigEntry, |
| 505 | +) -> None: |
| 506 | + """Test map search ignores locations without sensor lists.""" |
| 507 | + mock_config_entry.add_to_hass(hass) |
| 508 | + mock_openaq_client.locations.list.return_value = make_response( |
| 509 | + [SimpleNamespace(id=9999, name="Bad", locality="Albuquerque", sensors=None)] |
| 510 | + ) |
| 511 | + result = await hass.config_entries.subentries.async_init( |
| 512 | + (mock_config_entry.entry_id, "location"), |
| 513 | + context={"source": config_entries.SOURCE_USER}, |
| 514 | + ) |
| 515 | + result = await hass.config_entries.subentries.async_configure( |
| 516 | + result["flow_id"], |
| 517 | + { |
| 518 | + ATTR_LOCATION: {ATTR_LATITUDE: 35.1, ATTR_LONGITUDE: -106.6}, |
| 519 | + CONF_RADIUS: 5000, |
| 520 | + CONF_LIMIT: 10, |
| 521 | + }, |
| 522 | + ) |
| 523 | + |
| 524 | + assert result["type"] is FlowResultType.FORM |
| 525 | + assert result["step_id"] == "map" |
| 526 | + assert result["errors"] == {"base": "no_locations_found"} |
| 527 | + |
| 528 | + |
| 529 | +def test_location_select_label_without_supported_parameters() -> None: |
| 530 | + """Test location select label with no supported parameters.""" |
| 531 | + location = OpenAQLocationFlowData(location_id=9999, title="Del Norte") |
| 532 | + |
| 533 | + assert location.select_label == "Del Norte" |
| 534 | + |
| 535 | + |
468 | 536 | @pytest.mark.parametrize( |
469 | 537 | ("exception", "error"), |
470 | 538 | [ |
|
0 commit comments