I'm not sure what you mean by StdService. That's the abstract base class
all the services inherit from.

In any case, if a service is to augment a record, *it must check what unit
system the incoming record is in*, then convert what it is about to add to
that unit system. There are many utilities in weewx.units for doing this.
In particular, look at weewx.units.convertStd()
<https://github.com/weewx/weewx/blob/master/bin/weewx/units.py#L1297>.
Also, look at ValueTuples, also to be found in weewx.units.

Say you are about to add a wind speed that is m/s. It would look something
like this (NOT TESTED):

def new_archive_record(self, event):
    my_wind_speed =  (obtained from somewhere)
    # Create a Value Tuple:
    wind_speed_vt = weewx.units.ValueTuple(my_wind_speed,
'meter_per_second', 'group_speed')
    # Convert to the same unit system as the record
    wind_speed_converted_vt = weewx.units.convertStd(wind_speed_vt,
event.record['usUnits'})
    # Put the converted value into the record:
    event.record['windSpeedNetatmo'] = wind_speed_converted_vt.value



On Sun, Sep 27, 2020 at 9:33 AM flor...@pre-vost.fr <floren...@pre-vost.fr>
wrote:

> Hi,
>
> I work to implement a second data source with Netatmo Station and let the
> driver to the Davis Vantage Pro 2.
>
> But the new StdService can't convert US unit to my database unit (Database
> is set to Metric).
> I've set this on the top of my py file but the conversion doesn't work :
>
> import weewx.units
> from weewx.engine import StdService
>
> weewx.units.obs_group_dict['windSpeedNetatmo'] = 'group_speed'
> weewx.units.obs_group_dict['windGustNetatmo'] = 'group_speed'
> weewx.units.obs_group_dict['rainNetatmo'] = 'group_rain'
> weewx.units.obs_group_dict['windGustDirNetatmo'] = 'group_direction'
> weewx.units.obs_group_dict['windDirNetatmo'] = 'group_direction'
> weewx.units.obs_group_dict['barometerNetatmo'] = 'group_pressure'
> weewx.units.obs_group_dict['outTempNetatmo'] = 'group_temperature'
> weewx.units.obs_group_dict['datetimeNetatmo'] = 'group_time'
>
> The StdService can convert unit or not ?
>
> Thank's a lot.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "weewx-development" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to weewx-development+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/weewx-development/18d0423d-2722-46f3-a834-9516e3a008d0n%40googlegroups.com
> <https://groups.google.com/d/msgid/weewx-development/18d0423d-2722-46f3-a834-9516e3a008d0n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"weewx-development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to weewx-development+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/weewx-development/CAPq0zECJsGNcmDRR3gYeHwefna1az-YCQGuFZvH8zjDc%3DM83Sw%40mail.gmail.com.

Reply via email to