def test_transmit(self):
     packet = {'a': 'b'}
     value = 11
     que = HMQueue()
     que._queue.put = Mock()
     que.transmit(packet)
     que._queue.put.assert_called_once_with((que.MID_PRIORITY, packet))
 def test_transmit( self ):
     packet = {'a': 'b'}
     value = 11
     que = HMQueue()
     que._queue.put = Mock()
     que.transmit( packet )
     que._queue.put.assert_called_once_with( ( que.MID_PRIORITY, packet ) )
 def test_receive(self):
     packet = {'a': 'b'}
     value = 11
     que = HMQueue()
     priority = que.MID_PRIORITY
     que._queue.get = Mock(return_value=(priority, value))
     ret = que.receive()
     que._queue.get.assert_called_once_with()
     self.assertEqual(value, ret)
 def test_receive( self ):
     packet = {'a': 'b'}
     value = 11
     que = HMQueue()
     priority = que.MID_PRIORITY
     que._queue.get = Mock( return_value=( priority, value ) )
     ret = que.receive()
     que._queue.get.assert_called_once_with()
     self.assertEqual( value, ret )
Example #5
0
 def test_ZigBeeOutput_throws_exception(self, zo, t):
     queue = HMQueue()
     thread = ZigBeeOutputThread(queue, 1)
     zo.side_effect = KeyError('boom')
     thread.zigbeeConnect()
     self.assertFalse(thread.connected)
     self.assertFalse(thread.talking)
Example #6
0
 def test_run(self):
     queue = HMQueue()
     packet = 555
     thread = ZigBeeOutputThread(queue, 1)
     thread.connectAndProcessZigBeeCommands = MagicMock()
     thread.run()
     thread.connectAndProcessZigBeeCommands.assert_called_once_with()
Example #7
0
 def test_ProcessInput_work_status_request(self, process, config, receive):
     envelope = DataEnvelope(Constants.EnvelopeTypes.STATUS)
     que = HMQueue()
     pi = ProcessInput(que)
     que.receive.return_value = envelope
     pi.work()
     que.receive.assert_called_oncy_with()
     pi.commands[envelope.type].process.assert_called_once_with(envelope)
Example #8
0
 def __init__(self):
     super(Main, self).__init__()
     self.logger.debug('Start Input Queue')
     input_queue = HMQueue(name="ZigBeeInput")
     self.logger.debug('instantuate XBeeInputThread')
     xbee_thread = XBeeInputThread(input_queue)
     self.logger.debug('Start Thread')
     xbee_thread.start()
Example #9
0
 def test_processCommandToZigBee_with_IOError_in_SendCommand(self):
     queue = HMQueue()
     packet = 555
     thread = ZigBeeOutputThread(queue, 1)
     thread.output_queue = MagicMock()
     thread.output_queue.receive = MagicMock()
     thread.connected = True
     thread.talking = True
     thread.done = False
     thread.zigbee_output = MagicMock()
     thread.zigbee_output.sendCommand = MagicMock(side_effect=IOError())
     thread.processCommandToZigBee()
     self.assertFalse(thread.connected)
     self.assertFalse(thread.talking)
     self.assertFalse(thread.done)
Example #10
0
 def test_processCconnectAndProcessZigBeeCommands(self):
     queue = HMQueue()
     packet = 555
     thread = ZigBeeOutputThread(queue, 1)
     thread.connected = False
     thread.talking = True
     thread.done = False
     thread.zigbeeConnect = MagicMock(return_value=True)
     thread.processCommandToZigBee = MagicMock(
         side_effect=KeyboardInterrupt)
     thread.connectAndProcessZigBeeCommands()
     thread.zigbeeConnect.assert_called_once_with()
     thread.zigbeeConnect.assert_called_once_with()
     self.assertTrue(thread.connected)
     self.assertTrue(thread.talking)
     self.assertFalse(thread.done)
Example #11
0
 def test_processCommandToZigBee(self, qr):
     packet = {}
     queue = HMQueue()
     value = 555
     data = {}
     packet['value'] = value
     packet['data'] = data
     packet['id'] = 0xab
     thread = ZigBeeOutputThread(queue, 1)
     qr.return_value = packet
     thread.zigbee_output = MagicMock()
     thread.zigbee_output.sendCommand = MagicMock()
     thread.connected = True
     thread.talking = True
     thread.done = False
     thread.processCommandToZigBee()
     thread.zigbee_output.sendCommand.assert_called_once_with(**packet)
     self.assertTrue(thread.connected)
     self.assertTrue(thread.talking)
     thread.done = False
