mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 09:47:13 +00:00
Address huisbaasje review comments (#48313)
* Address huisbaasje review comments * Update homeassistant/components/huisbaasje/config_flow.py Co-authored-by: Martin Hjelmare <marhje52@gmail.com> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
parent
b4d39d517f
commit
b90c620c5e
@ -141,7 +141,7 @@ def _get_cumulative_value(
|
||||
:param source_type: The source of energy (electricity or gas)
|
||||
:param period_type: The period for which cumulative value should be given.
|
||||
"""
|
||||
if source_type in current_measurements.keys():
|
||||
if source_type in current_measurements:
|
||||
if (
|
||||
period_type in current_measurements[source_type]
|
||||
and current_measurements[source_type][period_type] is not None
|
||||
|
@ -32,9 +32,18 @@ class HuisbaasjeConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
|
||||
try:
|
||||
user_id = await self._validate_input(user_input)
|
||||
|
||||
_LOGGER.info("Input for Huisbaasje is valid!")
|
||||
|
||||
except HuisbaasjeConnectionException as exception:
|
||||
_LOGGER.warning(exception)
|
||||
errors["base"] = "cannot_connect"
|
||||
except HuisbaasjeException as exception:
|
||||
_LOGGER.warning(exception)
|
||||
errors["base"] = "invalid_auth"
|
||||
except AbortFlow:
|
||||
raise
|
||||
except Exception: # pylint: disable=broad-except
|
||||
_LOGGER.exception("Unexpected exception")
|
||||
errors["base"] = "unknown"
|
||||
else:
|
||||
# Set user id as unique id
|
||||
await self.async_set_unique_id(user_id)
|
||||
self._abort_if_unique_id_configured()
|
||||
@ -48,17 +57,6 @@ class HuisbaasjeConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
CONF_PASSWORD: user_input[CONF_PASSWORD],
|
||||
},
|
||||
)
|
||||
except HuisbaasjeConnectionException as exception:
|
||||
_LOGGER.warning(exception)
|
||||
errors["base"] = "connection_exception"
|
||||
except HuisbaasjeException as exception:
|
||||
_LOGGER.warning(exception)
|
||||
errors["base"] = "invalid_auth"
|
||||
except AbortFlow as exception:
|
||||
raise exception
|
||||
except Exception: # pylint: disable=broad-except
|
||||
_LOGGER.exception("Unexpected exception")
|
||||
errors["base"] = "unknown"
|
||||
|
||||
return await self._show_setup_form(user_input, errors)
|
||||
|
||||
@ -72,7 +70,6 @@ class HuisbaasjeConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
|
||||
Data has the keys from DATA_SCHEMA with values provided by the user.
|
||||
"""
|
||||
|
||||
username = user_input[CONF_USERNAME]
|
||||
password = user_input[CONF_PASSWORD]
|
||||
|
||||
|
@ -9,6 +9,7 @@ from huisbaasje.const import (
|
||||
)
|
||||
|
||||
from homeassistant.const import (
|
||||
DEVICE_CLASS_ENERGY,
|
||||
DEVICE_CLASS_POWER,
|
||||
ENERGY_KILO_WATT_HOUR,
|
||||
TIME_HOURS,
|
||||
@ -70,34 +71,34 @@ SENSORS_INFO = [
|
||||
},
|
||||
{
|
||||
"name": "Huisbaasje Energy Today",
|
||||
"device_class": DEVICE_CLASS_ENERGY,
|
||||
"unit_of_measurement": ENERGY_KILO_WATT_HOUR,
|
||||
"source_type": SOURCE_TYPE_ELECTRICITY,
|
||||
"sensor_type": SENSOR_TYPE_THIS_DAY,
|
||||
"icon": "mdi:counter",
|
||||
"precision": 1,
|
||||
},
|
||||
{
|
||||
"name": "Huisbaasje Energy This Week",
|
||||
"device_class": DEVICE_CLASS_ENERGY,
|
||||
"unit_of_measurement": ENERGY_KILO_WATT_HOUR,
|
||||
"source_type": SOURCE_TYPE_ELECTRICITY,
|
||||
"sensor_type": SENSOR_TYPE_THIS_WEEK,
|
||||
"icon": "mdi:counter",
|
||||
"precision": 1,
|
||||
},
|
||||
{
|
||||
"name": "Huisbaasje Energy This Month",
|
||||
"device_class": DEVICE_CLASS_ENERGY,
|
||||
"unit_of_measurement": ENERGY_KILO_WATT_HOUR,
|
||||
"source_type": SOURCE_TYPE_ELECTRICITY,
|
||||
"sensor_type": SENSOR_TYPE_THIS_MONTH,
|
||||
"icon": "mdi:counter",
|
||||
"precision": 1,
|
||||
},
|
||||
{
|
||||
"name": "Huisbaasje Energy This Year",
|
||||
"device_class": DEVICE_CLASS_ENERGY,
|
||||
"unit_of_measurement": ENERGY_KILO_WATT_HOUR,
|
||||
"source_type": SOURCE_TYPE_ELECTRICITY,
|
||||
"sensor_type": SENSOR_TYPE_THIS_YEAR,
|
||||
"icon": "mdi:counter",
|
||||
"precision": 1,
|
||||
},
|
||||
{
|
||||
|
@ -10,8 +10,7 @@
|
||||
},
|
||||
"error": {
|
||||
"invalid_auth": "[%key:common::config_flow::error::invalid_auth%]",
|
||||
"unauthenticated_exception": "[%key:common::config_flow::error::invalid_auth%]",
|
||||
"connection_exception": "[%key:common::config_flow::error::cannot_connect%]",
|
||||
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
|
||||
"unknown": "[%key:common::config_flow::error::unknown%]"
|
||||
},
|
||||
"abort": {
|
||||
|
@ -94,7 +94,7 @@ async def test_form_cannot_connect(hass):
|
||||
)
|
||||
|
||||
assert form_result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||
assert form_result["errors"] == {"base": "connection_exception"}
|
||||
assert form_result["errors"] == {"base": "cannot_connect"}
|
||||
|
||||
|
||||
async def test_form_unknown_error(hass):
|
||||
|
Loading…
x
Reference in New Issue
Block a user