mirror of
https://github.com/home-assistant/core.git
synced 2025-04-25 01:38:02 +00:00
Use common strings for Panasonic Viera (#41268)
* Update strings.json * Update config_flow.py * Update homeassistant/components/panasonic_viera/strings.json Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/panasonic_viera/strings.json Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * Update config_flow.py * Update test_config_flow.py * Update test_config_flow.py * Fix failed tests * revert line 530 * Fix remaining error key * Remove not needed import * Update const.py Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
parent
356ebc1128
commit
888c92aa5e
@ -17,9 +17,6 @@ from .const import ( # pylint: disable=unused-import
|
||||
DEFAULT_PORT,
|
||||
DOMAIN,
|
||||
ERROR_INVALID_PIN_CODE,
|
||||
ERROR_NOT_CONNECTED,
|
||||
REASON_NOT_CONNECTED,
|
||||
REASON_UNKNOWN,
|
||||
)
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
@ -54,10 +51,10 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
)
|
||||
except (TimeoutError, URLError, SOAPError, OSError) as err:
|
||||
_LOGGER.error("Could not establish remote connection: %s", err)
|
||||
errors["base"] = ERROR_NOT_CONNECTED
|
||||
errors["base"] = "cannot_connect"
|
||||
except Exception as err: # pylint: disable=broad-except
|
||||
_LOGGER.exception("An unknown error occurred: %s", err)
|
||||
return self.async_abort(reason=REASON_UNKNOWN)
|
||||
return self.async_abort(reason="unknown")
|
||||
|
||||
if "base" not in errors:
|
||||
if self._remote.type == TV_TYPE_ENCRYPTED:
|
||||
@ -104,10 +101,10 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
errors["base"] = ERROR_INVALID_PIN_CODE
|
||||
except (TimeoutError, URLError, OSError) as err:
|
||||
_LOGGER.error("The remote connection was lost: %s", err)
|
||||
return self.async_abort(reason=REASON_NOT_CONNECTED)
|
||||
return self.async_abort(reason="cannot_connect")
|
||||
except Exception as err: # pylint: disable=broad-except
|
||||
_LOGGER.exception("Unknown error: %s", err)
|
||||
return self.async_abort(reason=REASON_UNKNOWN)
|
||||
return self.async_abort(reason="unknown")
|
||||
|
||||
if "base" not in errors:
|
||||
encryption_data = {
|
||||
@ -128,10 +125,10 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
)
|
||||
except (TimeoutError, URLError, SOAPError, OSError) as err:
|
||||
_LOGGER.error("The remote connection was lost: %s", err)
|
||||
return self.async_abort(reason=REASON_NOT_CONNECTED)
|
||||
return self.async_abort(reason="cannot_connect")
|
||||
except Exception as err: # pylint: disable=broad-except
|
||||
_LOGGER.exception("Unknown error: %s", err)
|
||||
return self.async_abort(reason=REASON_UNKNOWN)
|
||||
return self.async_abort(reason="unknown")
|
||||
|
||||
return self.async_show_form(
|
||||
step_id="pairing",
|
||||
|
@ -12,8 +12,4 @@ DEFAULT_PORT = 55000
|
||||
|
||||
ATTR_REMOTE = "remote"
|
||||
|
||||
ERROR_NOT_CONNECTED = "not_connected"
|
||||
ERROR_INVALID_PIN_CODE = "invalid_pin_code"
|
||||
|
||||
REASON_NOT_CONNECTED = "not_connected"
|
||||
REASON_UNKNOWN = "unknown"
|
||||
|
@ -19,13 +19,13 @@
|
||||
}
|
||||
},
|
||||
"error": {
|
||||
"not_connected": "Could not establish a remote connection with your Panasonic Viera TV",
|
||||
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
|
||||
"invalid_pin_code": "The PIN code you entered was invalid"
|
||||
},
|
||||
"abort": {
|
||||
"already_configured": "This Panasonic Viera TV is already configured.",
|
||||
"not_connected": "The remote connection with your Panasonic Viera TV was lost. Check the logs for more information.",
|
||||
"unknown": "An unknown error occured. Check the logs for more information."
|
||||
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]",
|
||||
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
|
||||
"unknown": "[%key:common::config_flow::error::unknown%]"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,9 +11,6 @@ from homeassistant.components.panasonic_viera.const import (
|
||||
DEFAULT_PORT,
|
||||
DOMAIN,
|
||||
ERROR_INVALID_PIN_CODE,
|
||||
ERROR_NOT_CONNECTED,
|
||||
REASON_NOT_CONNECTED,
|
||||
REASON_UNKNOWN,
|
||||
)
|
||||
from homeassistant.const import CONF_HOST, CONF_NAME, CONF_PIN, CONF_PORT
|
||||
|
||||
@ -116,7 +113,7 @@ async def test_flow_not_connected_error(hass):
|
||||
|
||||
assert result["type"] == "form"
|
||||
assert result["step_id"] == "user"
|
||||
assert result["errors"] == {"base": ERROR_NOT_CONNECTED}
|
||||
assert result["errors"] == {"base": "cannot_connect"}
|
||||
|
||||
|
||||
async def test_flow_unknown_abort(hass):
|
||||
@ -139,7 +136,7 @@ async def test_flow_unknown_abort(hass):
|
||||
)
|
||||
|
||||
assert result["type"] == "abort"
|
||||
assert result["reason"] == REASON_UNKNOWN
|
||||
assert result["reason"] == "unknown"
|
||||
|
||||
|
||||
async def test_flow_encrypted_valid_pin_code(hass):
|
||||
@ -255,7 +252,7 @@ async def test_flow_encrypted_not_connected_abort(hass):
|
||||
)
|
||||
|
||||
assert result["type"] == "abort"
|
||||
assert result["reason"] == REASON_NOT_CONNECTED
|
||||
assert result["reason"] == "cannot_connect"
|
||||
|
||||
|
||||
async def test_flow_encrypted_unknown_abort(hass):
|
||||
@ -288,7 +285,7 @@ async def test_flow_encrypted_unknown_abort(hass):
|
||||
)
|
||||
|
||||
assert result["type"] == "abort"
|
||||
assert result["reason"] == REASON_UNKNOWN
|
||||
assert result["reason"] == "unknown"
|
||||
|
||||
|
||||
async def test_flow_non_encrypted_already_configured_abort(hass):
|
||||
@ -475,7 +472,7 @@ async def test_imported_flow_encrypted_not_connected_abort(hass):
|
||||
)
|
||||
|
||||
assert result["type"] == "abort"
|
||||
assert result["reason"] == REASON_NOT_CONNECTED
|
||||
assert result["reason"] == "cannot_connect"
|
||||
|
||||
|
||||
async def test_imported_flow_encrypted_unknown_abort(hass):
|
||||
@ -507,7 +504,7 @@ async def test_imported_flow_encrypted_unknown_abort(hass):
|
||||
)
|
||||
|
||||
assert result["type"] == "abort"
|
||||
assert result["reason"] == REASON_UNKNOWN
|
||||
assert result["reason"] == "unknown"
|
||||
|
||||
|
||||
async def test_imported_flow_not_connected_error(hass):
|
||||
@ -530,7 +527,7 @@ async def test_imported_flow_not_connected_error(hass):
|
||||
|
||||
assert result["type"] == "form"
|
||||
assert result["step_id"] == "user"
|
||||
assert result["errors"] == {"base": ERROR_NOT_CONNECTED}
|
||||
assert result["errors"] == {"base": "cannot_connect"}
|
||||
|
||||
|
||||
async def test_imported_flow_unknown_abort(hass):
|
||||
@ -552,7 +549,7 @@ async def test_imported_flow_unknown_abort(hass):
|
||||
)
|
||||
|
||||
assert result["type"] == "abort"
|
||||
assert result["reason"] == REASON_UNKNOWN
|
||||
assert result["reason"] == "unknown"
|
||||
|
||||
|
||||
async def test_imported_flow_non_encrypted_already_configured_abort(hass):
|
||||
|
Loading…
x
Reference in New Issue
Block a user