Mercurial > code > home > repos > homeauto
changeset 1683:437d7263b515
checkpoint service/frontDoorLock
author | drewp@bigasterisk.com |
---|---|
date | Mon, 27 Sep 2021 23:13:49 -0700 |
parents | d6996175ea78 |
children | c41af73a410f |
files | service/frontDoorLock/Dockerfile service/frontDoorLock/door.yaml service/frontDoorLock/front_door_lock.py service/frontDoorLock/tasks.py |
diffstat | 4 files changed, 21 insertions(+), 44 deletions(-) [+] |
line wrap: on
line diff
--- a/service/frontDoorLock/Dockerfile Mon Sep 27 23:05:30 2021 -0700 +++ b/service/frontDoorLock/Dockerfile Mon Sep 27 23:13:49 2021 -0700 @@ -1,4 +1,4 @@ -FROM bang6:5000/base_x86 +FROM bang5:5000/base_x86 WORKDIR /opt @@ -6,6 +6,7 @@ RUN pip3 install --index-url https://projects.bigasterisk.com/ --extra-index-url https://pypi.org/simple -r requirements.txt # not sure why this doesn't work from inside requirements.txt RUN pip3 install -U 'https://github.com/drewp/cyclone/archive/python3.zip?v3' +RUN pip3 install -U attrs COPY *.py *.html *.css *.js ./
--- a/service/frontDoorLock/door.yaml Mon Sep 27 23:05:30 2021 -0700 +++ b/service/frontDoorLock/door.yaml Mon Sep 27 23:13:49 2021 -0700 @@ -11,8 +11,8 @@ name: "strike" wifi: - ssid: '' - password: '' + ssid: !secret wifi_ssid + password: !secret wifi_password mqtt: broker: '10.2.0.1'
--- a/service/frontDoorLock/front_door_lock.py Mon Sep 27 23:05:30 2021 -0700 +++ b/service/frontDoorLock/front_door_lock.py Mon Sep 27 23:13:49 2021 -0700 @@ -1,4 +1,11 @@ """ +currently: +- serves simple.html +- listens for simple POST requests +- syncs mqtt frontdoorlock/switch/strike/state into an rdf graph +- listens for PUT /output with a request for :frontDoorLock :state :unlocked + +------ this service is generalized by mqtt_graph_bridge and rdf_from_mqtt, so delete when those are stable :frontDoorLock :state :locked/:unlocked @@ -52,8 +59,8 @@ def put(self): try: user = requestUser(self.request) - except KeyError: - log.warn('request without x-foaf-agent: %s', h) + except KeyError as e: + log.warn('request without x-foaf-agent: %r', e) self.set_status(403, 'need x-foaf-agent') return arg = self.request.arguments @@ -87,7 +94,7 @@ try: user = requestUser(self.request) except KeyError: - log.warn('request without x-foaf-agent: %s', h) + log.warn('request without x-foaf-agent: %s', self.request.headers) self.set_status(403, 'need x-foaf-agent') return @@ -170,7 +177,7 @@ def post(self): body = json.loads(self.request.body) log.info('POST bluetoothButton %r', body) - if body['addr'] == 'zz:zz:zz:zz:zz:zz' and body['key'] == 'top': + if body['addr'] == 'B8:27:EB:95:BE:1C' and body['key'] == 'top': log.info('unlock for %r', body['addr']) self.settings.mqtt.publish( espName + b"/switch/strike/command", b'ON')
--- a/service/frontDoorLock/tasks.py Mon Sep 27 23:05:30 2021 -0700 +++ b/service/frontDoorLock/tasks.py Mon Sep 27 23:13:49 2021 -0700 @@ -1,32 +1,11 @@ -from invoke import task - -JOB = 'front_door_lock' -PORT = 10011 -TAG = f'bang6:5000/{JOB}_x86:latest' -ANSIBLE_TAG = 'door' - -@task -def build_image(ctx): - ctx.run(f'docker build --network=host -t {TAG} .') - -@task(pre=[build_image]) -def push_image(ctx): - ctx.run(f'docker push {TAG}') +from invoke import Collection, task -@task(pre=[build_image]) -def shell(ctx): - ctx.run(f'docker run --name={JOB}_shell --rm -it --cap-add SYS_PTRACE --net=host ' - f' -v `pwd`/../../stubs:/opt/stubs' - f' {TAG} /bin/bash', pty=True) +import sys +sys.path.append('/my/proj/release') +from serv_tasks import serv_tasks -@task(pre=[build_image]) -def local_run(ctx): - ctx.run(f'docker run --name={JOB}_local --rm -it --net=host -v `pwd`/index.html:/opt/index.html {TAG} python3 ./front_door_lock.py -v', pty=True) - -@task(pre=[push_image]) -def redeploy(ctx): - ctx.run(f'sudo /my/proj/ansible/playbook -l bang -t {ANSIBLE_TAG}') - ctx.run(f'supervisorctl -s http://bang:9001/ restart {JOB}_{PORT}') +ns = Collection() +serv_tasks(ns, 'serv.n3', 'front_door_lock') @task def program_board_over_usb(ctx): @@ -51,13 +30,3 @@ def mqtt_force_lock(ctx): ctx.run(f'mosquitto_pub -h bang -p 10210 -t frontdoorlock/switch/strike/command -m OFF') - -@task(pre=[build_image]) -def mypy(ctx): - ctx.run(f'docker run --rm -it --name={JOB}_mypy --net=host' - f' -v `pwd`/.mypy_cache:/opt/.mypy_cache' - f' -v `pwd`/../../stubs:/opt/stubs' - f' -e MYPYPATH=/opt/stubs' - f' {TAG}' - f' /usr/local/bin/mypy -m front_door_lock', pty=True) -