mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Add voluptuous to locative (#3254)
This commit is contained in:
parent
515c4773f3
commit
dba78b02da
@ -6,9 +6,11 @@ https://home-assistant.io/components/device_tracker.locative/
|
|||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from homeassistant.components.device_tracker import DOMAIN
|
|
||||||
from homeassistant.const import HTTP_UNPROCESSABLE_ENTITY, STATE_NOT_HOME
|
from homeassistant.const import HTTP_UNPROCESSABLE_ENTITY, STATE_NOT_HOME
|
||||||
from homeassistant.components.http import HomeAssistantView
|
from homeassistant.components.http import HomeAssistantView
|
||||||
|
# pylint: disable=unused-import
|
||||||
|
from homeassistant.components.device_tracker import ( # NOQA
|
||||||
|
DOMAIN, PLATFORM_SCHEMA)
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -25,8 +27,8 @@ def setup_scanner(hass, config, see):
|
|||||||
class LocativeView(HomeAssistantView):
|
class LocativeView(HomeAssistantView):
|
||||||
"""View to handle locative requests."""
|
"""View to handle locative requests."""
|
||||||
|
|
||||||
url = "/api/locative"
|
url = '/api/locative'
|
||||||
name = "api:locative"
|
name = 'api:locative'
|
||||||
|
|
||||||
def __init__(self, hass, see):
|
def __init__(self, hass, see):
|
||||||
"""Initialize Locative url endpoints."""
|
"""Initialize Locative url endpoints."""
|
||||||
@ -43,22 +45,22 @@ class LocativeView(HomeAssistantView):
|
|||||||
data = request.values
|
data = request.values
|
||||||
|
|
||||||
if 'latitude' not in data or 'longitude' not in data:
|
if 'latitude' not in data or 'longitude' not in data:
|
||||||
return ("Latitude and longitude not specified.",
|
return ('Latitude and longitude not specified.',
|
||||||
HTTP_UNPROCESSABLE_ENTITY)
|
HTTP_UNPROCESSABLE_ENTITY)
|
||||||
|
|
||||||
if 'device' not in data:
|
if 'device' not in data:
|
||||||
_LOGGER.error("Device id not specified.")
|
_LOGGER.error('Device id not specified.')
|
||||||
return ("Device id not specified.",
|
return ('Device id not specified.',
|
||||||
HTTP_UNPROCESSABLE_ENTITY)
|
HTTP_UNPROCESSABLE_ENTITY)
|
||||||
|
|
||||||
if 'id' not in data:
|
if 'id' not in data:
|
||||||
_LOGGER.error("Location id not specified.")
|
_LOGGER.error('Location id not specified.')
|
||||||
return ("Location id not specified.",
|
return ('Location id not specified.',
|
||||||
HTTP_UNPROCESSABLE_ENTITY)
|
HTTP_UNPROCESSABLE_ENTITY)
|
||||||
|
|
||||||
if 'trigger' not in data:
|
if 'trigger' not in data:
|
||||||
_LOGGER.error("Trigger is not specified.")
|
_LOGGER.error('Trigger is not specified.')
|
||||||
return ("Trigger is not specified.",
|
return ('Trigger is not specified.',
|
||||||
HTTP_UNPROCESSABLE_ENTITY)
|
HTTP_UNPROCESSABLE_ENTITY)
|
||||||
|
|
||||||
device = data['device'].replace('-', '')
|
device = data['device'].replace('-', '')
|
||||||
@ -67,15 +69,15 @@ class LocativeView(HomeAssistantView):
|
|||||||
|
|
||||||
if direction == 'enter':
|
if direction == 'enter':
|
||||||
self.see(dev_id=device, location_name=location_name)
|
self.see(dev_id=device, location_name=location_name)
|
||||||
return "Setting location to {}".format(location_name)
|
return 'Setting location to {}'.format(location_name)
|
||||||
|
|
||||||
elif direction == 'exit':
|
elif direction == 'exit':
|
||||||
current_state = self.hass.states.get(
|
current_state = self.hass.states.get(
|
||||||
"{}.{}".format(DOMAIN, device))
|
'{}.{}'.format(DOMAIN, device))
|
||||||
|
|
||||||
if current_state is None or current_state.state == location_name:
|
if current_state is None or current_state.state == location_name:
|
||||||
self.see(dev_id=device, location_name=STATE_NOT_HOME)
|
self.see(dev_id=device, location_name=STATE_NOT_HOME)
|
||||||
return "Setting location to not home"
|
return '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
|
# aren't currently in. This occurs when a zone is entered
|
||||||
@ -87,10 +89,10 @@ class LocativeView(HomeAssistantView):
|
|||||||
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
|
||||||
# the user to let them know that it works.
|
# the user to let them know that it works.
|
||||||
return "Received test message."
|
return 'Received test message.'
|
||||||
|
|
||||||
else:
|
else:
|
||||||
_LOGGER.error("Received unidentified message from Locative: %s",
|
_LOGGER.error('Received unidentified message from Locative: %s',
|
||||||
direction)
|
direction)
|
||||||
return ("Received unidentified message: {}".format(direction),
|
return ('Received unidentified message: {}'.format(direction),
|
||||||
HTTP_UNPROCESSABLE_ENTITY)
|
HTTP_UNPROCESSABLE_ENTITY)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user