Skip to content

Commit

Permalink
Reset password or start bluetooth depending on state on button press
Browse files Browse the repository at this point in the history
Robert Putt authored and Robert Putt committed Jan 8, 2023
1 parent c580b10 commit 0ebb44d
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion gatewayconfig/gatewayconfig_app.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import sentry_sdk
import threading
import requests
from gpiozero import Button, LED

from hm_pyhelper.hardware_definitions import is_rockpi, is_raspberry_pi, \
@@ -102,6 +103,21 @@ def init_sentry(self, sentry_dsn, release, balena_id, balena_app, variant):
def init_nmcli(self):
nmcli_custom.disable_use_sudo()

def check_password_reset(self):
try:
resp = requests.post(
'http://diagnostics/password_reset',
timeout=5
)
password_reset_data = resp.json()
return password_reset_data.get('password_updated')
except Exception:
return False

def button_held(self):
if not self.check_password_reset():
self.start_bluetooth_advertisement()

def init_gpio(self, variant):
"""
This code was originally written for Raspberry Pi but ROCK Pi does not
@@ -120,7 +136,7 @@ def init_gpio(self, variant):
"GPIO not yet supported on this device: %s"
% variant)

self.user_button.when_held = self.start_bluetooth_advertisement
self.user_button.when_held = self.button_held

# Use daemon threads so that everything exists cleanly when the program stops
def start_threads(self):

0 comments on commit 0ebb44d

Please sign in to comment.