* Create a new NWS Alerts integration * Create a new NWS Alerts integration * Create new PECO integration * Remove empty keys * Revert "Create a new NWS Alerts integration" This reverts commit38309c5a87
. * Revert "Create a new NWS Alerts integration" This reverts commitaeabdd37b8
. * Fix test with new mock data * Add init and sensor to .coveragerc and more tests for config flow * Small fixes and replacing patch with pytest.raises in testing invalid county * Add type defs and fix test_config_flow to use MultipleValid instead * Fix issues with 'typing.Dict' * Move API communication to seperate PyPI library * Switch PyPI library from httpx to aiohttp to allow for passing in websessions * Commit file changes requested by farmio as listed here:d267e4300a
* Add suggestions requested by farmio as listed here:586d8ffa42
* Move native_unit_of_measurement from prop to attr * Update PLATFORMS constant type annotation Co-authored-by: Matthias Alphart <farmio@alphart.net> * Add peco to .strict-typing I am from school so I can't run mypy atm * Forgot to import Final * Do as requested [here](https://github.com/home-assistant/core/runs/5070634928?check_suite_focus=true) * Updated mypy.ini, checks should pass now * Fix to conform to mypy restrictions https://github.com/home-assistant/core/runs/5072861837\?check_suite_focus\=true * Fix type annotations * Fix tests * Use cast in async_update_data * Add data type to CoordinatorEntity and DataUpdateCoordinator * More cleanup from suggestions here: https://github.com/home-assistant/core/pull/65194\#pullrequestreview-908183493 * Fix tests for new code * Cleaning up a speck of dust * Remove unused variable from the peco sensor * Add rounding to percentage, and extra clean-up * Final suggestions from @farmio * Update SCAN_INTERVAL to be a little bit faster * Change the SCAN_INTERVAL to be somewhat near the update interval of the outage map, as noted by farmio * New UpdateCoordinator typing
57 lines
1.8 KiB
Python
57 lines
1.8 KiB
Python
"""Test the PECO Outage Counter config flow."""
|
|
from unittest.mock import patch
|
|
|
|
from pytest import raises
|
|
from voluptuous.error import MultipleInvalid
|
|
|
|
from homeassistant import config_entries
|
|
from homeassistant.components.peco.const import DOMAIN
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.data_entry_flow import RESULT_TYPE_CREATE_ENTRY, RESULT_TYPE_FORM
|
|
|
|
|
|
async def test_form(hass: HomeAssistant) -> None:
|
|
"""Test we get the form."""
|
|
result = await hass.config_entries.flow.async_init(
|
|
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
|
)
|
|
assert result["type"] == RESULT_TYPE_FORM
|
|
assert result["errors"] is None
|
|
|
|
with patch(
|
|
"homeassistant.components.peco.async_setup_entry",
|
|
return_value=True,
|
|
):
|
|
result2 = await hass.config_entries.flow.async_configure(
|
|
result["flow_id"],
|
|
{
|
|
"county": "PHILADELPHIA",
|
|
},
|
|
)
|
|
await hass.async_block_till_done()
|
|
|
|
assert result2["type"] == RESULT_TYPE_CREATE_ENTRY
|
|
assert result2["title"] == "Philadelphia Outage Count"
|
|
assert result2["data"] == {
|
|
"county": "PHILADELPHIA",
|
|
}
|
|
|
|
|
|
async def test_invalid_county(hass: HomeAssistant) -> None:
|
|
"""Test if the InvalidCounty error works."""
|
|
result = await hass.config_entries.flow.async_init(
|
|
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
|
)
|
|
assert result["type"] == RESULT_TYPE_FORM
|
|
assert result["errors"] is None
|
|
|
|
with raises(MultipleInvalid):
|
|
await hass.config_entries.flow.async_configure(
|
|
result["flow_id"],
|
|
{
|
|
"county": "INVALID_COUNTY_THAT_SHOULD_NOT_EXIST",
|
|
},
|
|
)
|
|
await hass.async_block_till_done()
|
|
|
|
# it should have errored, instead of returning an errors dict, since this error should never happen
|