From 6fe54e31ccc9397566076e172c777106bf6c28a3 Mon Sep 17 00:00:00 2001 From: Haemish Kyd Date: Sun, 12 Jul 2020 22:33:30 +0200 Subject: [PATCH] Apply code quality updates to poolsense (#37781) * Created a binary sensor and corrected some review comments. * Updated the poolsense class and its interface to handle credentials better * Moved the client session to the PoolSense class. * Apply suggestions from code review * Update binary_sensor.py * Update homeassistant/components/poolsense/__init__.py * Update sensor.py * Update binary_sensor.py * Removed unnecessary class variable * Correcting a merge error. Co-authored-by: Chris Talkington --- .../components/poolsense/config_flow.py | 9 ++++---- .../components/poolsense/translations/en.json | 22 +++++++++---------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/homeassistant/components/poolsense/config_flow.py b/homeassistant/components/poolsense/config_flow.py index f6386fb34f5..a56ec8971f6 100644 --- a/homeassistant/components/poolsense/config_flow.py +++ b/homeassistant/components/poolsense/config_flow.py @@ -21,11 +21,10 @@ class PoolSenseConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): def __init__(self): """Initialize PoolSense config flow.""" - self._errors = {} async def async_step_user(self, user_input=None): """Handle the initial step.""" - self._errors = {} + errors = {} if user_input is not None: await self.async_set_unique_id(user_input[CONF_EMAIL]) @@ -43,9 +42,9 @@ class PoolSenseConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): api_key_valid = await poolsense.test_poolsense_credentials() if not api_key_valid: - self._errors["base"] = "invalid_auth" + errors["base"] = "invalid_auth" - if not self._errors: + if not errors: return self.async_create_entry( title=user_input[CONF_EMAIL], data={ @@ -59,5 +58,5 @@ class PoolSenseConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): data_schema=vol.Schema( {vol.Required(CONF_EMAIL): str, vol.Required(CONF_PASSWORD): str} ), - errors=self._errors or {}, + errors=errors or {}, ) diff --git a/homeassistant/components/poolsense/translations/en.json b/homeassistant/components/poolsense/translations/en.json index a38fca9ed48..9104c9a6268 100644 --- a/homeassistant/components/poolsense/translations/en.json +++ b/homeassistant/components/poolsense/translations/en.json @@ -1,22 +1,22 @@ { "config": { - "abort": { - "already_configured": "Device is already configured" - }, - "error": { - "cannot_connect": "Failed to connect", - "invalid_auth": "Invalid authentication", - "unknown": "Unexpected error" - }, "step": { "user": { + "title": "PoolSense", + "description": "Set up PoolSense integration. Register on the dedicated app to get your username and password. Serial is optional.", "data": { "email": "Email", "password": "Password" - }, - "description": "[%key:common::config_flow::description%]", - "title": "PoolSense" + } } + }, + "error": { + "cannot_connect": "Can't connect to PoolSense.", + "invalid_auth": "Invalid authorisation details.", + "unknown": "Unknown Error." + }, + "abort": { + "already_configured": "Device already configured." } } } \ No newline at end of file