@@ -86,6 +86,7 @@ def __init__(self, device, sensor_count=1):
8686 if self ._ports == None :
8787 self ._ports = find_ports (device )
8888 self .set_calibration_data ()
89+ self .set_sensor_count (self .lookup_sensor_count ())
8990 LOGGER .debug ('Found device | Bus:{0} Ports:{1}' .format (
9091 self ._bus , self ._ports ))
9192
@@ -119,6 +120,35 @@ def set_calibration_data(self, scale=None, offset=None):
119120 else :
120121 raise RuntimeError ("Must set both scale and offset, or neither" )
121122
123+ def lookup_offset (self , sensor ):
124+ """
125+ Lookup the number of sensors on the device by product name.
126+ """
127+ if self ._device .product == 'TEMPer1F_V1.3' :
128+ # Has only 1 sensor, and it's at offset = 4
129+ return 4
130+
131+ # All others follow this pattern - if not, contribute here: https://github.com/padelt/temper-python/issues
132+ # Sensor 0 = Offset 2
133+ # Sensor 1 = Offset 4
134+ return (sensor + 1 ) * 2
135+
136+ def lookup_sensor_count (self ):
137+ """
138+ Lookup the number of sensors on the device by product name.
139+ """
140+ if self ._device .product == 'TEMPer1F_V1.3' :
141+ return 1
142+
143+ # All others are two - if not the case, contribute here: https://github.com/padelt/temper-python/issues
144+ return 2
145+
146+ def get_sensor_count (self ):
147+ """
148+ Get number of sensors on the device.
149+ """
150+ return self ._sensor_count
151+
122152 def set_sensor_count (self , count ):
123153 """
124154 Set number of sensors on the device.
@@ -127,7 +157,7 @@ def set_sensor_count(self, count):
127157 """
128158 # Currently this only supports 1 and 2 sensor models.
129159 # If you have the 8 sensor model, please contribute to the
130- # discussion here: https://github.com/padelt/temper-python/issues/19
160+ # discussion here: https://github.com/padelt/temper-python/issues
131161 if count not in [1 , 2 ,]:
132162 raise ValueError ('Only sensor_count of 1 or 2 supported' )
133163
@@ -261,7 +291,7 @@ def get_temperatures(self, sensors=None):
261291
262292 # Interpret device response
263293 for sensor in _sensors :
264- offset = (sensor + 1 ) * 2
294+ offset = self . lookup_offset (sensor )
265295 celsius = data [offset ] + data [offset + 1 ] / 256.0
266296 celsius = celsius * self ._scale + self ._offset
267297 results [sensor ] = {
0 commit comments