Open Switch thread skeleton

This commit is contained in:
Ondrej Mikle 2017-10-27 20:15:06 +02:00
parent fdc3007904
commit 388d8a80b0
2 changed files with 28 additions and 0 deletions

View file

@ -41,3 +41,11 @@ password = whatevs
channels = #test-bjornbot channels = #test-bjornbot
tls = True tls = True
reconnect_delay = 300 reconnect_delay = 300
[open-switch]
# Controls showing status of "OPEN/CLOSE" switch that is connected to some GPIO pin
# Changes topic of connected IRC channels if IRC is enabled
# enabled - True/False
# status_file - file in sysfs that contains 1 or 0 defining the state of button
enabled = True
status_file = /sys/class/gpio/gpio11/value

View file

@ -59,6 +59,9 @@ class BrmdoorConfig(object):
self.ircChannels = self.config.get("irc", "channels").split(" ") self.ircChannels = self.config.get("irc", "channels").split(" ")
self.ircUseTLS = self.config.getboolean("irc", "tls") self.ircUseTLS = self.config.getboolean("irc", "tls")
self.ircReconnectDelay = self.config.getint("irc", "reconnect_delay") self.ircReconnectDelay = self.config.getint("irc", "reconnect_delay")
self.useOpenSwitch = self.config.getboolean("open-switch", "enabled")
if self.useOpenSwitch:
self.switchStatusFile = self.config.get("open-switch", "status_file")
def convertLoglevel(self, levelString): def convertLoglevel(self, levelString):
"""Converts string 'debug', 'info', etc. into corresponding """Converts string 'debug', 'info', etc. into corresponding
@ -256,6 +259,23 @@ class IrcThread(threading.Thread):
else: else:
time.sleep(self.reconnectDelay) time.sleep(self.reconnectDelay)
class OpenSwitchThread(threading.Thread):
"""
Class for watching OPEN/CLOSED switch that
"""
def __init__(self, config, ircThread):
"""
Create thread for IRC connection.
:param config - BrmdoorConfig object
:param ircThread: IrcThread through which we can set and receive current topics
"""
self.statusFile = config.statusFile
threading.Thread.__init__(self)
def run(self):
while True:
time.sleep(1)
if __name__ == "__main__": if __name__ == "__main__":