mirror of
https://github.com/home-assistant/core.git
synced 2026-12-05 05:14:01 -04:00
Raise ConfigEntryError when the API has changed in powerwall (#185114)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
e5cc0a0531
commit
c61510de1d
@@ -18,7 +18,11 @@ from homeassistant.components import persistent_notification
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_IP_ADDRESS, CONF_PASSWORD, Platform
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
||||
from homeassistant.exceptions import (
|
||||
ConfigEntryAuthFailed,
|
||||
ConfigEntryError,
|
||||
ConfigEntryNotReady,
|
||||
)
|
||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||
from homeassistant.helpers.aiohttp_client import async_create_clientsession
|
||||
from homeassistant.helpers.update_coordinator import UpdateFailed
|
||||
@@ -189,13 +193,13 @@ async def async_setup_entry(hass: HomeAssistant, entry: PowerwallConfigEntry) ->
|
||||
except (TimeoutError, PowerwallUnreachableError) as err:
|
||||
raise ConfigEntryNotReady from err
|
||||
except MissingAttributeError as err:
|
||||
# The error might include some important
|
||||
# information about what exactly changed.
|
||||
_LOGGER.error("The powerwall api has changed: %s", str(err))
|
||||
persistent_notification.async_create(
|
||||
hass, API_CHANGED_ERROR_BODY, API_CHANGED_TITLE
|
||||
)
|
||||
return False
|
||||
raise ConfigEntryError(
|
||||
translation_domain=DOMAIN,
|
||||
translation_key="api_changed",
|
||||
) from err
|
||||
except AccessDeniedError as err:
|
||||
if use_auth_cookie and tries == 0:
|
||||
_LOGGER.debug(
|
||||
|
||||
@@ -197,5 +197,10 @@
|
||||
"name": "Off-grid operation"
|
||||
}
|
||||
}
|
||||
},
|
||||
"exceptions": {
|
||||
"api_changed": {
|
||||
"message": "The Powerwall API has changed"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,10 +2,11 @@
|
||||
|
||||
import datetime
|
||||
from http.cookies import Morsel
|
||||
from unittest.mock import MagicMock, patch
|
||||
from unittest.mock import MagicMock, Mock, patch
|
||||
|
||||
from aiohttp import CookieJar
|
||||
from tesla_powerwall import AccessDeniedError, ApiError, LoginResponse
|
||||
from tesla_powerwall.error import MissingAttributeError
|
||||
|
||||
from homeassistant.components.powerwall.const import (
|
||||
AUTH_COOKIE_KEY,
|
||||
@@ -377,3 +378,25 @@ async def test_setup_non_404_api_error_propagates(hass: HomeAssistant) -> None:
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert config_entry.state is ConfigEntryState.SETUP_RETRY
|
||||
|
||||
|
||||
async def test_setup_api_changed(hass: HomeAssistant) -> None:
|
||||
"""Test setup fails when the Powerwall API has changed."""
|
||||
mock_powerwall = await _mock_powerwall_with_fixtures(hass)
|
||||
config_entry = MockConfigEntry(domain=DOMAIN, data={CONF_IP_ADDRESS: "1.2.3.4"})
|
||||
config_entry.add_to_hass(hass)
|
||||
|
||||
with (
|
||||
patch(
|
||||
"homeassistant.components.powerwall.Powerwall", return_value=mock_powerwall
|
||||
),
|
||||
patch(
|
||||
"homeassistant.components.powerwall._login_and_fetch_base_info",
|
||||
side_effect=MissingAttributeError(Mock(), "din", "operation"),
|
||||
),
|
||||
):
|
||||
await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert config_entry.state is ConfigEntryState.SETUP_ERROR
|
||||
assert config_entry.reason == "The Powerwall API has changed"
|
||||
|
||||
Reference in New Issue
Block a user