Changes to locative based on tests
parent
55d1ad94ef
commit
bdb6182921
|
@ -40,7 +40,7 @@ def _handle_get_api_locative(hass, see, handler, path_match, data):
|
||||||
return
|
return
|
||||||
|
|
||||||
device = data['device'].replace('-', '')
|
device = data['device'].replace('-', '')
|
||||||
location_name = data['id']
|
location_name = data['id'].lower()
|
||||||
direction = data['trigger']
|
direction = data['trigger']
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -53,9 +53,8 @@ def _handle_get_api_locative(hass, see, handler, path_match, data):
|
||||||
|
|
||||||
if direction == 'enter':
|
if direction == 'enter':
|
||||||
zones = [state for state in hass.states.entity_ids('zone')]
|
zones = [state for state in hass.states.entity_ids('zone')]
|
||||||
_LOGGER.info(zones)
|
|
||||||
|
|
||||||
if "zone.{}".format(location_name.lower()) in zones:
|
if "zone.{}".format(location_name) in zones:
|
||||||
see(dev_id=device, location_name=location_name)
|
see(dev_id=device, location_name=location_name)
|
||||||
handler.write_text(
|
handler.write_text(
|
||||||
"Set new location to {}".format(location_name))
|
"Set new location to {}".format(location_name))
|
||||||
|
@ -68,7 +67,7 @@ def _handle_get_api_locative(hass, see, handler, path_match, data):
|
||||||
current_zone = hass.states.get(
|
current_zone = hass.states.get(
|
||||||
"{}.{}".format("device_tracker", device)).state
|
"{}.{}".format("device_tracker", device)).state
|
||||||
|
|
||||||
if current_zone.lower() == location_name.lower():
|
if current_zone == location_name:
|
||||||
see(dev_id=device, location_name=STATE_NOT_HOME)
|
see(dev_id=device, location_name=STATE_NOT_HOME)
|
||||||
handler.write_text("Set new location to not home")
|
handler.write_text("Set new location to not home")
|
||||||
else:
|
else:
|
||||||
|
@ -77,7 +76,9 @@ def _handle_get_api_locative(hass, see, handler, path_match, data):
|
||||||
# the previous zone was exited. The enter message will be sent
|
# the previous zone was exited. The enter message will be sent
|
||||||
# first, then the exit message will be sent second.
|
# first, then the exit message will be sent second.
|
||||||
handler.write_text(
|
handler.write_text(
|
||||||
"Ignoring transition from {}".format(location_name))
|
'Ignoring exit from "{}". Already in "{}".'.format(
|
||||||
|
location_name,
|
||||||
|
current_zone.split('.')[-1]))
|
||||||
|
|
||||||
elif direction == 'test':
|
elif direction == 'test':
|
||||||
# In the app, a test message can be sent. Just return something to
|
# In the app, a test message can be sent. Just return something to
|
||||||
|
@ -86,7 +87,8 @@ def _handle_get_api_locative(hass, see, handler, path_match, data):
|
||||||
|
|
||||||
else:
|
else:
|
||||||
handler.write_text(
|
handler.write_text(
|
||||||
"Received unidentified message: {}".format(direction))
|
"Received unidentified message: {}".format(direction),
|
||||||
|
HTTP_UNPROCESSABLE_ENTITY)
|
||||||
_LOGGER.error("Received unidentified message from Locative: %s",
|
_LOGGER.error("Received unidentified message from Locative: %s",
|
||||||
direction)
|
direction)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue