Add tractive integration (#51002)
* Scaffold * Implement config flow * Add dymmy device tracker and TractiveClient * Add simple DeviceTracker * Add device info * Listen to tractive event and update tracker entities accordingly * Refactoring * Fix logging level * Handle connection errors * Remove sleep * Fix logging * Remove unused strings * Replace username config with email * Update aiotractive * Use debug instead of info * Cover config_flow * Update .coveragerc * Add quality scale to manifest * pylint * Update aiotractive * Do not emit SERVER_AVAILABLE, properly handle availability * Use async_get_clientsession Co-authored-by: Daniel Hjelseth Høyer <mail@dahoiv.net> * Add @Danielhiversen as a codeowner * Remove the title from strings and translations * Update homeassistant/components/tractive/__init__.py Co-authored-by: Franck Nijhof <frenck@frenck.nl> * Force CI * Use _attr style properties instead of methods * Remove entry_type * Remove quality scale * Make pyupgrade happy Co-authored-by: Daniel Hjelseth Høyer <mail@dahoiv.net> Co-authored-by: Franck Nijhof <frenck@frenck.nl>
This commit is contained in:
parent
91ab86c17c
commit
25eb27cb9f
14 changed files with 525 additions and 0 deletions
78
tests/components/tractive/test_config_flow.py
Normal file
78
tests/components/tractive/test_config_flow.py
Normal file
|
@ -0,0 +1,78 @@
|
|||
"""Test the tractive config flow."""
|
||||
from unittest.mock import patch
|
||||
|
||||
import aiotractive
|
||||
|
||||
from homeassistant import config_entries, setup
|
||||
from homeassistant.components.tractive.const import DOMAIN
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
USER_INPUT = {
|
||||
"email": "test-email@example.com",
|
||||
"password": "test-password",
|
||||
}
|
||||
|
||||
|
||||
async def test_form(hass: HomeAssistant) -> None:
|
||||
"""Test we get the form."""
|
||||
await setup.async_setup_component(hass, "persistent_notification", {})
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||
)
|
||||
assert result["type"] == "form"
|
||||
assert result["errors"] is None
|
||||
|
||||
with patch(
|
||||
"aiotractive.api.API.user_id", return_value={"user_id": "user_id"}
|
||||
), patch(
|
||||
"homeassistant.components.tractive.async_setup_entry",
|
||||
return_value=True,
|
||||
) as mock_setup_entry:
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
USER_INPUT,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result2["type"] == "create_entry"
|
||||
assert result2["title"] == "test-email@example.com"
|
||||
assert result2["data"] == USER_INPUT
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
|
||||
async def test_form_invalid_auth(hass: HomeAssistant) -> None:
|
||||
"""Test we handle invalid auth."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||
)
|
||||
|
||||
with patch(
|
||||
"aiotractive.api.API.user_id",
|
||||
side_effect=aiotractive.exceptions.UnauthorizedError,
|
||||
):
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
USER_INPUT,
|
||||
)
|
||||
|
||||
assert result2["type"] == "form"
|
||||
assert result2["errors"] == {"base": "invalid_auth"}
|
||||
|
||||
|
||||
async def test_form_unknown_error(hass: HomeAssistant) -> None:
|
||||
"""Test we handle invalid auth."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||
)
|
||||
|
||||
with patch(
|
||||
"aiotractive.api.API.user_id",
|
||||
side_effect=Exception,
|
||||
):
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
USER_INPUT,
|
||||
)
|
||||
|
||||
assert result2["type"] == "form"
|
||||
assert result2["errors"] == {"base": "unknown"}
|
Loading…
Add table
Add a link
Reference in a new issue