def lights():
"""
example_lights_json = {
'rooms': [
{'name': 'Living Room', 'on': True},
]
}
"""
if is_local_request(flask.request):
json = flask.request.get_json()
rooms = json.get('rooms', [])
logger.info('Switching rooms %s', rooms)
for json_room in rooms:
room_name = json_room['name']
on_state = json_room['on']
for room in ROOMS:
# Strip whitespace
if room.name == room_name:
logger.info('Switching room %s', room.name)
room.switch(on_state)
return "Light commands sent."
else:
logger.info('Lights accessed by remote address %s', flask.request.environ['REMOTE_ADDR'])
flask.abort(404)
评论列表
文章目录