Skip to content

Commit

Permalink
Handle mapquest non-JSON response (error message)
Browse files Browse the repository at this point in the history
  • Loading branch information
rodpayne committed Apr 16, 2024
1 parent 5787124 commit e164304
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 121 deletions.
28 changes: 14 additions & 14 deletions custom_components/person_location/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ async def async_step_sensors(self, user_input=None):
else:
create_sensors_list = user_input[CONF_CREATE_SENSORS]
_LOGGER.debug("create_sensors_list before = %s", create_sensors_list)
create_sensors_list = sorted(list(set(create_sensors_list))) # sort and eliminate duplicates
create_sensors_list = sorted(list(set(create_sensors_list)))
_LOGGER.debug("create_sensors_list after = %s", create_sensors_list)
for sensor_name in create_sensors_list:
if sensor_name not in VALID_CREATE_SENSORS:
Expand All @@ -218,7 +218,7 @@ async def async_step_sensors(self, user_input=None):
create_sensors_list = self.integration_config_data.get(CONF_CREATE_SENSORS, "")
_LOGGER.debug("create_sensors_list = %s", create_sensors_list)
user_input[CONF_CREATE_SENSORS] = ','.join(create_sensors_list)

user_input[CONF_OUTPUT_PLATFORM] = self.integration_config_data.get(
CONF_OUTPUT_PLATFORM, DEFAULT_OUTPUT_PLATFORM
)
Expand Down Expand Up @@ -377,7 +377,7 @@ async def _test_osm_api_key(self, osm_api_key):
try:
if osm_api_key == DEFAULT_API_KEY_NOT_SET:
return True
regex = "^[a-z0-9]+[\._]?[a-z0-9]+[@]\w+[.]\w{2,3}$"
regex = "^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+$"
valid = re.search(regex, osm_api_key)
_LOGGER.debug("osm_api_key test valid = %s", valid)
if valid:
Expand All @@ -403,20 +403,20 @@ def __init__(self, config_entry):
"""Initialize options flow."""

self._errors = {} # error messages for the data entry flow

self._user_input = {} # validated user_input to be saved
self.config_entry = config_entry
self.options = dict(config_entry.options)

async def async_step_init(self, user_input=None): # pylint: disable=unused-argument
"""Handle option flow initiated by the user."""

if user_input is not None:
self.options.update(user_input)
self._user_input.update(user_input)

return await self.async_step_triggers()

return self.async_show_form(
step_id="init",
data_schema=vol.Schema(
Expand Down Expand Up @@ -454,9 +454,9 @@ async def _update_options(self):

async def async_step_triggers(self, user_input=None):
"""Handle the option flow."""

self._errors = {} # error messages for the data entry flow

if user_input is not None:
redisplay = False
# remove entity from self._all_devices if not in user_input[CONF_DEVICES]
Expand All @@ -473,7 +473,7 @@ async def async_step_triggers(self, user_input=None):
# add any new entity to self._all_devices
new_device = user_input[CONF_NEW_DEVICE]
if (new_device != '') or (user_input[CONF_NEW_NAME] != ''):
if (new_device != ''):
if new_device != '':
_LOGGER.debug("new_device = %s", new_device)
new_device_state = self.hass.states.get(new_device)
if new_device_state == None:
Expand All @@ -485,10 +485,10 @@ async def async_step_triggers(self, user_input=None):
_LOGGER.debug("new_device_state.state = %s", new_device_state.state)
self._errors[CONF_NEW_DEVICE] = "new_device_wrong_domain"
valid = False
if (user_input[CONF_NEW_DEVICE] == ''):
if user_input[CONF_NEW_DEVICE] == '':
self._errors[CONF_NEW_DEVICE] = "device_and_name_required"
valid = False
if (user_input[CONF_NEW_NAME] == ''):
if user_input[CONF_NEW_NAME] == '':
self._errors[CONF_NEW_NAME] = "device_and_name_required"
valid = False
if valid: # valid at this point is for CONF_NEW_DEVICE/CONF_NEW_NAME
Expand All @@ -512,8 +512,8 @@ async def async_step_triggers(self, user_input=None):
# location_name = self.hass.config.location_name
# our_currently_configured_entries = self._async_current_entries()
# if our_currently_configured_entries:
# for our_current_entry in our_currently_configured_entries:
# if our_current_entry.title == location_name:
# for our_current_entry in our_currently_configured_entries:
# if our_current_entry.title == location_name:
our_current_entry = self.config_entry
changed = self.hass.config_entries.async_update_entry(
our_current_entry, data={CONF_DEVICES: updated_conf_devices}
Expand Down Expand Up @@ -549,7 +549,7 @@ async def async_step_triggers(self, user_input=None):
): cv.multi_select(self._all_devices),
vol.Optional(
CONF_NEW_DEVICE, default=user_input[CONF_NEW_DEVICE],
# ): cv.entities_domain(VALID_ENTITY_DOMAINS),
# ): cv.entities_domain(VALID_ENTITY_DOMAINS),
): str,
vol.Optional(
CONF_NEW_NAME, default=user_input[CONF_NEW_NAME],
Expand Down
2 changes: 1 addition & 1 deletion custom_components/person_location/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
API_STATE_OBJECT = DOMAIN + "." + DOMAIN + "_integration"
INTEGRATION_NAME = "Person Location"
ISSUE_URL = "https://github.com/rodpayne/home-assistant/issues"
VERSION = "2024.04.08"
VERSION = "2024.04.16"

# Fixed parameters:
MIN_DISTANCE_TRAVELLED_TO_GEOCODE = 5
Expand Down
2 changes: 1 addition & 1 deletion custom_components/person_location/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@
"iot_class": "calculated",
"issue_tracker": "https://github.com/rodpayne/home-assistant_person_location/issues",
"requirements": [],
"version": "2024.04.08"
"version": "2024.04.16"
}
Loading

0 comments on commit e164304

Please sign in to comment.