Skip to content

Commit 7e1093d

Browse files
authored
Improve log messages (#35)
* Update log messages, remove dead code * Update log messages * Update log messages * Update log messages * More log message improvements * More log message improvements * More log message improvements * More log message improvements
1 parent 8cad1c2 commit 7e1093d

File tree

4 files changed

+35
-34
lines changed

4 files changed

+35
-34
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ The following table outlines the `weewx.conf` station variables.
3232
| api_url | Ambient Weather API endpoint. You probably don't need to change this. |
3333
| api_app_key | API Application Key from your ambientweather.net [website](https://ambientweather.docs.apiary.io/#) |
3434
| api_key | API Key from your ambientweather.net [website](https://ambientweather.docs.apiary.io/#) |
35-
| use_meteobridge | Set to `True` if using Meteobridge, `False` is the default or leave commented out |
36-
| station_mac | Specify a specific station MAC address to return data. If blank or unspecified, then the first station in the list is returned. |
3735
| hardware | String to identify the hardware used |
3836
| driver | Don't change this value |
37+
| aw_debug | Optional: Set to `1` to get verbose output from the Ambient API. The default value is `0` |
38+
| use_meteobridge | Optional: Set to `True` if using Meteobridge, `False` is the default or leave commented out |
39+
| station_mac | Optional: Specify a specific station MAC address to return data. If blank or unspecified, then the first station in the list is returned. |

bin/user/ambientweatherapi.py

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from os import path
2020

2121
DRIVER_NAME = 'ambientweatherapi'
22-
DRIVER_VERSION = '0.0.13'
22+
DRIVER_VERSION = '0.0.14'
2323
log = logging.getLogger(__name__)
2424

2525

@@ -32,15 +32,13 @@ class AmbientWeatherAPI(weewx.drivers.AbstractDevice):
3232
"""Custom driver for Ambient Weather API."""
3333

3434
def __init__(self, **stn_dict):
35+
log.info('Starting: %s, version: %s' % (DRIVER_NAME, DRIVER_VERSION))
3536
rainfile = "%s_%s_rain.txt" % (DRIVER_NAME, DRIVER_VERSION)
36-
self.log_file = stn_dict.get('log_file', None)
3737
self.loop_interval = float(stn_dict.get('loop_interval', 60))
3838
self.api_url = stn_dict.get('api_url', 'https://api.ambientweather.net/v1')
3939
self.api_key = stn_dict.get('api_key')
4040
self.api_app_key = stn_dict.get('api_app_key')
4141
self.station_hardware = stn_dict.get('hardware', 'Undefined')
42-
self.safe_humidity = float(stn_dict.get('safe_humidity', 60))
43-
self.max_humidity = float(stn_dict.get('max_humidity', 38))
4442
self.use_meteobridge = bool(stn_dict.get('use_meteobridge', False))
4543
log.info('use_meteobridge: %s' % str(self.use_meteobridge))
4644
self.station_mac = stn_dict.get('station_mac', '')
@@ -51,7 +49,14 @@ def __init__(self, **stn_dict):
5149
log.info("Using Station MAC: %s" % self.station_mac)
5250
self.use_station_mac = True
5351
self.rainfilepath = os.path.join(tempfile.gettempdir(), rainfile)
54-
log.info('Starting: %s, version: %s' % (DRIVER_NAME, DRIVER_VERSION))
52+
self.aw_log_level = None
53+
self.aw_debug = int(stn_dict.get('aw_debug', 0))
54+
log.info('aw_debug: %s' % str(self.aw_debug))
55+
if self.aw_debug == 1:
56+
self.aw_log_level = "info"
57+
log.info('aw_log_level: %s' % str(self.aw_log_level))
58+
log.info('Using rain file: %s' % str(self.rainfilepath))
59+
log.info('Loaded: %s, version: %s' % (DRIVER_NAME, DRIVER_VERSION))
5560
log.debug("Exiting init()")
5661

5762
@property
@@ -66,23 +71,6 @@ def archive_interval1(self):
6671
log.debug("calling: archive_interval")
6772
return self.loop_interval
6873

69-
def calc_target_humidity(self, external_temp_f):
70-
"""Converts the optimal indoor humidity. Drop target humidity 5% for every 5degree C drop below 0"""
71-
external_temp_c = (external_temp_f - 32) * 5.0 / 9.0
72-
if external_temp_c >= 0:
73-
return self.max_humidity
74-
else:
75-
target = max(0, self.max_humidity + external_temp_c)
76-
if external_temp_c <= -15:
77-
target = target + 2.5
78-
if external_temp_c <= -20:
79-
target = target + 2.5
80-
if external_temp_c <= -25:
81-
target = target + 2.5
82-
if external_temp_c <= -30:
83-
target = target + 2.5
84-
return target
85-
8674
def convert_epoch_ms_to_sec(self, epoch_ms):
8775
"""Converts a epoch that's in ms to sec.
8876
AmbientAPI returns the epoch time in ms not sec"""
@@ -92,9 +80,10 @@ def convert_epoch_ms_to_sec(self, epoch_ms):
9280

9381
def print_dict(self, data_dict):
9482
"""Prints a dict."""
95-
log.debug("calling: print_dict")
96-
for key in data_dict:
97-
log.debug(key + " = " + str(data_dict[key]))
83+
if log.getEffectiveLevel() == logging.DEBUG:
84+
log.debug("calling: print_dict")
85+
for key in data_dict:
86+
log.debug(key + " = " + str(data_dict[key]))
9887

9988
def get_value(self, data_dict, key):
10089
"""Gets the value from a dict, returns None if the key does not exist."""
@@ -103,15 +92,15 @@ def get_value(self, data_dict, key):
10392

10493
def get_float(self, value):
10594
"""Checks if a value is not, if not it performs a converstion to a float()"""
106-
# log.debug("calling: get_float")
95+
log.debug("calling: get_float")
10796
if value is None:
10897
return value
10998
else:
11099
return float(value)
111100

112101
def get_battery_status(self, value):
113102
"""Converts the AM API battery status to somthing weewx likes."""
114-
# log.debug("calling: get_battery_status")
103+
log.debug("calling: get_battery_status")
115104
if value is None:
116105
return None
117106
if (value <= 0):
@@ -145,6 +134,14 @@ def check_rain_rate(self, dailyrainin):
145134
log.debug('No previous value found for rain, assuming interval of 0 and recording daily value')
146135
lastRain = dailyrainin
147136

137+
if dailyrainin is None:
138+
log.info("Daily rain (from API) is none, skipping calculation")
139+
return 0
140+
141+
if lastRain is None:
142+
log.info("Previous rain (from cache) is none, skipping calculation")
143+
return 0
144+
148145
log.debug('Reported daily rain: %s' % str(dailyrainin))
149146

150147
if lastRain > dailyrainin:
@@ -286,7 +283,8 @@ def genLoopPackets(self):
286283
# init the API
287284
weather = AmbientAPI(AMBIENT_ENDPOINT=self.api_url,
288285
AMBIENT_API_KEY=self.api_key,
289-
AMBIENT_APPLICATION_KEY=self.api_app_key)
286+
AMBIENT_APPLICATION_KEY=self.api_app_key,
287+
log_level=self.aw_log_level)
290288
log.debug("Init API call returned")
291289

292290
# get the first device
@@ -305,7 +303,7 @@ def genLoopPackets(self):
305303
log.debug('Searching for specific Station MAC')
306304
for device in devices:
307305
if device.mac_address == self.station_mac:
308-
log.info("Found station mac: %s" % self.station_mac)
306+
log.info("Using station mac: %s" % self.station_mac)
309307
data = device.last_data
310308
break
311309
else:
@@ -358,9 +356,9 @@ def genLoopPackets(self):
358356
else:
359357
_packet[key] = self.get_float(data[value])
360358
else:
361-
log.debug("Dropping Ambient value: '%s' from Weewx packet." % (value))
359+
log.info("Weewx value: '%s' not found in AW JSON packet." % (key))
362360

363-
# self.print_dict(_packet)
361+
self.print_dict(_packet)
364362
log.debug("============Completed Packet Build============")
365363
yield _packet
366364
log.info("loopPacket Accepted")

install.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def loader():
1010
class AmbientWeatherApiInstaller(ExtensionInstaller):
1111
def __init__(self):
1212
super(AmbientWeatherApiInstaller, self).__init__(
13-
version="0.0.13",
13+
version="0.0.14",
1414
name='ambientweatherapi',
1515
description='WeeWx AmbientWeather API Driver.',
1616
author="Karl Moos",

weewx.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
# The ObserverIP only pushes data every 60 seconds.
1111
loop_interval = 60
1212

13+
aw_debug = 0
14+
1315
#URL to the Ambient Weather API
1416
api_url = 'https://api.ambientweather.net/v1'
1517

0 commit comments

Comments
 (0)