-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusePreferred.py
More file actions
57 lines (39 loc) · 1.81 KB
/
usePreferred.py
File metadata and controls
57 lines (39 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# -*- coding: utf-8 -*-
# See the file LICENSE.txt for your rights.
# Author: Michael Kainzbauer (github: mkainzbauer)
"""Prefers a reading over another, if reading is present
*******************************************************************************
To use this extension, add the following somewhere in your configuration file
weewx.conf:
[UsePreferred]
value1 = preferredValue1
value2 = preferredValue2
...
*******************************************************************************
To enable this service:
1) copy this file to the user directory
2) modify the weewx configuration file by adding this service to the option
"report_services", located in section [Engine][[Services]].
[Engine]
[[Services]]
...
data_services = user.usePreferred.UsePreferred # other services can be appended separated with a comma
*******************************************************************************
"""
import weewx, logging
from weewx.engine import StdService
log = logging.getLogger(__name__)
class UsePreferred(StdService):
def __init__(self, engine, config_dict):
# Initialize my superclass first:
super(UsePreferred, self).__init__(engine, config_dict)
# Bind to any new archive record events:
self.bind(weewx.NEW_ARCHIVE_RECORD, self.new_archive_record)
def new_archive_record(self, event):
for key in self.config_dict['UsePreferred']:
otherKey = self.config_dict['UsePreferred'][key]
if key in event.record:
log.debug("%s: %s" % (key,event.record[key]))
if otherKey in event.record:
log.debug("Replacing %s(%s) with %s(%s)" % (key, event.record[key], otherKey, event.record[otherKey]))
event.record[key] = event.record[otherKey]