Looks good, one thing you can do to make your code a little more readable is to make use the available properties of ValueTuple objects. weewx.units.convertStd returns an object of type ValueTuple. ValueTuple objects have 3 useful properties; .value, .unit and .group. In your code you could replace pres_tuple[0] with pres_tuple.value. Likewise temp_tuple. Will make no difference to the execution of your code but it does make is a bit more readable. If you are interested you can read about ValueTuple objects here <https://github.com/weewx/weewx/blob/master/bin/weewx/units.py#L414>.
Gary On Wednesday, 22 August 2018 20:04:11 UTC+10, David Moore wrote: > > So, thanks for all your help, here's what I finally have working. > > It's a little more generic, as in I can specify in weewx.conf where my BMP > library is, what my sea level modifier is, and where I want to store the > values, if at all > > weewx.conf > > [BMP280] > col_pres = pressure > col_temp = '' > sl_denominator = 0.8708 > BME280_lib_location = '/home/pi/git/Adafruit_Python_BME280' > > data_services = user.bmp280a.bmp > > > bmp280a.py > > import weewx > from weewx.engine import StdService > import sys > import syslog > > # Inherit from the base class StdService: > class bmp(StdService): > > def __init__(self, engine, config_dict): > # Pass the initialization information on to my superclass: > super(bmp, self).__init__(engine, config_dict) > > self.col_pres = config_dict['BMP280']['col_pres'] > self.col_temp = config_dict['BMP280']['col_temp'] > self.sl_denominator = float(config_dict['BMP280'][ > 'sl_denominator']) > self.BME280_lib_location = config_dict['BMP280'][ > 'BME280_lib_location'] > > # Bind to any new archive record events: > self.bind(weewx.NEW_ARCHIVE_RECORD, self.new_archive_packet) > > def new_archive_packet(self, event): > sys.path.insert(0, self.BME280_lib_location) > from Adafruit_BME280 import * > > sensor = BME280(t_mode=BME280_OSAMPLE_8, p_mode=BME280_OSAMPLE_8, > h_mode=BME280_OSAMPLE_8) > degrees = sensor.read_temperature() > pascals = sensor.read_pressure() > hectopascals = pascals / 100 > > ## convert to sea level pressure > ## relativePressure/(1-alt_in_meters/44330)^5.255 > ## > ## we can read altitude of station, convert to m, then run the > formala... > ## for now I can just hard code that I have to divide by value in > weewx.conf in my case > hectopascals = hectopascals/self.sl_denominator > > # pres_tuple = weewx.units.convertStd((hectopascals, "mbar", > "group_pressure"),weewx.US) > pres_tuple = weewx.units.convertStd((hectopascals, "mbar", > "group_pressure"), event.record['usUnits']) > temp_tuple = weewx.units.convertStd((degrees, "degree_C", > "group_temperature"), event.record['usUnits']) > > if self.col_pres: > event.record[self.col_pres] = pres_tuple[0] > if self.col_temp: > event.record[self.col_temp] = temp_tuple[0] > > > > > > > On Wednesday, 22 August 2018 00:12:24 UTC+2, gjr80 wrote: >> >> Generally speaking if your service is based on StdService and it's >> properly constructed then the 'event' parameter should have either >> event.packet or event.record (depending on whether it is bound to >> NEW_LOOP_PACKET or NEW_ARCHIVE_RECORD) which will give you access to the >> loop packet or event record just as Tim has done. There was no context in >> Tom's example and I suspect that is why there is the subtle difference. >> >> Gary >> >