mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
Remove unnecessary error checking
This commit is contained in:
parent
1bcca8cba1
commit
5d953061e8
@ -10,7 +10,7 @@ import logging
|
|||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
HTTP_UNPROCESSABLE_ENTITY, HTTP_INTERNAL_SERVER_ERROR, STATE_NOT_HOME)
|
HTTP_UNPROCESSABLE_ENTITY, STATE_NOT_HOME)
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -57,11 +57,11 @@ def _handle_get_api_locative(hass, see, handler, path_match, data):
|
|||||||
if "zone.{}".format(location_name) 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))
|
"Setting location to {}".format(location_name))
|
||||||
else:
|
else:
|
||||||
see(dev_id=device, gps=gps_coords)
|
see(dev_id=device, gps=gps_coords)
|
||||||
handler.write_text(
|
handler.write_text(
|
||||||
"Set new location to {}".format(gps_coords))
|
"Setting location to {}".format(gps_coords))
|
||||||
|
|
||||||
elif direction == 'exit':
|
elif direction == 'exit':
|
||||||
current_zone = hass.states.get(
|
current_zone = hass.states.get(
|
||||||
@ -69,14 +69,14 @@ def _handle_get_api_locative(hass, see, handler, path_match, data):
|
|||||||
|
|
||||||
if current_zone == location_name:
|
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("Setting location to not home")
|
||||||
else:
|
else:
|
||||||
# Ignore the message if it is telling us to exit a zone that we
|
# Ignore the message if it is telling us to exit a zone that we
|
||||||
# aren't currently in. This occurs when a zone is entered before
|
# aren't currently in. This occurs when a zone is entered before
|
||||||
# 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 exit from "{}". Already in "{}".'.format(
|
'Ignoring exit from {} (already in {})'.format(
|
||||||
location_name,
|
location_name,
|
||||||
current_zone.split('.')[-1]))
|
current_zone.split('.')[-1]))
|
||||||
|
|
||||||
@ -94,13 +94,6 @@ def _handle_get_api_locative(hass, see, handler, path_match, data):
|
|||||||
|
|
||||||
|
|
||||||
def _check_data(handler, data):
|
def _check_data(handler, data):
|
||||||
if not isinstance(data, dict):
|
|
||||||
handler.write_text("Error while parsing Locative message.",
|
|
||||||
HTTP_INTERNAL_SERVER_ERROR)
|
|
||||||
_LOGGER.error("Error while parsing Locative message: "
|
|
||||||
"data is not a dict.")
|
|
||||||
return False
|
|
||||||
|
|
||||||
if 'latitude' not in data or 'longitude' not in data:
|
if 'latitude' not in data or 'longitude' not in data:
|
||||||
handler.write_text("Latitude and longitude not specified.",
|
handler.write_text("Latitude and longitude not specified.",
|
||||||
HTTP_UNPROCESSABLE_ENTITY)
|
HTTP_UNPROCESSABLE_ENTITY)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user