stijnstijn / pyaranet4

A cross-platform Python interface for the Aranet4 CO₂ meter
MIT License
47 stars 8 forks source link

pyaranet4 --history Invocation Raises ValueError Exception #3

Open max-franklin opened 1 year ago

max-franklin commented 1 year ago

Issue Summary:

pyaranet4 --history raises ValueError exception. See Issue Details section below for more information.

Python Version Details:

% python -VV
Python 3.10.8 (main, Oct 13 2022, 09:48:40) [Clang 14.0.0 (clang-1400.0.29.102)]

Aranet4 Sensor Details:

Firmware: v1.2.0
Smart Home Integration: enabled

Issue Details:

I am receiving a ValueError runtime exception when attempting to pull back history from my Aranet4:

% pyaranet4 --history
Traceback (most recent call last):
  File "/<redacted>/pyaranet4/.venv/bin/pyaranet4", line 8, in <module>
    sys.exit(main())
  File "/<redacted>/pyaranet4/.venv/lib/python3.10/site-packages/pyaranet4/__main__.py", line 56, in main
    collect_data(a4, args, sensors)
  File "/<redacted>/pyaranet4/.venv/lib/python3.10/site-packages/pyaranet4/__main__.py", line 114, in collect_data
    history = a4.get_history(sensors)
  File "/<redacted>/pyaranet4/.venv/lib/python3.10/site-packages/pyaranet4/pyaranet4.py", line 219, in get_history
    return self.loop.run_until_complete(self._get_history(sensors, start, end))
  File "/<redacted>/homebrew/Cellar/python@3.10/3.10.8/Frameworks/Python.framework/Versions/3.10/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
    return future.result()
  File "/<redacted>/pyaranet4/.venv/lib/python3.10/site-packages/pyaranet4/pyaranet4.py", line 410, in _get_history
    index_map[max(self._datapoints)] = last_timestamp
ValueError: max() arg is an empty sequence
% 

I can pull back the most recent measurement without issue using pyaranet4:

% pyaranet4    
--------------------------------------
Connected: Aranet4 03263 | v0.4.10
Updated 40 s ago. Intervals: 60 s
5040 total readings
--------------------------------------
CO2:         846 ppm
Temperature: 20.00 C
Humidity:    32 %
Pressure:    980.50 hPa
Battery:     33 %
--------------------------------------

But for some reason when I pass the --history flag, I get the ValueError exception. Based on the detail message max() arg is an empty sequence, I wonder if self._datapoints isn't getting set for some reason.

Desired Resolution:

Can you provide any guidance on why I might be receiving this error, and how to resolve it?

Please let me know if I can provide any additional details!