def test_get_steps( self, configure ): steps = [i for i in range( 10 )] xdc = xmlDeviceConfiguration() xdc.devices = {'device': {'port': {Constants.XbeeConfiguration.name: 'test', Constants.XbeeConfiguration.steps: steps}}} self.assertSequenceEqual( xdc.get_steps( 'device', 'port' ), steps )
def test_get_port_units( self, configure ): units = 'C' xdc = xmlDeviceConfiguration() xdc.devices = {'device': {'port': {Constants.XbeeConfiguration.name: 'test', Constants.XbeeConfiguration.units: units}}} self.assertEqual( xdc.get_port_units( 'device', 'port' ), units )
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 __init__( self, input_queue ): ''' Constructor ''' super( ProcessInput, self ).__init__() self.__input_queue = input_queue self.devices = xmlDeviceConfiguration() self.commands = {Constants.EnvelopeTypes.XBEE: ProcessXBeeInput( self.devices ), Constants.EnvelopeTypes.COMMAND: ProcessCommandInput( self.devices ), Constants.EnvelopeTypes.STATUS: ProcessStatusRequests( self.devices )}
def __init__(self, input_queue): ''' Constructor ''' super(ProcessInput, self).__init__() self.__input_queue = input_queue self.devices = xmlDeviceConfiguration() self.commands = { Constants.EnvelopeTypes.XBEE: ProcessXBeeInput(self.devices), Constants.EnvelopeTypes.COMMAND: ProcessCommandInput(self.devices), Constants.EnvelopeTypes.STATUS: ProcessStatusRequests(self.devices) }
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_process_configuration( self, configure ): expected_config = {'0x13a200409029bf': {'dio-0': {'cosm_channel': '1', 'description': 'Monitors whether the garage door is open or closed.', 'name': 'Garage Door Monitor', 'network_address': '0xf9f2', 'steps': ['step.garage_door_state', 'step.CurrentValue', 'step.onBooleanChange', 'outputs.COSM']}, 'name': 'Garage Door XBee Monitor', 'network_address': '0xf9f2'}} self.maxDiff = None xdc = xmlDeviceConfiguration() root = ET.fromstring( xml ) config = xdc.process_configuration( root ) self.assertEqual( config, expected_config )
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 )
def test_logger_name( self, configure ): x = xmlDeviceConfiguration() self.assertEqual( x.logger_name, "configuration" )
def test_get_source_address_with_invalid_device( self, configure ): xdc = xmlDeviceConfiguration() xdc.devices = {'device': {Constants.XbeeConfiguration.name: 'test', Constants.XbeeConfiguration.source_address: 'address'}} with self.assertRaisesRegexp( InvalidDeviceError, 'Invalid device (.*)' ): xdc.get_source_address( 'device-1' )
def test_get_network_address( self, configure ): xdc = xmlDeviceConfiguration() xdc.devices = {'device': {Constants.XbeeConfiguration.network_address: 'test'}} self.assertEqual( xdc.get_network_address( 'device' ), 'test' )
def test_get_steps_with_invalid_option( self, configure ): xdc = xmlDeviceConfiguration() xdc.devices = {'device': {'port': {Constants.XbeeConfiguration.description: 'test'}}} with self.assertRaisesRegexp( InvalidConfigurationOptionError, 'Required configuration option not present (.*) for device(.*) port (.*)' ): xdc.get_steps( 'device', 'port' )
def test_get_steps_with_invalid_port( self, configure ): xdc = xmlDeviceConfiguration() xdc.devices = {'device': {'port': {Constants.XbeeConfiguration.name: 'test'}}} with self.assertRaisesRegexp( InvalidPortError, 'Invalid port \(port-1\)' ): xdc.get_steps( 'device', 'port-1' )
def test_get_steps_with_invalid_device( self, configure ): xdc = xmlDeviceConfiguration() xdc.devices = {'device': {Constants.XbeeConfiguration.name: 'test'}} with self.assertRaisesRegexp( InvalidDeviceError, 'Invalid device (.*)' ): xdc.get_steps( 'device-1', 'port' )
def test_get_network_address_with_no_name_device( self, configure ): xdc = xmlDeviceConfiguration() xdc.devices = {'device': {Constants.XbeeConfiguration.description: 'test'}} with self.assertRaisesRegexp( InvalidConfigurationOptionError, 'Required configuration option not present (.*) for device(.*) port (.*)' ): xdc.get_network_address( device='device' )
def test_get_port_name( self, configure ): xdc = xmlDeviceConfiguration() xdc.devices = {'device': {'port': {Constants.XbeeConfiguration.name: 'test'}}} self.assertSequenceEqual( xdc.get_port_name( 'device', 'port' ), 'test' )
def test_configuration_file_name( self, configure ): x = xmlDeviceConfiguration() self.assertEqual( x.configuration_file_name, 'configuration.xmlDeviceConfiguration' )
def test_get_source_address( self, configure ): xdc = xmlDeviceConfiguration() xdc.devices = {'device': {Constants.XbeeConfiguration.name: 'test', Constants.XbeeConfiguration.source_address: 'address'}} self.assertEqual( xdc.get_source_address( 'device' ), 'address' )
def test_in_valid_device( self, c ): xdc = xmlDeviceConfiguration() xdc.devices = {'device': {'port': 'a'}, 'device 1': {'port 1': 'b'}} with self.assertRaisesRegexp( InvalidDeviceError, 'device a' ): xdc.valid_device( 'device a' )
def test_valid_device( self, c ): xdc = xmlDeviceConfiguration() xdc.devices = {'device': {'port': 'a'}, 'device 1': {'port 1': 'b'}} device = xdc.valid_device( 'device' ) self.assertEqual( device, 'device' )
def test_get_port_type( self, configure ): xdc = xmlDeviceConfiguration() xdc.devices = {'device': {'port': {Constants.XbeeConfiguration.type: 'type'}}} self.assertEqual( xdc.get_port_type( 'device', 'port' ), 'type' )
def test_get_port_units_with_invalid_device( self, configure ): xdc = xmlDeviceConfiguration() xdc.devices = {'device': {'port': {Constants.XbeeConfiguration.units: 'test'}}} with self.assertRaisesRegexp( InvalidDeviceError, 'Invalid device \(.*\)' ): xdc.get_port_units( 'device-1', 'port' )
def test_configuration_topic_name( self, configure ): x = xmlDeviceConfiguration() self.assertEqual( x.configuration_topic_name, Constants.TopicNames.xmlDeviceConfiguration )
def test_get_port_description( self, configure ): xdc = xmlDeviceConfiguration() xdc.devices = {'device': {'port': {Constants.XbeeConfiguration.description: 'description'}}} self.assertEqual( xdc.get_port_description( 'device', 'port' ), 'description' )