diff --git a/kdoorpi.py b/kdoorpi.py index 496bd03..22eb730 100644 --- a/kdoorpi.py +++ b/kdoorpi.py @@ -69,14 +69,13 @@ class DoorController: def wiegand_callback(self, bits, value): uid_h = hash_uid(value, self.uid_hash) - logging.debug("hash %s", uid_h) + logging.debug(f"hash {uid_h}") if uid_h in self.uids: - logging.info("Opening door for UID hash trail %s", uid_h[-10:]) + logging.info(f"Opening door for UID hash trail {uid_h[-10:]}") self.wiegand.open_door() success = True else: - logging.info("Access card not in allow list, hash trail %s", - uid_h[-10:]) + logging.info(f"Access card not in allow list, hash trail {uid_h[-10:]}") success = False data = { "uid": value, @@ -127,9 +126,10 @@ class DoorController: if __name__ == "__main__": DoorController( - os.environ["KDOORPI_DOOR"], - os.environ["KDOORPI_API_ALLOWED"], - os.environ["KDOORPI_API_LONGPOLL"], - os.environ["KDOORPI_API_SWIPE"], - os.environ["KDOORPI_API_KEY"], - os.environ["KDOORPI_UID_SALT"]) + door=os.environ["KDOORPI_DOOR"], + api_allowed=os.environ["KDOORPI_API_ALLOWED"], + api_longpoll=os.environ["KDOORPI_API_LONGPOLL"], + api_swipe=os.environ["KDOORPI_API_SWIPE"], + api_key=os.environ["KDOORPI_API_KEY"], + uid_hash=os.environ["KDOORPI_UID_SALT"], + ) diff --git a/wiegand.py b/wiegand.py index 7d4782e..d8e0073 100644 --- a/wiegand.py +++ b/wiegand.py @@ -79,12 +79,11 @@ class Decoder: bits))).rstrip() except ValueError: - logging.error("Failed to convert binary to hex: %s" % self.items) + logging.error(f"Failed to convert binary to hex: {self.items}") return False except Exception as e: - logging.error("Wiegand convert error (raw: %s): %s" % ( - self.items, e)) + logging.error(f"Wiegand convert error (raw: {self.items}): {e}") return False def _cb(self, gpio_pin, level, tick): @@ -99,7 +98,7 @@ class Decoder: if self.in_code: self.bits += 1 else: - logging.debug("Wiegand data transfer start") + logging.debug(f"Wiegand data transfer start") self.bits = 1 self.items = "" self.in_code = True @@ -133,16 +132,13 @@ class Decoder: if hex: self.callback(self.bits, hex) else: - logging.error("Expected 26 bits, but got %i: %s" % - (self.bits, self.items)) + logging.error(f"Expected 26 bits, but got {self.bits:d}: {self.items}") except Exception as e: - logging.error("Wiegand callback error: %s" % e) + logging.error(f"Wiegand callback error: {e}") def button_cb(self, gpio_pin, level, tick): - print("button: gpio_pin:{}, level:{}, tick:{}".format(gpio_pin, - level, - tick)) + print(f"button: gpio_pin:{gpio_pin}, level:{level}, tick:{tick}") def open_door(self): self.pi.write(self.door_pin, 1)