Example #12
0
    def startCOSM(self, options):
        '''
        Start the COSM processing.
        
        >>> from optparse import OptionParser
        >>> from outputs.cosm.control import COSMControl
        >>> c = COSMControl()                                                   # doctest: +SKIP
        >>> options = 1                                                         # doctest: +SKIP
        >>> c.startCOSM(options)                                                # doctest: +SKIP
        >>> c.cosmOutputThread.forever = False                                  # doctest: +SKIP
        >>> c = None                                                            # doctest: +SKIP
        
        .. warning:: This doctest has been disabled.  It is trying to start too much.

        '''
        self.logger.debug('COSM starting up')
        self.queue = HMQueue('COSM')
        self.cosmOutputThread = COSMOutputThread(self.queue,
                                                 options,
                                                 name='COSM')
        self.cosmOutputThread.start()
        self.cosm = COSMOutputStep(self.queue)
    def startZigBee(self, in_test_mode):
        '''
        Start the ZigBee processing.

        This consists of three parts:

        #. Start the ZigBeeQueue which used Queue, a thread safe queue for communcating
        between threads.

        #. Start the ZigBeeOutputThread which talks to the ZigBee server.  This is a slow process.

        #. Start the ZigBeeOutputProcessing object which takes massages sent to ZigBee on the
        main thread and sends them to the ZigBee thread.

        '''
        self.queue = HMQueue('ZigBeeInput')
        self.in_test_mode = in_test_mode
        self.zig = ZigBeeOutputStep(self.queue)

        self.ZigBeeOutputThread = ZigBeeOutputThread(self.queue,
                                                     self.in_test_mode)
        self.ZigBeeOutputThread.start()
Example #14
0
    def run(self):

        self.logger.debug('Setting up global_data')
        global_data = {}
        global_data[Constants.GlobalData.CURRENT_VALUES] = CurrentValues()
        global_data[Constants.GlobalData.OPTIONS] = self.options
        global_data[Constants.GlobalData.ARGS] = self.args
        global_data[Constants.GlobalData.START_TIME] = datetime.utcnow()
        global_data[Constants.GlobalData.INPUT_QUEUE] = HMQueue("Input")

        self.module_loader = ModuleLoader()
        self.module_loader.load(global_data)

        self.startOutputs(global_data)

        self.startInputs(global_data)

        self.pubAid = PubSubAid()

        # Endless loop will never return
        self.input.input()

        self.logger.debug("Exiting")
 def test_topic_name( self ):
     queue = HMQueue()
     zig = ZigBeeOutputStep( queue )
     self.assertEqual( Constants.TopicNames.ZigBeeOutput, zig.topic_name )
 def test_logger_name( self ):
     queue = HMQueue()
     zig = ZigBeeOutputStep( queue )
     self.assertEqual( Constants.LogKeys.outputsZigBee, zig.logger_name )
Example #17
0
 def test_input(self, receive, work, config):
     que = HMQueue()
     self.pi = ProcessInput(que)
     work.side_effect = self.side_effect
     self.pi.input()
     self.pi.work.assert_called_once_with()
Example #18
0
 def test_clear( self ):
     que = HMQueue()
     que._queue.get = Mock( side_effect=Queue.Empty )
     que.clear()
     que._queue.get.assert_called_once_with( False )
Example #19
0
 def test_logger_name( self , config ):
     queue = HMQueue( 'COSM' )
     options = 'a'
     thread = COSMOutputThread( options, queue )
     self.assertEqual( thread.logger_name, Constants.LogKeys.outputsCOSM )
Example #20
0
 def test_clear(self):
     que = HMQueue()
     que._queue.get = Mock(side_effect=Queue.Empty)
     que.clear()
     que._queue.get.assert_called_once_with(False)
Example #21
0
 def test_logger_name(self):
     queue = HMQueue()
     thread = ZigBeeOutputThread(queue, 1)
     self.assertEqual(thread.logger_name, Constants.LogKeys.outputsZigBee)
Example #22
0
 def test_logger_name(self):
     que = HMQueue()
     self.assertEqual(que.logger_name, Constants.LogKeys.lib)