diff --git a/custom_components/openei/__init__.py b/custom_components/openei/__init__.py index e2644f9..bf4a279 100644 --- a/custom_components/openei/__init__.py +++ b/custom_components/openei/__init__.py @@ -50,9 +50,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry): updated_config[CONF_PLAN] = updated_config[CONF_MANUAL_PLAN] updated_config.pop(CONF_MANUAL_PLAN, None) - if CONF_LOCATION in updated_config.keys() and updated_config[CONF_LOCATION] == "": - updated_config.pop(CONF_LOCATION, None) - _LOGGER.debug("updated_config: %s", updated_config) if updated_config != entry.data: hass.config_entries.async_update_entry(entry, data=updated_config) diff --git a/custom_components/openei/config_flow.py b/custom_components/openei/config_flow.py index fef6884..784f9fb 100644 --- a/custom_components/openei/config_flow.py +++ b/custom_components/openei/config_flow.py @@ -7,7 +7,6 @@ from homeassistant import config_entries from homeassistant.components.sensor import DOMAIN as SENSORS_DOMAIN from homeassistant.core import HomeAssistant, callback -from homeassistant.helpers import config_validation as cv import openeihttp import voluptuous as vol @@ -41,7 +40,6 @@ async def async_step_user(self, user_input=None): self._errors = {} if user_input is not None: - _LOGGER.debug("Step 1: %s", user_input) self._data.update(user_input) return await self.async_step_user_2() @@ -122,8 +120,9 @@ async def async_step_init(self, user_input=None): # pylint: disable=unused-argu async def async_step_user(self, user_input=None): """Handle a flow initialized by the user.""" if user_input is not None: + if user_input[CONF_LOCATION] == '""': + user_input[CONF_LOCATION] = "" self._data.update(user_input) - _LOGGER.debug("Step 1: %s", user_input) return await self.async_step_user_2() return await self._show_config_form(user_input) @@ -133,7 +132,6 @@ async def async_step_user_2(self, user_input=None): _LOGGER.debug("data: %s", self._data) if user_input is not None: self._data.update(user_input) - _LOGGER.debug("Step 2: %s", user_input) return await self.async_step_user_3() return await self._show_config_form_2(user_input) @@ -143,7 +141,6 @@ async def async_step_user_3(self, user_input=None): _LOGGER.debug("data: %s", self._data) if user_input is not None: self._data.update(user_input) - _LOGGER.debug("Step 3: %s", user_input) return self.async_create_entry(title="", data=self._data) return await self._show_config_form_3(user_input) @@ -273,7 +270,7 @@ async def _get_utility_list(hass, user_input) -> list | None: address = user_input[CONF_LOCATION] radius = user_input[CONF_RADIUS] - if not bool(user_input[CONF_LOCATION]): + if not bool(address): lat = hass.config.latitude lon = hass.config.longitude address = None @@ -299,7 +296,7 @@ async def _get_plan_list(hass, user_input) -> list | None: radius = user_input[CONF_RADIUS] utility = user_input[CONF_UTILITY] - if not bool(user_input[CONF_LOCATION]): + if not bool(address): lat = hass.config.latitude lon = hass.config.longitude address = None diff --git a/tests/test_config_flow.py b/tests/test_config_flow.py index 0ad3a4c..2ee0872 100644 --- a/tests/test_config_flow.py +++ b/tests/test_config_flow.py @@ -58,7 +58,7 @@ async def test_form( ) assert result["type"] == "form" assert result["errors"] == {} - # assert result["title"] == title_1 + # assert result['title'] == title_1 with patch( "custom_components.openei.async_setup", return_value=True @@ -168,7 +168,7 @@ async def test_options_flow( assert result["type"] == "form" assert result["errors"] == {} - # assert result["title"] == title_1 + # assert result['title'] == title_1 with patch("custom_components.openei.async_setup", return_value=True), patch( "custom_components.openei.async_setup_entry", @@ -277,7 +277,7 @@ async def test_options_flow_no_changes( assert result["type"] == "form" assert result["errors"] == {} - # assert result["title"] == title_1 + # assert result['title'] == title_1 with patch("custom_components.openei.async_setup", return_value=True), patch( "custom_components.openei.async_setup_entry", @@ -324,7 +324,7 @@ async def test_options_flow_no_changes( { "api_key": "fakeAPIKey", "radius": 0, - "location": "''", + "location": '""', }, "user_2", { @@ -343,7 +343,7 @@ async def test_options_flow_no_changes( "utility": "Fake Utility Co", "rate_plan": "randomstring", "sensor": "(none)", - "location": "''", + "location": "", "manual_plan": "", }, ), @@ -386,7 +386,7 @@ async def test_options_flow_some_changes( assert result["type"] == "form" assert result["errors"] == {} - # assert result["title"] == title_1 + # assert result['title'] == title_1 with patch("custom_components.openei.async_setup", return_value=True), patch( "custom_components.openei.async_setup_entry",