def get_device_settings(self, address): # Compute ASCII representation of device address. address = OneWireBus.device_address_ascii(address) # Get device-specific settings from configuration. for device_settings in self.settings.get('devices', []): if device_settings['address'] == address: return device_settings return {}
def read_devices(self): """ :param devices: """ data = {} devices = self.get_effective_devices() for device in devices: address = OneWireBus.device_address_ascii(device) log.info('Reading DS18X20 device "{}"'.format(address)) try: value = self.driver.read_temp(device) except Exception as ex: log.exc(ex, "Reading DS18X20 device {} failed".format(address)) continue # Evaluate device response. if value is not None: # TODO: Mask power-on reset value 0550h (85°) here. # https://github.com/micropython/micropython/pull/5338 # Maybe it's not only 85°. Sometimes it's also 25°(!). # https://github.com/cpetrich/counterfeit_DS18B20 try: # Compute telemetry field name. fieldname = self.format_fieldname('temperature', address) # Apply value offset. offset = self.get_setting(address, 'offset') if offset is not None: log.info( 'Adding offset {} to value {} from device "{}"'. format(offset, value, address)) value += offset # Add value to telemetry message. data[fieldname] = value except Exception as ex: log.exc( ex, 'Processing data from DS18X20 device "{}" failed'. format(address)) continue else: log.warning( 'No response from DS18X20 device "{}"'.format(address)) return data
def read_devices(self): """ :param devices: """ data = {} devices = self.get_effective_devices() for device in devices: address = OneWireBus.device_address_ascii(device) log.info('Reading DS18X20 device "{}"'.format(address)) try: value = self.driver.read_temp(device) except Exception as ex: log.exc(ex, "Reading DS18X20 device {} failed".format(address)) continue # Evaluate device response. if value is not None: # TODO: Filter the 85° thing here. try: # Compute telemetry field name. fieldname = self.format_fieldname('temperature', address) # Apply value offset. offset = self.get_setting(address, 'offset') if offset is not None: log.info( 'Adding offset {} to value {} from device "{}"'. format(offset, value, address)) value += offset # Add value to telemetry message. data[fieldname] = value except Exception as ex: log.exc( ex, 'Processing data from DS18X20 device "{}" failed'. format(address)) continue else: log.warning( 'No response from DS18X20 device "{}"'.format(address)) return data
def get_effective_devices(self): """ """ log.info('Start conversion for DS18X20 devices on bus "{}"'.format(self.bus.name)) effective_devices = [] for device in self.bus.devices: address = OneWireBus.device_address_ascii(device) device_settings = self.get_device_settings(address) enabled = device_settings.get('enabled') if enabled is False: log.info('Skipping DS18X20 device "{}"'.format(address)) continue effective_devices.append(device) return effective_devices
def read_devices(self, devices): data = {} for device in devices: address = OneWireBus.device_address_ascii(device) log.info('Reading DS18X20 device "{}"'.format(address)) try: value = self.driver.read_temp_async(device) except: log.exception( "Reading DS18X20 device {} failed".format(address)) continue # Evaluate device response. if value is not None: try: # Compute telemetry field name. fieldname = self.format_fieldname('temperature', address) # Apply value offset. offset = self.get_setting(address, 'offset') if offset is not None: log.info( 'Adding offset {} to value {} from device "{}"'. format(offset, value, address)) value += offset # Add value to telemetry message. data[fieldname] = value except: log.exception( 'Processing data from DS18X20 device "{}" failed'. format(address)) continue else: log.warning( 'No response from DS18X20 device "{}"'.format(address)) return data