Skip to content
This repository was archived by the owner on Jan 31, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyvantagepro/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
from .logger import LOGGER, active_logger
from .device import VantagePro2

VERSION = '0.3.3dev'
VERSION = '0.3.4dev'
__version__ = VERSION
15 changes: 11 additions & 4 deletions pyvantagepro/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,28 @@ class VantagePro2(object):
ESC = '\x1b'
OK = '\n\rOK\n\r'

def __init__(self, link):
RAIN_COLLECTOR_UNITS = {
0x00: 0.01, # inch
0x10: 0.2, # millimeter
0x20: 0.1, # millimeter
}

def __init__(self, link, rain_collector_unit=0.01):
self.link = link
self.link.open()
self.rain_collector_unit = rain_collector_unit
self._check_revision()

@classmethod
def from_url(cls, url, timeout=10):
def from_url(cls, url, timeout=10, rain_collector_unit=0.01):
''' Get device from url.

:param url: A `PyLink` connection URL.
:param timeout: Set a read timeout value.
'''
link = link_from_url(url)
link.settimeout(timeout)
return cls(link)
return cls(link, rain_collector_unit)

@classmethod
def from_serial(cls, tty, baud, timeout=10):
Expand Down Expand Up @@ -170,7 +177,7 @@ def get_current_data(self):
self.send("LOOP 1", self.ACK)
current_data = self.link.read(99)
if self.RevB:
return LoopDataParserRevB(current_data, datetime.now())
return LoopDataParserRevB(current_data, datetime.now(), self.rain_collector_unit)
else:
raise NotImplementedError('Do not support RevB data format')

Expand Down
12 changes: 6 additions & 6 deletions pyvantagepro/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,20 +145,20 @@ class LoopDataParserRevB(DataParser):
('SunSet', 'H'), ('EOL', '2s'), ('CRC', 'H'),
)

def __init__(self, data, dtime):
def __init__(self, data, dtime, rain_collector_unit=0.01):
super(LoopDataParserRevB, self).__init__(data, self.LOOP_FORMAT)
self['Datetime'] = dtime
self['Barometer'] = self['Barometer'] / 1000
self['TempIn'] = self['TempIn'] / 10
self['TempOut'] = self['TempOut'] / 10
self['RainRate'] = self['RainRate'] / 100
self['RainStorm'] = self['RainStorm'] / 100
self['RainRate'] = self['RainRate'] * rain_collector_unit
self['RainStorm'] = self['RainStorm'] * rain_collector_unit
# Given a packed storm date field, unpack and return date
self['StormStartDate'] = self.unpack_storm_date()
# rain totals
self['RainDay'] = self['RainDay'] / 100
self['RainMonth'] = self['RainMonth'] / 100
self['RainYear'] = self['RainYear'] / 100
self['RainDay'] = self['RainDay'] * rain_collector_unit
self['RainMonth'] = self['RainMonth'] * rain_collector_unit
self['RainYear'] = self['RainYear'] * rain_collector_unit
# evapotranspiration totals
self['ETDay'] = self['ETDay'] / 1000
self['ETMonth'] = self['ETMonth'] / 100
Expand Down