Exemplo n.º 1
0
 def testDoTTurn(self):
     valveCfg = getDictFromXmlString(digitalTimedCfg)
     self.valve = Valve(valveCfg['valve'],self.router)
     
     #turn the valve all the way to hot
     self.valve.doTurn("TS" , 100)
     time.sleep(0.2)
     TestEventLogger.logEvents()
     assert TestEventLogger._events[0].getType() == 'internal/hvac/digitalout'
     assert TestEventLogger._events[0].getSource() == 'hvac/valve/tv1/2/off'
     assert TestEventLogger._events[1].getType()  == 'internal/hvac/digitalout'
     assert TestEventLogger._events[1].getSource() == 'hvac/valve/tv1/1/dwell'
     assert TestEventLogger._events[1].getPayload()['val'] == '100'        
     TestEventLogger.clearEvents()
     
     #turn the valve all the way to cold
     self.valve.doTurn("CS" , 100)        
     time.sleep(0.2)
     TestEventLogger.logEvents()
     assert TestEventLogger._events[0].getType()  == 'internal/hvac/digitalout'
     assert TestEventLogger._events[0].getSource() == 'hvac/valve/tv1/1/off'
     assert TestEventLogger._events[1].getType()  == 'internal/hvac/digitalout'
     assert TestEventLogger._events[1].getSource() == 'hvac/valve/tv1/2/dwell'
     assert TestEventLogger._events[1].getPayload()['val'] == '200'        
     TestEventLogger.clearEvents()
     
     #turn the valve halfway to hot
     self.valve.doTurn("TS" , 50)
     time.sleep(0.2)
     TestEventLogger.logEvents()
     assert TestEventLogger._events[0].getType()  == 'internal/hvac/digitalout'
     assert TestEventLogger._events[0].getSource() == 'hvac/valve/tv1/2/off'  
     
     assert TestEventLogger._events[1].getType()  == 'internal/hvac/digitalout'
     assert TestEventLogger._events[1].getSource() == 'hvac/valve/tv1/1/dwell'
     assert TestEventLogger._events[1].getPayload()['val'] == '50'        
     TestEventLogger.clearEvents()
     
     #turn the valve 25% further to hot, should end up getting rounded to 22
     self.valve.doTurn("TS" , 25)
     time.sleep(0.2)
     TestEventLogger.logEvents()
     assert TestEventLogger._events[0].getType()  == 'internal/hvac/digitalout'
     assert TestEventLogger._events[0].getSource() == 'hvac/valve/tv1/2/off'  
     
     assert TestEventLogger._events[1].getType()  == 'internal/hvac/digitalout'
     assert TestEventLogger._events[1].getSource() == 'hvac/valve/tv1/1/dwell'
     assert TestEventLogger._events[1].getPayload()['val'] == '25'        
     TestEventLogger.clearEvents()
Exemplo n.º 2
0
 def testAoTurn(self):
     """
         Test to make sure the correct events are being sent out when we request valvage
         We fake the return webbrick event to avoid having to set up a live webbrick
         The outgoing http request also never gets sent as we dont initialize twisted
     """            
     valveCfg = getDictFromXmlString(aCfg)
     self.valve = Valve(valveCfg['valve'],self.router)
     
     #turn the valve all the way to hot
     self.valve.doTurn("TS" , 100)
     time.sleep(0.2)
     TestEventLogger.logEvents()
     assert TestEventLogger._events[0].getType()  == 'internal/hvac/analogoutput'
     assert TestEventLogger._events[0].getSource() == 'hvac/valve/tv1/3'
     assert TestEventLogger._events[0].getPayload()['val'] == '30'
     TestEventLogger.clearEvents()
     
     #turn the valve all the way to cold
     self.valve.doTurn("CS" , 100)        
     time.sleep(0.2)
     TestEventLogger.logEvents()
     assert TestEventLogger._events[0].getType()  == 'internal/hvac/analogoutput'
     assert TestEventLogger._events[0].getSource() == 'hvac/valve/tv1/3'
     assert TestEventLogger._events[0].getPayload()['val'] == '0'        
     TestEventLogger.clearEvents()
     
     #turn the valve halfway to hot
     self.valve.doTurn("TS" , 50)
     time.sleep(0.2)
     TestEventLogger.logEvents()
     assert TestEventLogger._events[0].getType()  == 'internal/hvac/analogoutput'
     assert TestEventLogger._events[0].getSource() == 'hvac/valve/tv1/3'
     assert TestEventLogger._events[0].getPayload()['val'] == '15'        
     TestEventLogger.clearEvents()
     
     #turn the valve 25% further to hot, should end up getting rounded to 22
     self.valve.doTurn("TS" , 25)
     time.sleep(0.2)
     TestEventLogger.logEvents()
     assert TestEventLogger._events[0].getType()  == 'internal/hvac/analogoutput'
     assert TestEventLogger._events[0].getSource() == 'hvac/valve/tv1/3'
     assert TestEventLogger._events[0].getPayload()['val'] == '22'        
     TestEventLogger.clearEvents()
