2022-01-19 23:52:20 +00:00
|
|
|
"""Test the Netatmo diagnostics."""
|
|
|
|
from unittest.mock import AsyncMock, patch
|
|
|
|
|
2022-01-20 22:02:47 +00:00
|
|
|
from homeassistant.components.diagnostics import REDACTED
|
2022-01-19 23:52:20 +00:00
|
|
|
from homeassistant.setup import async_setup_component
|
|
|
|
|
|
|
|
from .common import fake_post_request
|
|
|
|
|
|
|
|
from tests.components.diagnostics import get_diagnostics_for_config_entry
|
|
|
|
|
|
|
|
|
|
|
|
async def test_entry_diagnostics(hass, hass_client, config_entry):
|
|
|
|
"""Test config entry diagnostics."""
|
|
|
|
with patch(
|
|
|
|
"homeassistant.components.netatmo.api.AsyncConfigEntryNetatmoAuth",
|
|
|
|
) as mock_auth, patch(
|
|
|
|
"homeassistant.helpers.config_entry_oauth2_flow.async_get_config_entry_implementation",
|
|
|
|
), patch(
|
|
|
|
"homeassistant.components.netatmo.webhook_generate_url"
|
|
|
|
):
|
|
|
|
mock_auth.return_value.async_post_request.side_effect = fake_post_request
|
|
|
|
mock_auth.return_value.async_addwebhook.side_effect = AsyncMock()
|
|
|
|
mock_auth.return_value.async_dropwebhook.side_effect = AsyncMock()
|
|
|
|
assert await async_setup_component(hass, "netatmo", {})
|
|
|
|
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
result = await get_diagnostics_for_config_entry(hass, hass_client, config_entry)
|
|
|
|
|
|
|
|
# ignore for tests
|
|
|
|
result["info"]["data"]["token"].pop("expires_at")
|
|
|
|
result["info"].pop("entry_id")
|
|
|
|
|
|
|
|
assert result["info"] == {
|
|
|
|
"data": {
|
|
|
|
"auth_implementation": "cloud",
|
|
|
|
"token": {
|
2022-01-20 22:02:47 +00:00
|
|
|
"access_token": REDACTED,
|
2022-01-19 23:52:20 +00:00
|
|
|
"expires_in": 60,
|
2022-01-20 22:02:47 +00:00
|
|
|
"refresh_token": REDACTED,
|
2022-01-19 23:52:20 +00:00
|
|
|
"scope": [
|
|
|
|
"read_station",
|
|
|
|
"read_camera",
|
|
|
|
"access_camera",
|
|
|
|
"write_camera",
|
|
|
|
"read_presence",
|
|
|
|
"access_presence",
|
|
|
|
"write_presence",
|
|
|
|
"read_homecoach",
|
|
|
|
"read_smokedetector",
|
|
|
|
"read_thermostat",
|
|
|
|
"write_thermostat",
|
|
|
|
],
|
|
|
|
"type": "Bearer",
|
|
|
|
},
|
2022-01-20 22:02:47 +00:00
|
|
|
"webhook_id": REDACTED,
|
2022-01-19 23:52:20 +00:00
|
|
|
},
|
|
|
|
"disabled_by": None,
|
|
|
|
"domain": "netatmo",
|
|
|
|
"options": {
|
|
|
|
"weather_areas": {
|
|
|
|
"Home avg": {
|
|
|
|
"area_name": "Home avg",
|
2022-01-20 22:02:47 +00:00
|
|
|
"lat_ne": REDACTED,
|
|
|
|
"lat_sw": REDACTED,
|
|
|
|
"lon_ne": REDACTED,
|
|
|
|
"lon_sw": REDACTED,
|
2022-01-19 23:52:20 +00:00
|
|
|
"mode": "avg",
|
|
|
|
"show_on_map": False,
|
|
|
|
},
|
|
|
|
"Home max": {
|
|
|
|
"area_name": "Home max",
|
2022-01-20 22:02:47 +00:00
|
|
|
"lat_ne": REDACTED,
|
|
|
|
"lat_sw": REDACTED,
|
|
|
|
"lon_ne": REDACTED,
|
|
|
|
"lon_sw": REDACTED,
|
2022-01-19 23:52:20 +00:00
|
|
|
"mode": "max",
|
|
|
|
"show_on_map": True,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"pref_disable_new_entities": False,
|
|
|
|
"pref_disable_polling": False,
|
|
|
|
"source": "user",
|
|
|
|
"title": "Mock Title",
|
|
|
|
"unique_id": "netatmo",
|
|
|
|
"version": 1,
|
|
|
|
"webhook_registered": False,
|
|
|
|
}
|
|
|
|
|
2022-01-21 09:26:18 +00:00
|
|
|
for home in result["data"]["AsyncClimateTopology"]["homes"]:
|
|
|
|
assert home["coordinates"] == REDACTED
|