stijnstijn / pyaranet4

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

Failed to read temperature, humidity, co2, pressure #4

Open JulyIghor opened 1 year ago

JulyIghor commented 1 year ago

pyaranet4 --history works as expected, but pyaranet4 produces the error:

--------------------------------------
Connected: Aranet4 1BAE8 | v0.4.14
Updated 20 s ago. Intervals: 60 s
249 total readings
--------------------------------------
Traceback (most recent call last):
  File "/home/ighor/.local/lib/python3.10/site-packages/pyaranet4/pyaranet4.py", line 477, in _read_value
    value = await self._client.read_gatt_char(uuid)
  File "/home/ighor/.local/lib/python3.10/site-packages/bleak/__init__.py", line 571, in read_gatt_char
    return await self._backend.read_gatt_char(char_specifier, **kwargs)
  File "/home/ighor/.local/lib/python3.10/site-packages/bleak/backends/bluezdbus/client.py", line 679, in read_gatt_char
    assert_reply(reply)
  File "/home/ighor/.local/lib/python3.10/site-packages/bleak/backends/bluezdbus/utils.py", line 20, in assert_reply
    raise BleakDBusError(reply.error_name, reply.body)
bleak.exc.BleakDBusError: [org.bluez.Error.NotPermitted] Read not permitted

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/ighor/.local/bin/pyaranet4", line 8, in <module>
    sys.exit(main())
  File "/home/ighor/.local/lib/python3.10/site-packages/pyaranet4/__main__.py", line 61, in main
    basic_overview(a4)
  File "/home/ighor/.local/lib/python3.10/site-packages/pyaranet4/__main__.py", line 76, in basic_overview
    print("CO2:         {:d} ppm".format(a4.current_readings.co2))
  File "/home/ighor/.local/lib/python3.10/site-packages/pyaranet4/pyaranet4.py", line 155, in current_readings
    return self._get_readings(simple=False)
  File "/home/ighor/.local/lib/python3.10/site-packages/pyaranet4/pyaranet4.py", line 284, in _get_readings
    data = self.read_from_uuid(uuid)
  File "/home/ighor/.local/lib/python3.10/site-packages/pyaranet4/pyaranet4.py", line 230, in read_from_uuid
    value = self.loop.run_until_complete(self._read_value(uuid))
  File "/usr/lib/python3.10/asyncio/base_events.py", line 646, in run_until_complete
    return future.result()
  File "/home/ighor/.local/lib/python3.10/site-packages/pyaranet4/pyaranet4.py", line 479, in _read_value
    raise Aranet4UnpairedException("Error reading from device. Check if it is properly paired.")
pyaranet4.exceptions.Aranet4UnpairedException: Error reading from device. Check if it is properly paired.
JulyIghor commented 1 year ago

The problem appears because if UUID_CURRENT_READING_FULL requested it produces "Failed to read: org.bluez.Error.NotPermitted", when UUID_CURRENT_READING_SIMPLE forced everything works fine. Possible solution is fallback to UUID_CURRENT_READING_SIMPLE when UUID_CURRENT_READING_FULL failed.