Mercurial > code > home > repos > homeauto
changeset 576:150aa09c9723
new simple mode that can set the door without rdf
Ignore-this: ff9ab7c6507a7b3fb3252f91b078a318
author | drewp@bigasterisk.com |
---|---|
date | Mon, 06 May 2019 21:07:42 -0700 |
parents | 1209229cd56e |
children | 759bf29d9dbe |
files | service/frontDoorLock/front_door_lock.py service/frontDoorLock/index.html service/frontDoorLock/simple.html |
diffstat | 3 files changed, 81 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/service/frontDoorLock/front_door_lock.py Mon May 06 21:06:08 2019 -0700 +++ b/service/frontDoorLock/front_door_lock.py Mon May 06 21:07:42 2019 -0700 @@ -76,6 +76,16 @@ return log.warn("ignoring %s", stmt) +class SimpleState(cyclone.web.RequestHandler): + def post(self): + state = self.request.body.strip().decode('ascii') + if state == 'unlock': + self.settings.autoLock.onUnlockedStmt() + self.settings.mqtt.publish(espName + b"/switch/strike/command", b'ON') + if state == 'lock': + self.settings.autoLock.onLockedStmt() + self.settings.mqtt.publish(espName + b"/switch/strike/command", b'OFF') + class AutoLock(object): def __init__(self, masterGraph, mqtt): @@ -97,7 +107,7 @@ if lockIn < 0: state = g._graph.value(self.subj, ROOM['state']) log.warn(f"timeUnlocked {self.timeUnlocked}, state {state}, " - "unlockedFor {unlockedFor}, lockIn {lockIn}") + f"unlockedFor {unlockedFor}, lockIn {lockIn}") lockIn = 0 g.patchObject(ctx, self.subj, ROOM['unlockedForSec'], Literal(int(unlockedFor))) @@ -184,11 +194,14 @@ [ (r"/()", cyclone.web.StaticFileHandler, {"path": ".", "default_filename": "index.html"}), + (r"/simple/()", cyclone.web.StaticFileHandler, + {"path": ".", "default_filename": "simple.html"}), (r"/graph", CycloneGraphHandler, {'masterGraph': masterGraph}), (r"/graph/events", CycloneGraphEventsHandler, {'masterGraph': masterGraph}), (r'/output', OutputPage), (r'/bluetoothButton', BluetoothButton), + (r'/simpleState', SimpleState), ], mqtt=mqtt, masterGraph=masterGraph,
--- a/service/frontDoorLock/index.html Mon May 06 21:06:08 2019 -0700 +++ b/service/frontDoorLock/index.html Mon May 06 21:07:42 2019 -0700 @@ -176,6 +176,8 @@ </style> <div class="served-resources"> + <a href=".">root</a> + <a href="simple/">/simple/</a> <a href="stats/">/stats/</a> <a href="graph">/graph</a> <a href="graph/events">/graph/events</a>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/service/frontDoorLock/simple.html Mon May 06 21:07:42 2019 -0700 @@ -0,0 +1,65 @@ +<!doctype html> +<html> + <head> + <title>front door lock simple</title> + <meta charset="utf-8" /> + <meta name="mobile-web-app-capable" content="yes"> + <meta name="viewport" content="width=device-width, initial-scale=1"> + </head> + <body> + + <style> + button { + min-width: 60px; + min-height: 40px; + } + </style> + + <p>Simple door control:</p> + + <button id="lock">Lock now</button> <button id="unlock">Unlock now</button> + + <div id="result"></div> + + <script> + (()=>{ + + const send = (state) => { + const resultReport = document.querySelector('#result'); + resultReport.innerText = 'sending..'; + fetch('../simpleState', { + method: 'POST', + body: state, + headers: new Headers({ + 'Content-type': 'text/plain' + })}).then((resp) => { + resultReport.innerText = `ok=${resp.ok}`; + }); + resultReport.innerText = 'sending....'; + }; + document.querySelector('#lock').addEventListener('click', () => { send('lock'); }); + document.querySelector('#unlock').addEventListener('click', () => { send('unlock'); }); + })(); + </script> + + <style> + .served-resources { + margin-top: 4em; + border-top: 1px solid gray; + padding-top: 1em; + } + .served-resources a { + padding-right: 2em; + } + </style> + + <div class="served-resources"> + <a href="../">root</a> + <a href="../simple">/simple/</a> + <a href="../stats/">/stats/</a> + <a href="../graph">/graph</a> + <a href="../graph/events">/graph/events</a> + <a href="../output">(post) output</a> + </div> + </body> +</html>