hass-core/tests/components/peco/test_init.py
IceBotYT a43505a0a3
Add PECO power outage counter integration (#65194)
* 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 commit 38309c5a87.

* Revert "Create a new NWS Alerts integration"

This reverts commit aeabdd37b8.

* 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
2022-03-21 23:56:53 +01:00

38 lines
1.3 KiB
Python

"""Test the PECO Outage Counter init file."""
from peco import PecoOutageApi
from homeassistant.components.peco.const import DOMAIN
from homeassistant.config_entries import ConfigEntryState
from homeassistant.core import HomeAssistant
from tests.common import MockConfigEntry
MOCK_ENTRY_DATA = {"county": "TOTAL"}
INVALID_COUNTY_DATA = {"county": "INVALID_COUNTY_THAT_SHOULD_NOT_EXIST", "test": True}
async def test_unload_entry(hass: HomeAssistant) -> None:
"""Test the unload entry."""
config_entry = MockConfigEntry(domain=DOMAIN, data=MOCK_ENTRY_DATA)
config_entry.add_to_hass(hass)
assert await hass.config_entries.async_setup(config_entry.entry_id)
assert hass.data[DOMAIN]
entries = hass.config_entries.async_entries(DOMAIN)
assert len(entries) == 1
assert entries[0].state == ConfigEntryState.LOADED
await hass.config_entries.async_unload(entries[0].entry_id)
await hass.async_block_till_done()
assert entries[0].state == ConfigEntryState.NOT_LOADED
async def test_data(hass: HomeAssistant) -> None:
"""Test the data."""
config_entry = MockConfigEntry(domain=DOMAIN, data=MOCK_ENTRY_DATA)
config_entry.add_to_hass(hass)
assert await hass.config_entries.async_setup(config_entry.entry_id)
assert hass.data[DOMAIN]
assert isinstance(hass.data[DOMAIN][config_entry.entry_id], PecoOutageApi)