Merge branch 'setuptools'

This commit is contained in:
Lynn Ochs 2021-08-11 07:37:17 +02:00
commit 43e7129a11
3 changed files with 59 additions and 35 deletions

View File

@ -1,8 +1,13 @@
#!/usr/bin/python
import os, serial, socket, select, datetime
import paho.mqtt.client as mqcl
import argparse
import datetime
import logging
import os
import select
import socket
import paho.mqtt.client as mqcl
import serial
UPDATE_RATE = 2
MAX_UPDATE_RATE = 20
@ -12,19 +17,6 @@ OPEN_THRESHOLD = 190
CLOSED_THRESHOLD = 160
CLOSED_WANT = 40
parser = argparse.ArgumentParser()
parser.add_argument("--serial_port", default="/dev/serial/by-id/usb-Imaginaerraum.de_DoorControl_43363220195053573A002C0-if01")
parser.add_argument("--nfc_fifo", default="/tmp/nfc_fifo")
parser.add_argument("--control_socket", default="/tmp/nfc.sock")
parser.add_argument("--valid_tokens", default="/etc/door_tokens")
parser.add_argument("--log_file", default="/tmp/nfc.log")
parser.add_argument("--state_timeout", type=float, default=10)
parser.add_argument("--state_timeout_speed", type=float, default=3)
parser.add_argument("--repeat_time", type=float, default=5)
parser.add_argument("--mqtt_host", default="10.10.21.2")
config = parser.parse_args()
def timestamp():
return datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
@ -433,26 +425,42 @@ class DoorControl:
DoorControl.action_names[self.action()],
(datetime.datetime.now() - self.start_time).total_seconds()))
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--serial_port", default="/dev/serial/by-id/usb-Imaginaerraum.de_DoorControl_43363220195053573A002C0-if01")
parser.add_argument("--nfc_fifo", default="/tmp/nfc_fifo")
parser.add_argument("--control_socket", default="/tmp/nfc.sock")
parser.add_argument("--valid_tokens", default="/etc/door_tokens")
parser.add_argument("--log_file", default="/tmp/nfc.log")
parser.add_argument("--state_timeout", type=float, default=10)
parser.add_argument("--state_timeout_speed", type=float, default=3)
parser.add_argument("--repeat_time", type=float, default=5)
parser.add_argument("--mqtt_host", default="10.10.21.2")
config = parser.parse_args()
dc = DoorControl(config)
dc = DoorControl(config)
buffers = {}
while True:
readable = select.select([ dc.serial_port.fileno(), dc.nfc_fifo, dc.control_socket ] + dc.comm_channels, [], [], 1 / UPDATE_RATE)[0]
buffers = {}
while True:
readable = select.select([ dc.serial_port.fileno(), dc.nfc_fifo, dc.control_socket ] + dc.comm_channels, [], [], 1 / UPDATE_RATE)[0]
for c in readable:
if c == dc.serial_port.fileno():
dc.handle_door_line()
elif c == dc.nfc_fifo:
dc.handle_nfc_token()
elif c == dc.control_socket:
dc.logger.info("Got connection")
sock = dc.control_socket.accept()[0]
buffers[sock] = dc.LineBuffer(sock, dc.handle_cmd)
dc.comm_channels += [sock]
else:
if not buffers[c].update():
dc.logger.info("Lost connection")
del buffers[c]
dc.comm_channels.remove(c)
dc.handle_door_state()
for c in readable:
if c == dc.serial_port.fileno():
dc.handle_door_line()
elif c == dc.nfc_fifo:
dc.handle_nfc_token()
elif c == dc.control_socket:
dc.logger.info("Got connection")
sock = dc.control_socket.accept()[0]
buffers[sock] = dc.LineBuffer(sock, dc.handle_cmd)
dc.comm_channels += [sock]
else:
if not buffers[c].update():
dc.logger.info("Lost connection")
del buffers[c]
dc.comm_channels.remove(c)
dc.handle_door_state()
if __name__ == '__main__':
main()

3
pyproject.toml Normal file
View File

@ -0,0 +1,3 @@
[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"

13
setup.cfg Normal file
View File

@ -0,0 +1,13 @@
[metadata]
name = door_pi_control
version = 0.0.1
[options]
packages = door_pi_control
install_requires =
paho-mqtt
serial
[options.entry_points]
console_scripts =
door.py = door_pi_control:main