libhueble icon indicating copy to clipboard operation
libhueble copied to clipboard

Always getting EOFError when trying to turn on the bulb

Open Refuhr opened this issue 2 years ago • 0 comments

My setup: Rpi0 W, Philips Hue white GU10 (paired and trusted via bluetoothctl) My script:

import libhueble
import asyncio

async def main():
    lamp = libhueble.Lamp('C1:14:8A:F4:FA:CC')
    await lamp.connect()
    print('Connected.')
    try:
        await lamp.set_power(True)
        await lamp.set_brightness(1.0)
        # await lamp.set_color_rgb(1.0, 0.0, 0.0)
    finally:
        await lamp.disconnect()

asyncio.run(main())

Error:

Traceback (most recent call last):
  File "/home/pi/libhueble/src/test.py", line 15, in <module>
    asyncio.run(main())
  File "/usr/lib/python3.9/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
    return future.result()
  File "/home/pi/libhueble/src/test.py", line 9, in main
    await lamp.set_power(True)
  File "/home/pi/libhueble/src/libhueble.py", line 52, in set_power
    await self.client.write_gatt_char(CHAR_POWER, bytes([1 if on else 0]), response=True)
  File "/home/pi/.local/lib/python3.9/site-packages/bleak/backends/bluezdbus/client.py", line 707, in write_gatt_char
    reply = await self._bus.call(
  File "/home/pi/.local/lib/python3.9/site-packages/dbus_fast/aio/message_bus.py", line 337, in call
    await future
  File "/home/pi/.local/lib/python3.9/site-packages/dbus_fast/aio/message_bus.py", line 404, in _message_reader
    if self._unmarshaller.unmarshall():
  File "/home/pi/.local/lib/python3.9/site-packages/dbus_fast/_private/unmarshaller.py", line 332, in unmarshall
    self._read_header()
  File "/home/pi/.local/lib/python3.9/site-packages/dbus_fast/_private/unmarshaller.py", line 271, in _read_header
    self.read_to_offset(HEADER_SIGNATURE_SIZE)
  File "/home/pi/.local/lib/python3.9/site-packages/dbus_fast/_private/unmarshaller.py", line 174, in read_to_offset
    raise EOFError()
EOFError

a part of unmarshaller.py:

def read_to_offset(self, offset: int) -> None:
        """
        Read from underlying socket into buffer.

        Raises MarshallerStreamEndError if there is not enough data to be read.

        :arg offset:
            The offset to read to. If not enough bytes are available in the
            buffer, read more from it.

        :returns:
            None
        """
        start_len = len(self.buf)
        missing_bytes = offset - (start_len - self.offset)
        if self.sock is None:
            data = self.stream.read(missing_bytes)
        else:
            data = self.read_sock(missing_bytes)
        if data == b"":
            raise EOFError()

This seems to be indicating that the pi can't read data from the bulb?! I'm not sure what I did wrong here. Help is appreciated.

Refuhr avatar Sep 14 '22 10:09 Refuhr