Skip to content

Commit

Permalink
Add history data parsing
Browse files Browse the repository at this point in the history
History data contains min/max temperature and humidity for each hour.
  • Loading branch information
gdyuldin committed Feb 1, 2020
1 parent 6474e2f commit 37fd795
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lywsd02/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def __init__(self, mac, notification_timeout=5.0):
self._handles = {}
self._tz_offset = None
self._data = SensorData(None, None)
self._history_data = collections.OrderedDict()
self._connected = False

@contextlib.contextmanager
Expand Down Expand Up @@ -125,6 +126,10 @@ def tz_offset(self):
def tz_offset(self, tz_offset: int):
self._tz_offset = tz_offset

@property
def history_data(self):
self.get_history_data()
return self._history_data

def _get_sensor_data(self):
with self.connect():
Expand Down Expand Up @@ -164,5 +169,9 @@ def _process_sensor_data(self, data):
self._data = SensorData(temperature=temperature, humidity=humidity)

def _process_history_data(self, data):
# TODO: Process history data
print(data)
(id, ts, max_temp, max_hum, min_temp, _, min_hum) = struct.unpack_from(
'IIHBBBB', data)
ts = datetime.fromtimestamp(ts)
max_temp /= 10
min_temp /= 10
self._history_data[id] = [ts, max_temp, max_hum, min_temp, min_hum]

0 comments on commit 37fd795

Please sign in to comment.