def test_XBeeInput_process_with_valid_data( self, config, send, dt ): test_time = datetime.datetime( 2012, 1, 2, 3, 4, 5 ) data = {'source_addr_long': '\x00\x13\xa2\x00@\x90)\xbf', 'source_addr': '\xf9\xf2', 'id': 'rx_io_data_long_addr', 'samples': [{'adc-1': 622}], 'options': '\x01'} env = DataEnvelope( Constants.EnvelopeTypes.XBEE, **data ) xd = xmlDeviceConfiguration() xd.devices = self.valid_devices_configuration xp = ProcessXBeeInput( xd ) dt.utcnow.return_value = 123 xp.process( env ) send.assert_called_once_with( 622, {'name': 'Garage Temperature', 'units': 'F', 'steps': ['step.ZigbeeAnalogNumberToVolts', 'step.TMP_36_Volts_to_Centigrade', 'step.Centigrade_to_Fahrenheit', 'step.Average', 'step.FormatValue', 'step.CurrentValue', 'step.oneInN', 'outputs.COSM'], 'at': 123, 'device': '0x13a200409029bf', 'port': 'adc-1'}, ['step.ZigbeeAnalogNumberToVolts', 'step.TMP_36_Volts_to_Centigrade', 'step.Centigrade_to_Fahrenheit', 'step.Average', 'step.FormatValue', 'step.CurrentValue', 'step.oneInN', 'outputs.COSM'] )
def test_XBeeInput_process_invalid_configuration_options_error( self, config, send): data = { 'source_addr_long': '\x00\x13\xa2\x00@\x90)\xbf', 'source_addr': '\xf9\xf2', 'id': 'rx_io_data_long_addr', 'samples': [{ 'adc-0': 622 }], 'options': '\x01' } env = DataEnvelope(Constants.EnvelopeTypes.XBEE, **data) xd = xmlDeviceConfiguration() xd.devices = { '0x13a200409029bf': { 'adc-0': { 'cosm_channel': '3', 'description': 'The temperature in the sunroom', 'name': 'Indoor Temperature', 'steps': [ 'step.ZigbeeAnalogNumberToVolts', 'step.TMP_36_Volts_to_Centigrade', 'step.Centigrade_to_Fahrenheit', 'step.Average', 'step.FormatValue', 'step.CurrentValue' ] }, 'adc-1': { 'cosm_channel': '3', 'description': 'The temperature at 100 West Lisa Drive Austin TX', 'name': 'Outdoor Temperature', 'steps': [ 'step.ZigbeeAnalogNumberToVolts', 'step.TMP_36_Volts_to_Centigrade', 'step.Centigrade_to_Fahrenheit', 'step.Average', 'step.FormatValue', 'step.CurrentValue' ], 'units': 'F' }, 'name': 'Sunroom', 'network_address': '0xf9f2' } } xp = ProcessXBeeInput(xd) xp.logger.exception = MagicMock() value = xp.process(env) xp.logger.exception.assert_called_with( "'Required configuration option not present (units) for device(0x13a200409029bf) port (adc-0)'" ) self.assertEqual(send.call_count, 0)
def test_XBeeInput_process_with_valid_data(self, config, send, dt): test_time = datetime.datetime(2012, 1, 2, 3, 4, 5) data = { 'source_addr_long': '\x00\x13\xa2\x00@\x90)\xbf', 'source_addr': '\xf9\xf2', 'id': 'rx_io_data_long_addr', 'samples': [{ 'adc-1': 622 }], 'options': '\x01' } env = DataEnvelope(Constants.EnvelopeTypes.XBEE, **data) xd = xmlDeviceConfiguration() xd.devices = self.valid_devices_configuration xp = ProcessXBeeInput(xd) dt.utcnow.return_value = 123 xp.process(env) send.assert_called_once_with( 622, { 'name': 'Garage Temperature', 'units': 'F', 'steps': [ 'step.ZigbeeAnalogNumberToVolts', 'step.TMP_36_Volts_to_Centigrade', 'step.Centigrade_to_Fahrenheit', 'step.Average', 'step.FormatValue', 'step.CurrentValue', 'step.oneInN', 'outputs.COSM' ], 'at': 123, 'device': '0x13a200409029bf', 'port': 'adc-1' }, [ 'step.ZigbeeAnalogNumberToVolts', 'step.TMP_36_Volts_to_Centigrade', 'step.Centigrade_to_Fahrenheit', 'step.Average', 'step.FormatValue', 'step.CurrentValue', 'step.oneInN', 'outputs.COSM' ])
def test_XBeeInput_process_invalid_port_error( self, config, send ): data = {'source_addr_long': '\x00\x13\xa2\x00@\x90)\xbf', 'source_addr': '\xf9\xf2', 'id': 'rx_io_data_long_addr', 'samples': [{'adc-3': 622}], 'options': '\x01'} env = DataEnvelope( Constants.EnvelopeTypes.XBEE, **data ) xd = xmlDeviceConfiguration() xd.devices = {'0x13a200409029bf': {'adc-0': {'cosm_channel': '3', 'description': 'The temperature in the sunroom', 'name': 'Indoor Temperature', 'steps': ['step.ZigbeeAnalogNumberToVolts', 'step.TMP_36_Volts_to_Centigrade', 'step.Centigrade_to_Fahrenheit', 'step.Average', 'step.FormatValue', 'step.CurrentValue'], 'units': 'F'}, 'adc-1': {'cosm_channel': '3', 'description': 'The temperature at 100 West Lisa Drive Austin TX', 'name': 'Outdoor Temperature', 'steps': ['step.ZigbeeAnalogNumberToVolts', 'step.TMP_36_Volts_to_Centigrade', 'step.Centigrade_to_Fahrenheit', 'step.Average', 'step.FormatValue', 'step.CurrentValue'], 'units': 'F'}, 'name': 'Sunroom', 'network_address': '0xf9f2'}} xp = ProcessXBeeInput( xd ) xp.logger.exception = MagicMock() value = xp.process( env ) xp.logger.exception.assert_called_with( "'Invalid port (adc-3)'" ) self.assertEqual( send.call_count, 0 )