Refactor Tado to use OAuth in the DeviceTracker (#102610)

* Refactor to use TadoConnector in the DeviceTracker

* Proposing myself as code owner to be notified of issues

* Update homeassistant/components/tado/device_tracker.py

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>

* Fixing method names

* Current progress, switching machines

* Updating DeviceTracker to working prototype

* Removing unnecessary callback

* Adding dispatcher logic

* Minor fine-tuning the intervals

* Removing unnecessary debug log

* Update homeassistant/components/tado/device_tracker.py

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>

* Update homeassistant/components/tado/device_tracker.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Fix sorting

* Retrieve devices from the Tado connector data

* Asyncio feedback & dispatch generic mobile devices

* Updating const

* Fine-tuning unloading

* Making add_tracked_entites callback

* Adding unload over dispatcher_connect

* Convert on_demand_update to callback

* Removing now unused method

* Merging method to on_demand_u

* Adding create_issue to address repair

* Updating with better translation

* Converting to callback

* Adding _attr_should_poll

* Putting back the on_demand_update

* Adding unique_id

* Converting to TrackerEntity

* Adding import step (review needed!)

* Update homeassistant/components/tado/device_tracker.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Update homeassistant/components/tado/device_tracker.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Update homeassistant/components/tado/device_tracker.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Update homeassistant/components/tado/config_flow.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Typing and location_name

* Changing to _attr_unique_id

* Import improvement attempt

* Property feedback

* Update homeassistant/components/tado/config_flow.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Adding CONF_HOME_ID and task in get_scanner

* Updating descriptions

* Removing the create_task

* Putting back PLATFORM_SCHEMA

* Adding device_tracker

* Adding get for HomeID

* Get it better ;)

* Retrieve HomeID from API

* Add integration title in dialogs

* Update homeassistant/components/tado/config_flow.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Update homeassistant/components/tado/config_flow.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Update homeassistant/components/tado/config_flow.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Fixing homeID and strings.json

* Delete request in strings

* Update deprecation date

* Adding test cases for import flow

* Update tests/components/tado/test_config_flow.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Update tests/components/tado/test_config_flow.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Update tests/components/tado/test_config_flow.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Removing none

* Fixing test cases

* Update homeassistant/components/tado/config_flow.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Removing from context manager

* Removing code owner

* Re-adding code owner

* Fix get scanner return value

* Fix device tracker interface

---------

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
Erwin Douna 2023-12-27 14:17:23 +01:00 committed by GitHub
parent 0694ff8965
commit 4decc2bbfb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 382 additions and 119 deletions

View file

@ -260,3 +260,120 @@ async def test_form_homekit(hass: HomeAssistant) -> None:
),
)
assert result["type"] == "abort"
async def test_import_step(hass: HomeAssistant) -> None:
"""Test import step."""
mock_tado_api = _get_mock_tado_api(getMe={"homes": [{"id": 1, "name": "myhome"}]})
with patch(
"homeassistant.components.tado.config_flow.Tado",
return_value=mock_tado_api,
), patch(
"homeassistant.components.tado.async_setup_entry",
return_value=True,
) as mock_setup_entry:
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_IMPORT},
data={
"username": "test-username",
"password": "test-password",
"home_id": 1,
},
)
await hass.async_block_till_done()
assert result["type"] == FlowResultType.CREATE_ENTRY
assert result["data"] == {
"username": "test-username",
"password": "test-password",
"home_id": "1",
}
assert mock_setup_entry.call_count == 1
async def test_import_step_existing_entry(hass: HomeAssistant) -> None:
"""Test import step with existing entry."""
entry = MockConfigEntry(
domain=DOMAIN,
data={
"username": "test-username",
"password": "test-password",
"home_id": 1,
},
)
entry.add_to_hass(hass)
with patch(
"homeassistant.components.tado.async_setup_entry",
return_value=True,
) as mock_setup_entry:
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_IMPORT},
data={
"username": "test-username",
"password": "test-password",
"home_id": 1,
},
)
await hass.async_block_till_done()
assert result["type"] == FlowResultType.ABORT
assert result["reason"] == "already_configured"
assert mock_setup_entry.call_count == 0
async def test_import_step_validation_failed(hass: HomeAssistant) -> None:
"""Test import step with validation failed."""
with patch(
"homeassistant.components.tado.config_flow.Tado",
side_effect=RuntimeError,
):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_IMPORT},
data={
"username": "test-username",
"password": "test-password",
"home_id": 1,
},
)
await hass.async_block_till_done()
assert result["type"] == FlowResultType.ABORT
assert result["reason"] == "import_failed"
async def test_import_step_unique_id_configured(hass: HomeAssistant) -> None:
"""Test import step with unique ID already configured."""
entry = MockConfigEntry(
domain=DOMAIN,
data={
"username": "test-username",
"password": "test-password",
"home_id": 1,
},
unique_id="unique_id",
)
entry.add_to_hass(hass)
with patch(
"homeassistant.components.tado.async_setup_entry",
return_value=True,
) as mock_setup_entry:
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_IMPORT},
data={
"username": "test-username",
"password": "test-password",
"home_id": 1,
},
)
await hass.async_block_till_done()
assert result["type"] == FlowResultType.ABORT
assert result["reason"] == "already_configured"
assert mock_setup_entry.call_count == 0