Add Twente Milieu integration (#25129)
* Adds Twente Milieu integration * Addresses flake8 warnings * Adds required test deps * Fixes path typo in coveragerc * dispatcher_send -> async_dispatcher_send Signed-off-by: Franck Nijhof <frenck@addons.community> * Removes not needed __init__ Signed-off-by: Franck Nijhof <frenck@addons.community> * Remove explicitly setting None default value on get call Signed-off-by: Franck Nijhof <frenck@addons.community> * Correct typo in comment Signed-off-by: Franck Nijhof <frenck@addons.community> * Clean storage for only the unloaded entry Signed-off-by: Franck Nijhof <frenck@addons.community> * asyncio.wait on updating all integrations Signed-off-by: Franck Nijhof <frenck@addons.community> * Use string formatting Signed-off-by: Franck Nijhof <frenck@addons.community> * Set a more sane SCAN_INTERVAL Signed-off-by: Franck Nijhof <frenck@addons.community> * Small refactor around services Signed-off-by: Franck Nijhof <frenck@addons.community> * Small styling correction * Extract update logic into own function Signed-off-by: Franck Nijhof <frenck@addons.community> * Addresses flake8 warnings
This commit is contained in:
1 parent
369e6a3905
commit
9d4b5ee58d
16 files changed
+539
No files matched your search
@@ -0,0 +1 @@
|
||||
"""Tests for the Twente Milieu integration."""
|
||||
@@ -0,0 +1,112 @@
|
||||
"""Tests for the Twente Milieu config flow."""
|
||||
import aiohttp
|
||||
|
||||
from homeassistant import data_entry_flow
|
||||
from homeassistant.components.twentemilieu import config_flow
|
||||
from homeassistant.components.twentemilieu.const import (
|
||||
CONF_HOUSE_LETTER,
|
||||
CONF_HOUSE_NUMBER,
|
||||
CONF_POST_CODE,
|
||||
DOMAIN,
|
||||
)
|
||||
from homeassistant.const import CONF_ID
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
FIXTURE_USER_INPUT = {
|
||||
CONF_ID: "12345",
|
||||
CONF_POST_CODE: "1234AB",
|
||||
CONF_HOUSE_NUMBER: "1",
|
||||
CONF_HOUSE_LETTER: "A",
|
||||
}
|
||||
|
||||
|
||||
async def test_show_set_form(hass):
|
||||
"""Test that the setup form is served."""
|
||||
flow = config_flow.TwenteMilieuFlowHandler()
|
||||
flow.hass = hass
|
||||
result = await flow.async_step_user(user_input=None)
|
||||
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||
assert result["step_id"] == "user"
|
||||
|
||||
|
||||
async def test_connection_error(hass, aioclient_mock):
|
||||
"""Test we show user form on Twente Milieu connection error."""
|
||||
aioclient_mock.post(
|
||||
"https://wasteapi.2go-mobile.com/api/FetchAdress",
|
||||
exc=aiohttp.ClientError,
|
||||
)
|
||||
|
||||
flow = config_flow.TwenteMilieuFlowHandler()
|
||||
flow.hass = hass
|
||||
result = await flow.async_step_user(user_input=FIXTURE_USER_INPUT)
|
||||
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||
assert result["step_id"] == "user"
|
||||
assert result["errors"] == {"base": "connection_error"}
|
||||
|
||||
|
||||
async def test_invalid_address(hass, aioclient_mock):
|
||||
"""Test we show user form on Twente Milieu invalid address error."""
|
||||
aioclient_mock.post(
|
||||
"https://wasteapi.2go-mobile.com/api/FetchAdress",
|
||||
json={"dataList": []},
|
||||
headers={"Content-Type": "application/json"},
|
||||
)
|
||||
|
||||
flow = config_flow.TwenteMilieuFlowHandler()
|
||||
flow.hass = hass
|
||||
result = await flow.async_step_user(user_input=FIXTURE_USER_INPUT)
|
||||
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||
assert result["step_id"] == "user"
|
||||
assert result["errors"] == {"base": "invalid_address"}
|
||||
|
||||
|
||||
async def test_address_already_set_up(hass, aioclient_mock):
|
||||
"""Test we abort if address has already been set up."""
|
||||
MockConfigEntry(
|
||||
domain=DOMAIN, data=FIXTURE_USER_INPUT, title="12345"
|
||||
).add_to_hass(hass)
|
||||
|
||||
aioclient_mock.post(
|
||||
"https://wasteapi.2go-mobile.com/api/FetchAdress",
|
||||
json={"dataList": [{"UniqueId": "12345"}]},
|
||||
headers={"Content-Type": "application/json"},
|
||||
)
|
||||
|
||||
flow = config_flow.TwenteMilieuFlowHandler()
|
||||
flow.hass = hass
|
||||
result = await flow.async_step_user(user_input=FIXTURE_USER_INPUT)
|
||||
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
||||
assert result["reason"] == "address_already_set_up"
|
||||
|
||||
|
||||
async def test_full_flow_implementation(hass, aioclient_mock):
|
||||
"""Test registering an integration and finishing flow works."""
|
||||
aioclient_mock.post(
|
||||
"https://wasteapi.2go-mobile.com/api/FetchAdress",
|
||||
json={"dataList": [{"UniqueId": "12345"}]},
|
||||
headers={"Content-Type": "application/json"},
|
||||
)
|
||||
|
||||
flow = config_flow.TwenteMilieuFlowHandler()
|
||||
flow.hass = hass
|
||||
result = await flow.async_step_user(user_input=None)
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||
assert result["step_id"] == "user"
|
||||
|
||||
result = await flow.async_step_user(user_input=FIXTURE_USER_INPUT)
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||
assert result["title"] == "12345"
|
||||
assert result["data"][CONF_POST_CODE] == FIXTURE_USER_INPUT[CONF_POST_CODE]
|
||||
assert (
|
||||
result["data"][CONF_HOUSE_NUMBER]
|
||||
== FIXTURE_USER_INPUT[CONF_HOUSE_NUMBER]
|
||||
)
|
||||
assert (
|
||||
result["data"][CONF_HOUSE_LETTER]
|
||||
== FIXTURE_USER_INPUT[CONF_HOUSE_LETTER]
|
||||
)
|
||||
Reference in new issue
Block a user