Address late review of Flipr (#54668)

* Code format correction

* Other code review remarks of MartinHjelmare

* Simplification of flipr instantiation

* Formatting correction
This commit is contained in:
cnico 2021-08-16 07:12:39 +02:00 committed by GitHub
parent 094f7d38ad
commit 416668c289
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 9 deletions

View file

@ -35,7 +35,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
return True
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload a config entry."""
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
@ -54,8 +54,6 @@ class FliprDataUpdateCoordinator(DataUpdateCoordinator):
password = entry.data[CONF_PASSWORD]
self.flipr_id = entry.data[CONF_FLIPR_ID]
_LOGGER.debug("Config entry values : %s, %s", username, self.flipr_id)
# Establishes the connection.
self.client = FliprAPIRestClient(username, password)
self.entry = entry

View file

@ -45,7 +45,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
errors["base"] = "unknown"
_LOGGER.exception(exception)
if not errors and len(flipr_ids) == 0:
if not errors and not flipr_ids:
# No flipr_id found. Tell the user with an error message.
errors["base"] = "no_flipr_id_found"
@ -85,9 +85,8 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
async def _authenticate_and_search_flipr(self) -> list[str]:
"""Validate the username and password provided and searches for a flipr id."""
client = await self.hass.async_add_executor_job(
FliprAPIRestClient, self._username, self._password
)
# Instantiates the flipr API that does not require async since it is has no network access.
client = FliprAPIRestClient(self._username, self._password)
flipr_ids = await self.hass.async_add_executor_job(client.search_flipr_ids)

View file

@ -6,6 +6,7 @@ from homeassistant.const import (
ATTR_ATTRIBUTION,
DEVICE_CLASS_TEMPERATURE,
DEVICE_CLASS_TIMESTAMP,
ELECTRIC_POTENTIAL_MILLIVOLT,
TEMP_CELSIUS,
)
@ -14,7 +15,7 @@ from .const import ATTRIBUTION, CONF_FLIPR_ID, DOMAIN
SENSORS = {
"chlorine": {
"unit": "mV",
"unit": ELECTRIC_POTENTIAL_MILLIVOLT,
"icon": "mdi:pool",
"name": "Chlorine",
"device_class": None,
@ -33,7 +34,7 @@ SENSORS = {
"device_class": DEVICE_CLASS_TIMESTAMP,
},
"red_ox": {
"unit": "mV",
"unit": ELECTRIC_POTENTIAL_MILLIVOLT,
"icon": "mdi:pool",
"name": "Red OX",
"device_class": None,