import spiff
from bonehead import Plugin
from bonehead.ui import Page
from PyQt4 import QtCore, QtGui, QtWebKit, QtNetwork

class OpenClosePlugin(Plugin):
    def newPage(self, name, args, ui):
        api = spiff.API(args['url'], verify=False)
        return OpenClosePage(api.sensor(args['sensor-id']), ui)

class OpenClosePage(Page):
    def __init__(self, sensor, parent=None):
        super(OpenClosePage, self).__init__('Open/Close Space', parent)
        self.__sensor = sensor
        self.setStyleSheet("*{font-size:32pt}")
        self.layout = QtGui.QVBoxLayout(self)
        self.button = QtGui.QPushButton(self)
        self.text = QtGui.QLabel(self)
        self.text.setAlignment(QtCore.Qt.AlignHCenter)
        self.layout.addWidget(self.text)
        self.layout.addWidget(self.button)
        self.button.clicked.connect(self.toggle)
        self.updateButton()

    def toggle(self):
        if self.__sensor.value == True:
            self.__sensor.setValue(False)
        else:
            self.__sensor.setValue(True)
        self.updateButton()

    def updateButton(self):
        if self.__sensor.value == True:
            self.button.setStyleSheet("*{background-color: #f00;}")
            self.button.setText("Close Space")
            self.text.setText("Space is OPEN")
        else:
            self.button.setStyleSheet("*{background-color: #0f0;}")
            self.button.setText("Open Space")
            self.text.setText("Space is CLOSED")


@@ -115,16 +115,33 @@
 tNetwork
+%0Aimport threading
 %0A%0Aclass 
@@ -899,17 +899,21 @@
     def 
-t
+_runT
 oggle(se
@@ -949,32 +949,82 @@
 .value == True:%0A
+            self.text.setText(%22Closing space...%22)%0A
             self
@@ -1084,57 +1084,201 @@
 elf.
-__sensor.setValue(True)%0A        self.updateButton
+text.setText(%22Opening space...%22)%0A            self.__sensor.setValue(True)%0A        self.updateButton()%0A%0A    def toggle(self):%0A        t = threading.Thread(target=self._runToggle)%0A        t.start
 ()%0A%0A

Make the open/close button async