Exemplo n.º 1
0
def list_i2c_devices():
    i2c_devices_attached = []
    dev = atlas_i2c.AtlasI2C()
    for device in deviceName.keys():
        try:
            dev = atlas_i2c.AtlasI2C()
            dev.set_i2c_address(device)
            dev.read("R")
            i2c_devices_attached.append(device)
            print("Found " + str(deviceName[device]))
        except IOError:
            pass
    return i2c_devices_attached
Exemplo n.º 2
0
 def test_read(self, good_response, error_response, no_data_response,
               not_ready_response):
     for response in (good_response, error_response, no_data_response,
                      not_ready_response):
         device_file = io.BytesIO(response)
         dev = atlas_i2c.AtlasI2C(device_file=device_file)
         dev.address = 102
         response = dev.read(original_cmd="R")
         assert isinstance(response, atlas_i2c.CommandResponse)
Exemplo n.º 3
0
    def __init__(self,
                 name: str,
                 address: int = 102,
                 commands: List = None,
                 i2c_client=None):
        self.name = name
        self.address = address
        self.commands = commands
        self.client = i2c_client

        if not self.commands:
            self.commands = []

        if not self.client:
            self.client = atlas_i2c.AtlasI2C()
Exemplo n.º 4
0
 def test_query_with_args(self):
     device_file = io.BytesIO()
     i2c_client = atlas_i2c.AtlasI2C(device_file=device_file)
     i2c_client.query = Mock()
     response = atlas_i2c.CommandResponse()
     response.sensor_name = "test-sensor"
     response.sensor_address = 102
     response.original_command = "S,?"
     response.response_type = str
     response.response_data = "?S,c"
     i2c_client.query.return_value = response
     sensor = sensors.Sensor("test-sensor", i2c_client=i2c_client)
     result = sensor.query(commands.SCALE, arguments="?")
     assert isinstance(result, atlas_i2c.CommandResponse)
     assert result == response
Exemplo n.º 5
0
 def test_query_with_nonexisting_command(self):
     device_file = io.BytesIO()
     i2c_client = atlas_i2c.AtlasI2C(device_file=device_file)
     sensor = sensors.Sensor("test-sensor", i2c_client=i2c_client)
     with pytest.raises(AttributeError) as ex:
         sensor.query("eat")
Exemplo n.º 6
0
 def test_write(self, command):
     device_file = io.BytesIO()
     dev = atlas_i2c.AtlasI2C(device_file=device_file)
     dev.address = 102
     dev.write(command)