Improve error handling for Powerwall (#34580)

* Improve error handling
	modified:   homeassistant/components/powerwall/__init__.py
	modified:   homeassistant/components/powerwall/config_flow.py
	modified:   homeassistant/components/powerwall/const.py
	modified:   homeassistant/components/powerwall/strings.json
	modified:   homeassistant/components/powerwall/translations/en.json

* Change exception name
	modified:   homeassistant/components/powerwall/__init__.py
	modified:   homeassistant/components/powerwall/config_flow.py

* Add test

* Rename PowerwallError to POWERWALL_ERROR

* Modify handling of APIChangedErrors
	modified:   homeassistant/components/powerwall/__init__.py
	modified:   homeassistant/components/powerwall/const.py
This commit is contained in:
jrester authored and GitHub committed 2020-04-26 19:14:53 -05:00
1 parent aa2bfbb541
commit 4b998ea6af
6 files changed
+76 -21

No files matched your search

+21 -1
View File
@@ -1,7 +1,7 @@
"""Test the Powerwall config flow."""
from asynctest import patch
from tesla_powerwall import PowerwallUnreachableError
from tesla_powerwall import APIChangedError, PowerwallUnreachableError
from homeassistant import config_entries, setup
from homeassistant.components.powerwall.const import DOMAIN
@@ -86,3 +86,23 @@ async def test_form_cannot_connect(hass):
assert result2["type"] == "form"
assert result2["errors"] == {"base": "cannot_connect"}
async def test_form_wrong_version(hass):
"""Test we can handle wrong version error."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
mock_powerwall = _mock_powerwall_side_effect(site_info=APIChangedError(object, {}))
with patch(
"homeassistant.components.powerwall.config_flow.Powerwall",
return_value=mock_powerwall,
):
result3 = await hass.config_entries.flow.async_configure(
result["flow_id"], {CONF_IP_ADDRESS: "1.2.3.4"},
)
assert result3["type"] == "form"
assert result3["errors"] == {"base": "wrong_version"}