Exemplo n.º 3
0
 def testDoTurn(self):
     valveCfg = getDictFromXmlString(digitalCfg)
     self.valve = Valve(valveCfg['valve'],self.router)
     
     #because of the way the digital valves work, any turn its 100% in either direction
     #turn the valve all the way to hot
     self.valve.doTurn("TS" , 100)
     time.sleep(0.2)
     TestEventLogger.logEvents()
     assert TestEventLogger._events[0].getType()  == 'internal/hvac/digitaloutput'
     assert TestEventLogger._events[0].getSource() == 'hvac/valve/tv1/1/on'
     TestEventLogger.clearEvents()
     
     #turn the valve all the way to cold
     self.valve.doTurn("CS" , 100)        
     time.sleep(0.2)
     TestEventLogger.logEvents()
     assert TestEventLogger._events[0].getType()  == 'internal/hvac/digitaloutput'
     assert TestEventLogger._events[0].getSource() == 'hvac/valve/tv1/1/off'
     TestEventLogger.clearEvents()
     
     #turn the valve halfway to hot 
     self.valve.doTurn("TS" , 50)
     time.sleep(0.2)
     TestEventLogger.logEvents()
     assert TestEventLogger._events[0].getType()  == 'internal/hvac/digitaloutput'
     assert TestEventLogger._events[0].getSource() == 'hvac/valve/tv1/1/on'
     TestEventLogger.clearEvents()
     
     #turn the valve 25% further to hot
     self.valve.doTurn("TS" , 25)
     time.sleep(0.2)
     TestEventLogger.logEvents()
     assert TestEventLogger._events[0].getType()  == 'internal/hvac/digitaloutput'
     assert TestEventLogger._events[0].getSource() == 'hvac/valve/tv1/1/on'     
     TestEventLogger.clearEvents()
    def testRun(self):
        self._log.debug( "\ntestRun" )
        self.loader = EventRouterLoader()
        self.loader.loadHandlers( getDictFromXmlString(testConfig1) )
        self.loader.start()  # all tasks
        self.router = self.loader.getEventRouter()
        time.sleep(0.1)

        # We should see lots of events here as initial pass.
        TestEventLogger.logEvents()
        oldLen = len(TestEventLogger._events)
        self.assertEqual( oldLen, 11 )  # twice sent.
        TestEventLogger.clearEvents()
        
        # send midnight
        # no new events, just me
        self.router.publish( EventAgent("TestScheduleProcessor"), evtMidnightMon )
        time.sleep(0.1)
        oldLen = len(TestEventLogger._events)
        TestEventLogger.logEvents()
        self.assertEqual( oldLen, 1 )
        self.assertEqual( TestEventLogger._events[0].getSource(), "time/minute" )

        # first event time
        self.router.publish( EventAgent("TestScheduleProcessor"), evt0530 )
        time.sleep(0.2)
        # time and two actions
        oldLen = len(TestEventLogger._events)
        TestEventLogger.logEvents()
        self.assertEqual( oldLen, 4 )
        self.assertEqual( TestEventLogger._events[1].getSource(), "time/minute" )
        self.assertEqual( TestEventLogger._events[2].getSource(), "zone1/set" )
        self.assertEqual( TestEventLogger._events[3].getSource(), "boiler/On" )

        # second event time
        self.router.publish( EventAgent("TestScheduleProcessor"), evt0800 )
        time.sleep(0.1)
        # time and one actions
        oldLen = len(TestEventLogger._events)
        TestEventLogger.logEvents()
        self.assertEqual( oldLen, 6 )
        self.assertEqual( TestEventLogger._events[4].getSource(), "time/minute" )
        self.assertEqual( TestEventLogger._events[5].getSource(), "zone1/set" )

        # third event time
        self.router.publish( EventAgent("TestScheduleProcessor"), evt1600 )
        time.sleep(0.1)
        # time and one actions
        oldLen = len(TestEventLogger._events)
        TestEventLogger.logEvents()
        self.assertEqual( oldLen, 8 )
        self.assertEqual( TestEventLogger._events[6].getSource(), "time/minute" )
        self.assertEqual( TestEventLogger._events[7].getSource(), "boiler/Off" )

        # fourth event time
        self.router.publish( EventAgent("TestScheduleProcessor"), evt2200 )
        time.sleep(0.1)
        # time and two actions
        oldLen = len(TestEventLogger._events)
        TestEventLogger.logEvents()
        self.assertEqual( oldLen, 11 )
        self.assertEqual( TestEventLogger._events[8].getSource(), "time/minute" )
        self.assertEqual( TestEventLogger._events[9].getSource(), "zone1/set" )
        self.assertEqual( TestEventLogger._events[10].getSource(), "boiler/On" )