mirror of
https://github.com/brmlab/brmdoor_libnfc.git
synced 2025-06-08 00:24:00 +02:00
Upload open/close status on startup and status change
This commit is contained in:
parent
8fd2b47638
commit
43e5ecaab8
1 changed files with 13 additions and 4 deletions
|
@ -413,12 +413,10 @@ class OpenSwitchThread(threading.Thread):
|
||||||
self.statusFile = config.switchStatusFile
|
self.statusFile = config.switchStatusFile
|
||||||
self.openValue = config.switchOpenValue
|
self.openValue = config.switchOpenValue
|
||||||
self.ircThread = ircThread
|
self.ircThread = ircThread
|
||||||
|
self.config = config
|
||||||
threading.Thread.__init__(self)
|
threading.Thread.__init__(self)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
logging.info("Switch thread start")
|
|
||||||
if self.ircThread is None: #no point in running this thread if we can't report it anywhere
|
|
||||||
return
|
|
||||||
|
|
||||||
lastStatus = None #Some random value so that first time it will be registered as change
|
lastStatus = None #Some random value so that first time it will be registered as change
|
||||||
while True:
|
while True:
|
||||||
|
@ -433,7 +431,18 @@ class OpenSwitchThread(threading.Thread):
|
||||||
else:
|
else:
|
||||||
strStatus = "CLOSED |"
|
strStatus = "CLOSED |"
|
||||||
|
|
||||||
if self.ircThread.connected:
|
try:
|
||||||
|
#this will upload status always upon brmdoor start, which is better than waiting until someone
|
||||||
|
#changes status with button
|
||||||
|
if self.config.useStatusUpload:
|
||||||
|
uploader = SpaceAPIUploader(self.config)
|
||||||
|
uploader.upload(status == self.openValue)
|
||||||
|
except Exception:
|
||||||
|
#we could use retrying with @retry decorator, but it's likely that it wouldn't help with
|
||||||
|
#current connection/upload/out of disk space or similar problem
|
||||||
|
logging.exception("Failed to upload spaceAPI status JSON")
|
||||||
|
|
||||||
|
if self.ircThread is not None and self.ircThread.connected:
|
||||||
for channel in self.ircThread.channels:
|
for channel in self.ircThread.channels:
|
||||||
logging.info("Request topic for channel %s with intention to change it, prefix %s",
|
logging.info("Request topic for channel %s with intention to change it, prefix %s",
|
||||||
channel, strStatus)
|
channel, strStatus)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue