def doHandleEvent( self, handler, inEvent ):

        #self._log.debug('inEvent handled %s with %s' % (inEvent.getType(), inEvent.getSource()))  #Noisy logging
    
        if inEvent.getType() == 'http://id.webbrick.co.uk/events/config/get':
            self.doHandleConfig( inEvent )
            return makeDeferred(StatusVal.OK)            

        elif inEvent.getType() == "http://id.webbrick.co.uk/events/time/minute":
            now = int(inEvent.getPayload()['minute'])
            self.Evaluate_Conditions('minute')
            return makeDeferred(StatusVal.OK)
 
        elif self._run_event and inEvent.getType() == self._run_event['type'] and inEvent.getSource() == self._run_event['source']:
            self._target = float(inEvent.getPayload()['targetsetpoint'])
            self.Evaluate_Conditions('new target setpoint')
            return makeDeferred(StatusVal.OK)
 
        elif self._air_event and inEvent.getType() == self._air_event['type'] and inEvent.getSource() == self._air_event['source']:
            self._air_temperature = float(inEvent.getPayload()['val'])
            self.Evaluate_Conditions('air_temperature')
            return makeDeferred(StatusVal.OK)    

        elif self._floor_event and inEvent.getType() == self._floor_event['type'] and inEvent.getSource() == self._floor_event['source']:
            self._floor_temperature = float(inEvent.getPayload()['val'])
            self.Evaluate_Conditions('floor_temperature')
            return makeDeferred(StatusVal.OK)    

        return super(UnderFloorHeating,self).doHandleEvent( handler, inEvent)
    def doHandleEvent( self, handler, inEvent ):
        if inEvent.getType() == "http://id.webbrick.co.uk/events/time/runtime" :
            if int(inEvent.getPayload()["elapsed"]) == 5:
                _log.debug( 'caught runtime event' )
                self.makeManifest()

        return makeDeferred(StatusVal.OK)
def eventHandlerBlocking(h,e):
    Trace("%s eventHandlerBlocking %s"%(h,str(e)), "EventLib.TestEventRouterThreaded")
    time.sleep(1.0)
    h.evcount += 1
    h.event    = e
    Trace("%s eventHandlerBlocking - return"%(h), "EventLib.TestEventRouterThreaded")
    return makeDeferred(StatusVal.OK)
def eventHandlerIncoming(h, e):
    h.evcount += 1
    h.event = e
    if h.event.getType() == "to/router/original":
        rootlogger.warn("== Received an incoming event, event number: %s ==", router.getCount())

        # Increment the counter for the incoming events. Sleep so that we don't have a continuous loop of events.
        router.inC()
        time.sleep(0.5)

        # Make and publish an event back to Router2Console
        eventType = "to/router/2"
        eventSource = "source/router1"
        router1EventAgentOutgoing = makeEventAgent(uri="router1EventAgentOutgoing")
        router1EventHandlerOutgoing = makeEventHandler(
            uri="router1EventAgentOutgoing",
            handler=eventHandlerOutgoing,
            initSubscription=subHandlerOutgoing,
            endSubscription=unsubHandlerOutgoing,
        )
        router1EventHandlerOutgoing.subcount = 0
        router1EventHandlerOutgoing.evcount = 0

        event = makeEvent(evtype=eventType, source=eventSource, payload=router.getCount())

        rootlogger.warn("== Sending out event, number: %s ==", router.getCount())
        status2 = router.getR1().publish(
            router1EventHandlerOutgoing, event
        )  ## R1 publishes the main event, R2C picks it up and forwards it to TestEventHTTPRouter1Console.py
        rootlogger.warn("== The event has completed being published ==")

    return makeDeferred(StatusVal.OK)
Beispiel #5
0
 def resethandler(self, h, e):
     """
     On receiving a reset event, reset the response counter
     """
     log.info("resethandler %s", e)
     self._count = 0
     return makeDeferred(StatusVal.OK)
 def resethandler(self, h, e):
     """
     On receiving a reset event, reset the response counter
     """
     log.info("resethandler %s", e)
     self._count = 0
     return makeDeferred(StatusVal.OK)
def eventHandlerQueueing(h, e):
    Trace("%s eventHandlerQueueing %s" % (h, str(e)),
          "EventLib.TestEventRouterThreaded")
    h.evcount += 1
    h.event = e
    h.queue.append(e)
    return makeDeferred(StatusVal.OK)
Beispiel #8
0
    def doHandleEvent( self, handler, inEvent ):
    
        if inEvent.getType() == 'http://id.webbrick.co.uk/events/config/get':
            self.doHandleConfig( inEvent )
            return makeDeferred(StatusVal.OK)    
        
        elif inEvent.getType() == 'http://id.webbrick.co.uk/events/time/dayphaseext':
            self.doHandleDayPhase( inEvent ) 
            return makeDeferred(StatusVal.OK)   
        
        elif inEvent.getType() == 'http://id.webbrick.co.uk/events/time/isDark':
            self.doHandleDark( inEvent )
            return makeDeferred(StatusVal.OK)    
        
        elif inEvent.getType() == "http://id.webbrick.co.uk/events/time/second":
            self.indexTimer()
            return makeDeferred(StatusVal.OK)

        elif inEvent.getType() == self._presence_event['type'] and inEvent.getSource() == self._presence_event['source']:
            self.doHandlePresence( inEvent )
            return makeDeferred(StatusVal.OK)    
        
        elif self._hold_event and inEvent.getType() == self._hold_event['type'] and inEvent.getSource() == self._hold_event['source']:
            self.doHandleHold( inEvent )
            return makeDeferred(StatusVal.OK)    

        elif self._light_state_event and inEvent.getType() == self._light_state_event['type'] and inEvent.getSource() == self._light_state_event['source']:
            self.doHandleLightState( inEvent )
            return makeDeferred(StatusVal.OK)    

        else: 
            return super(Timer,self).doHandleEvent( handler, inEvent)
def eventHandlerBlocking(h, e):
    Trace("%s eventHandlerBlocking %s" % (h, str(e)),
          "EventLib.TestEventRouterThreaded")
    time.sleep(1.0)
    h.evcount += 1
    h.event = e
    Trace("%s eventHandlerBlocking - return" % (h),
          "EventLib.TestEventRouterThreaded")
    return makeDeferred(StatusVal.OK)
    def doHandleEvent( self, handler, inEvent ):
        """ Update our cache of values """
        if inEvent.getType() == "http://id.webbrick.co.uk/events/time/minute" :
            self.handleMinute( inEvent )

        elif inEvent.getType() == "http://id.webbrick.co.uk/events/config/get":
            self.handleConfiguration( inEvent )

        return makeDeferred(StatusVal.OK)
 def handleEvent(self, event):
     # Treat subscribe-related events differently
     if not isSubscribeEvent(event.getType()):
         self._triggered = True
         self._status    = StatusVal.TRIGGERED
     else:
         self._watched = True
         self._event   = event
     return makeDeferred(StatusVal.OK)
 def handleEvent(self, event):
     # Treat subscribe-related events differently
     if not isSubscribeEvent(event.getType()):
         self._triggered = True
         self._status    = StatusVal.TRIGGERED
     else:
         self._watched = True
         self._event   = event
     return makeDeferred(StatusVal.OK)
Beispiel #13
0
    def doHandleEvent(self, handler, inEvent):
        """
        Override base class to pick up second events.
        """
        if inEvent.getType() == "http://id.webbrick.co.uk/events/time/second":
            self.checkDelays()
            return makeDeferred(StatusVal.OK)

        return super(DelayedEvent, self).doHandleEvent(handler, inEvent)
 def doHandleEvent( self, handler, inEvent ):
     if inEvent.getType() == "http://id.webbrick.co.uk/events/time/minute" :
         od = inEvent.getPayload()
         curMin = od["minute"]
         if (curMin % 10) == 0:
             self.checkIcalSourceFile()
         self.checkVacationStatus( string.replace(string.replace(od["datetimestr"], "-", ""),":","") )
         # {'datetimestr': '2008-06-24T12:58:00', 'hour': 12, 'timestr': '12:58:00', 'month': 6, 'second': 0, 'datestr': '2008-06-24', 'year': 2008, 'date': 24, 'day': 2, 'minute': 58} 
     elif inEvent.getType() == "http://id.webbrick.co.uk/events/time/runtime" :
         pass
     return makeDeferred(StatusVal.OK)    
def eventHandler(h,e):
    # This is called when R1 picks up a subscribed event
    h.evcount += 1
    h.event    = e
    rootlogger.debug("!!!!!!!!!!!!!!!!!== Received an incoming event, event number: %s ==", h.evcount)
    rootlogger.debug("!!!!!!!!!!!!!!!!!== With payload: %s ==", h.event.getPayload())    
    if h.event.getType() == "to/router/2":
        rootlogger.warn("== Received an incoming event, event number: %s ==", h.evcount)
        rootlogger.warn("== With payload: %s ==", h.event.getPayload())       
        sendBackResponse(count=h.evcount)
    return makeDeferred(StatusVal.OK)
Beispiel #16
0
    def doHandleEvent(self, handler, inEvent):
        if inEvent.getType() == "http://id.webbrick.co.uk/events/time/minute":
            if int(inEvent.getPayload()["hour"]) == 2 and int(inEvent.getPayload()["minute"]) == 5:
                self.doDailyCompress()

        elif inEvent.getType() == "http://id.webbrick.co.uk/events/config/set":
            self.handleSet(inEvent)

        elif inEvent.getType() == "http://id.webbrick.co.uk/events/time/runtime":
            if int(inEvent.getPayload()["elapsed"]) == 5:
                self.doPublishAll("")  # publish all the data.

        return makeDeferred(StatusVal.OK)
Beispiel #17
0
 def clickhandler(self, h, e):
     """
     On receiving a button-click, bump the counter and generate some more events
     """
     log.info("clickhandler %s", e)
     buttonstates  = ('up', 'down', 'waiting', 'unknown')
     displaystates = ('normal', 'low', 'high', 'unknown')
     if e.getPayload() == "click":
         self._count += 1
         e1 = makeEvent(SetButtonTextEvent, h.getUri(), "Button:%i"%(self._count))
         self._router.publish(h, e1)
         e2 = makeEvent(SetButtonStateEvent, h.getUri(), buttonstates[self._count%4])
         self._router.publish(h, e2)
         e3 = makeEvent(SetNumericDisplayValueEvent, h.getUri(), str(self._count))
         self._router.publish(h, e3)
         e4 = makeEvent(SetNumericDisplayStateEvent, h.getUri(), displaystates[self._count%4])
         self._router.publish(h, e4)
     return makeDeferred(StatusVal.OK)
Beispiel #18
0
    def doHandleEvent( self, handler, event ):
        """ Update our cache of values """
        dc = None
        od = event.getPayload()
        # handle events with no payload.
        if od:
            _log.debug( 'update %s %s ' % (event.getSource(), od ) )
            if not self._cache.has_key(event.getSource()):
                self._cache[event.getSource()] = dict()
                
            dc = self._cache[event.getSource()]
            for k in od:
                dc[k] = od[k]
        else:
            # treat no payload as instruction to clear the cache
            if self._cache.has_key(event.getSource()):
                del self._cache[event.getSource()]

        return makeDeferred(StatusVal.OK)
Beispiel #19
0
    def doHandleEvent( self, handler, event ):
        if ( event.getType() == "http://id.webbrick.co.uk/events/webbrick/config/nodename" ):
            self._log.debug( 'update name map %s' % ( ( event.getPayload() ) ) )
            if event.getPayload().has_key("fromNode"):
                self._log.info("fromNode is %s" % (event.getPayload()["fromNode"]))
				# in case set from XML config file
                nr = int(event.getPayload()["fromNode"])
                if event.getPayload().has_key("nodename"):
                    self._nameMap[event.getPayload()["nodename"].lower()] = nr
                if event.getPayload().has_key("ipAdr"):
                    self._nodeMap[nr] = event.getPayload()["ipAdr"]
                    if event.getPayload().has_key("nodename"):
                        self._IpMap[event.getPayload()["ipAdr"]] = event.getPayload()["nodename"].lower()
                    if event.getPayload().has_key("version"):
                        self._Versions[event.getPayload()["ipAdr"]] = event.getPayload()["version"].lower()
            self._log.debug( 'XXXXXXXXXXXXXXXXXX   self._nameMap %s' % ( ( self._nameMap ) ) )
            self._log.debug( 'self._nodeMap %s' % ( ( self._nodeMap ) ) )
            self._log.debug( 'self._IpMap %s' % ( ( self._IpMap ) ) )
        return makeDeferred(StatusVal.OK)
Beispiel #20
0
    def doHandleEvent( self, handler, event ):
        """ Update our cache of values, if the value is not provided for an event then
            we delete the key from our cache """
        self._log.debug( 'WebBrickStatus cache update %s' % (event.getSource() ) )
        if ( event.getType() == "http://id.webbrick.co.uk/events/webbrick/AO" ) :
            # need ipaddr, node number.
            if event.getPayload().has_key("val"):
                self._cache[ event.getSource() ] = event.getPayload()["val"]
            elif self._cache.has_key( event.getSource() ):
                del self._cache[ event.getSource() ]
        elif ( event.getType() == "http://id.webbrick.co.uk/events/webbrick/AI" ) :
            if event.getPayload().has_key("val"):
                self._cache[ event.getSource() ] = event.getPayload()["val"]
            elif self._cache.has_key( event.getSource() ):
                del self._cache[ event.getSource() ]
        elif ( event.getType() == "http://id.webbrick.co.uk/events/webbrick/DI" ) :
            if event.getPayload().has_key("state"):
                if event.getPayload()["state"] == 1:
                    self._cache[ event.getSource() ] = "True"
                else:
                    self._cache[ event.getSource() ] = "False"
            elif self._cache.has_key( event.getSource() ):
                del self._cache[ event.getSource() ]
        elif ( event.getType() == "http://id.webbrick.co.uk/events/webbrick/DO" ) :
            if event.getPayload().has_key("state"):
                if event.getPayload()["state"] == 1:
                    self._cache[ event.getSource() ] = "True"
                else:
                    self._cache[ event.getSource() ] = "False"
            elif self._cache.has_key( event.getSource() ):
                del self._cache[ event.getSource() ]
        elif ( event.getType() == "http://id.webbrick.co.uk/events/webbrick/CT" ) :
            if event.getPayload().has_key("val"):
                self._cache[ event.getSource() ] = event.getPayload()["val"]
            elif self._cache.has_key( event.getSource() ):
                del self._cache[ event.getSource() ]

        if event.getPayload() and event.getPayload().has_key("ipAdr"):
            # update last seen cache
            self._wbActiveTS[event.getPayload()["ipAdr"]] = (time.time(),event.getSource()) # in seconds etc.
        return makeDeferred(StatusVal.OK)
 def doHandleEvent(self,handler,inEvent):
     if inEvent.getType() == 'http://id.webbrick.co.uk/events/webbrick/DO':
         if inEvent.getSource() == 'webbrick/' + self.nodeNum + '/DO/' + self.doNum:
             if inEvent.getPayload()['state'] != self.targetVal:
                 if self.targetVal == '0':          
                     self._log.error("Webbrick DO not at target value is off , should be on")
                     self.turnOff()
                 elif self.targetVal == '1':
                     #check if we were dwelling
                     if self.dwellAmount:
                         if self.dwellTime < time.time():
                             #dwell time has expired being off is fine
                             self.targetVal = '0'
                         else:
                             #dwell not expired , dwell must have failed to set
                             self._log.error("Webbrick DO not at target value is off , should be on for %i seconds" %self.dwellTime)
                             self.turnOn(self.dwellAmount)
                     else:                    
                         self._log.error("Webbrick DO not at target value is off , should be on")
                         self.turnOn()
     return makeDeferred(StatusVal.OK)
Beispiel #22
0
    def doHandleEvent( self, handler, inEvent ):
        # handle commit using self._commit_delay
        if inEvent.getType() == "http://id.webbrick.co.uk/events/time/minute" :
            # Chose 19.05 since at this time most heating will be on, hence if gateway fals over and uses 24hr backup heatign will be on! 
            if int(inEvent.getPayload()["hour"]) == 19 and int(inEvent.getPayload()["minute"]) == 5:
                self.doDailyBackup()
    
        elif inEvent.getType() == "http://id.webbrick.co.uk/events/config/set" :
            self.handleSet( inEvent )

        elif inEvent.getType() == "http://id.webbrick.co.uk/events/subscribe" :
            self.handleSubscribe( inEvent )

        elif inEvent.getType() == "http://id.webbrick.co.uk/events/time/second":
            self.commitCountdown()

        elif inEvent.getType() == "http://id.webbrick.co.uk/events/time/runtime" :
            if int(inEvent.getPayload()["elapsed"]) == 5:
                self.doPublish("")  # publish all the data.

        return makeDeferred(StatusVal.OK)
Beispiel #23
0
 def clickhandler(self, h, e):
     """
     On receiving a button-click, bump the counter and generate some more events
     """
     log.info("clickhandler %s", e)
     buttonstates = ('up', 'down', 'waiting', 'unknown')
     displaystates = ('normal', 'low', 'high', 'unknown')
     if e.getPayload() == "click":
         self._count += 1
         e1 = makeEvent(SetButtonTextEvent, h.getUri(),
                        "Button:%i" % (self._count))
         self._router.publish(h, e1)
         e2 = makeEvent(SetButtonStateEvent, h.getUri(),
                        buttonstates[self._count % 4])
         self._router.publish(h, e2)
         e3 = makeEvent(SetNumericDisplayValueEvent, h.getUri(),
                        str(self._count))
         self._router.publish(h, e3)
         e4 = makeEvent(SetNumericDisplayStateEvent, h.getUri(),
                        displaystates[self._count % 4])
         self._router.publish(h, e4)
     return makeDeferred(StatusVal.OK)
def eventHandlerQueueing(h,e):
    Trace("%s eventHandlerQueueing %s"%(h,str(e)), "EventLib.TestEventRouterThreaded")
    h.evcount += 1
    h.event    = e
    h.queue.append(e)
    return makeDeferred(StatusVal.OK)
Beispiel #25
0
    def doHandleEvent( self, handler, event ):
        et = event.getType()
        od = event.getPayload()

        return makeDeferred(StatusVal.OK)
def eventHandler(h,e):
    Trace("%s eventHandler %s"%(h,str(e)), "EventLib.TestEventRouterThreaded")
    h.evcount += 1
    h.event    = e
    return makeDeferred(StatusVal.OK)
Beispiel #27
0
def handleEvent(handler, event):
    s = Status(URI.Status_TRIGGERED, event.getType())
    return makeDeferred(s)
def endSub(handler, status):
    s = Status(URI.Status_UNSUBSCRIBED, str(status))
    return makeDeferred(s)
def eventHandler(h,e):
    h.evcount += 1
    h.event    = e
    return makeDeferred(StatusVal.OK)
def handleEvent(handler, event):
    s = Status(URI.Status_TRIGGERED, event.getType())
    return makeDeferred(s)
Beispiel #31
0
def eventHandler(h,e):
    h.evcount += 1
    h.event    = e
    return makeDeferred(StatusVal.OK)
 def testMakeDeferred(self):
     d = makeDeferred("DeferredVal")
     self.assertEqual(d.syncValue(), "DeferredVal", "testMakeDeferred")
 def initSubscription(self, status):
     self._triggered = False
     self._status    = StatusVal.SUBSCRIBED
     return makeDeferred(StatusVal.OK)
Beispiel #34
0
 def testMakeDeferred(self):
     d = makeDeferred("DeferredVal")
     self.assertEqual(d.syncValue(), "DeferredVal", "testMakeDeferred")
 def endSubscription(self, status):
     self._status    = StatusVal.UNSUBSCRIBED
     return makeDeferred(StatusVal.OK)
 def initSubscription(self, status):
     self._triggered = False
     self._status    = StatusVal.SUBSCRIBED
     return makeDeferred(StatusVal.OK)
Beispiel #37
0
    def doHandleEvent( self, handler, inEvent ):
        _log.debug( 'doHandleEvent %s', inEvent )
        self._taskList.put( inEvent )

        return makeDeferred(StatusVal.OK)
 def endSubscription(self, status):
     self._status    = StatusVal.UNSUBSCRIBED
     return makeDeferred(StatusVal.OK)
Beispiel #39
0
 def doHandleEvent( self, handler, event ):
     """ Update our cache of values """
     self._log.debug( 'update %s' % (event.getSource() ) )
     self._cache[event.getSource()] = event.getPayload()["val"]
     return makeDeferred(StatusVal.OK)
Beispiel #40
0
                source = None
                if typeDict.has_key( inEvent.getSource() ):
                    source = typeDict[inEvent.getSource()]
                elif typeDict.has_key( "" ):
                    source = typeDict[""]

                if source:
                    #self._log.debug( 'source %s' % ( source ) )
                    # Look through all possible event targets.
                    for eventEntry in source:
                        # now match params.
                        # basically anything in the param 
                        paramSet = eventEntry[0]
                        isMatched = True # in case no parameters
                        if ( paramSet ):   # if no parameters assume match
                            isMatched = paramSet.match( inEvent.getPayload() )

                        if isMatched:
                            self._log.debug( 'Handler Matches %s' % (eventEntry,) )
                            try:
                                self.doActions( eventEntry[1], inEvent )
                            except Exception, ex:
                                self._log.exception( ex )
                        # not matched this time.
                    # for eventEntry in typeDict[ inEvent.type() ]:

        except Exception, ex:
            self._log.exception( ex )

        return makeDeferred(StatusVal.OK)
Beispiel #41
0
def endSub(handler, status):
    s = Status(URI.Status_UNSUBSCRIBED, str(status))
    return makeDeferred(s)
def eventHandler(h, e):
    Trace("%s eventHandler %s" % (h, str(e)),
          "EventLib.TestEventRouterThreaded")
    h.evcount += 1
    h.event = e
    return makeDeferred(StatusVal.OK)