RedMeKool / HA-Raspberry-pi-GPIO-PWM

Home Assistant component rpi_gpio_pwm as a custom component
MIT License
34 stars 12 forks source link

Broken Pipe if RPI loses connection #35

Closed patchido closed 6 months ago

patchido commented 7 months ago

System Health details

System Information

version core-2024.2.1
installation_type Home Assistant OS
dev false
hassio true
docker true
user root
virtualenv false
python_version 3.12.1
os_name Linux
os_version 6.1.74-haos
arch x86_64
timezone America/Mexico_City
config_dir /config
Home Assistant Community Store GitHub API | ok -- | -- GitHub Content | ok GitHub Web | ok GitHub API Calls Remaining | 5000 Installed Version | 1.34.0 Stage | running Available Repositories | 1464 Downloaded Repositories | 14 HACS Data | ok
Home Assistant Cloud logged_in | false -- | -- can_reach_cert_server | ok can_reach_cloud_auth | ok can_reach_cloud | ok
Home Assistant Supervisor host_os | Home Assistant OS 11.5 -- | -- update_channel | stable supervisor_version | supervisor-2024.01.1 agent_version | 1.6.0 docker_version | 24.0.7 disk_total | 228.5 GB disk_used | 49.0 GB healthy | true supported | true board | generic-x86-64 supervisor_api | ok version_api | ok installed_addons | eWeLink Smart Home (1.4.3), Terminal & SSH (9.9.0), Docker Wyze Bridge (2.7.0), Mosquitto broker (6.4.0), AC MQTT proxy for home assistant (0.6.2), ESPHome (2023.12.9), Cloudflared (5.1.3), File editor (5.8.0), UniFi Network Application (3.0.3), AdGuard Home (5.0.3), RPC Shutdown (2.4), Frigate (0.13.1)
Dashboards dashboards | 1 -- | -- resources | 5 views | 3 mode | storage
Recorder oldest_recorder_run | February 3, 2024 at 9:24 PM -- | -- current_recorder_run | February 12, 2024 at 11:06 PM estimated_db_size | 164.31 MiB database_engine | sqlite database_version | 3.44.2
Sonoff version | 3.5.4 (a4a8c5f) -- | -- cloud_online | 1 / 1 local_online | 1 / 1

Checklist

Describe the issue

My raspberry isnt the host of HA, so im using this as remote.

Whenever the RPI reboots, or disconects for a moment on the network HA will just answer back broken pipe, seems as if the component has no reconnect.

Reproduction steps

1.Install component

  1. Add entity
  2. Use entity (works)
  3. Disconnect or reboot RPI
  4. Try and use entity again

Debug logs


Logger: homeassistant.components.websocket_api.http.connection
Source: components/websocket_api/commands.py:240
Integration: Home Assistant WebSocket API (documentation, issues)
First occurred: 11:44:56 PM (1 occurrences)
Last logged: 11:44:56 PM

[140402200715584] unpack requires a buffer of 16 bytes
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 240, in handle_call_service
    response = await hass.services.async_call(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2279, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2316, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 892, in entity_service_call
    single_response = await _handle_entity_call(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 962, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/light/__init__.py", line 628, in async_handle_light_on_service
    await light.async_turn_on(**filter_turn_on_params(light, params))
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1615, in async_turn_on
    await self.hass.async_add_executor_job(ft.partial(self.turn_on, **kwargs))
  File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/rpi_gpio_pwm/light.py", line 134, in turn_on
    self._led.value = _from_hass_brightness(self._brightness)
    ^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/gpiozero/devices.py", line 132, in __setattr__
    return super(GPIOBase, self).__setattr__(name, value)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/gpiozero/output_devices.py", line 448, in value
    self._write(value)
  File "/usr/local/lib/python3.12/site-packages/gpiozero/output_devices.py", line 435, in _write
    super(PWMOutputDevice, self)._write(value)
  File "/usr/local/lib/python3.12/site-packages/gpiozero/output_devices.py", line 96, in _write
    self.pin.state = self._value_to_state(value)
    ^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/gpiozero/pins/__init__.py", line 285, in <lambda>
    lambda self, value: self._set_state(value),
                        ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/gpiozero/pins/pigpio.py", line 244, in _set_state
    value = int(value * self.factory.connection.get_PWM_range(self.number))
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pigpio.py", line 1543, in get_PWM_range
    return _u2i(_pigpio_command(self.sl, _PI_CMD_PRG, user_gpio, 0))
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pigpio.py", line 1026, in _pigpio_command
    dummy, res = struct.unpack('12sI', sl.s.recv(_SOCK_CMD_LEN))
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
struct.error: unpack requires a buffer of 16 bytes

Logger: homeassistant.components.websocket_api.http.connection
Source: components/websocket_api/commands.py:240
Integration: Home Assistant WebSocket API (documentation, issues)
First occurred: 11:45:00 PM (21 occurrences)
Last logged: 11:47:52 PM

[140402200715584] [Errno 32] Broken pipe
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 240, in handle_call_service
    response = await hass.services.async_call(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2279, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2316, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 892, in entity_service_call
    single_response = await _handle_entity_call(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 962, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/light/__init__.py", line 628, in async_handle_light_on_service
    await light.async_turn_on(**filter_turn_on_params(light, params))
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1615, in async_turn_on
    await self.hass.async_add_executor_job(ft.partial(self.turn_on, **kwargs))
  File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/rpi_gpio_pwm/light.py", line 134, in turn_on
    self._led.value = _from_hass_brightness(self._brightness)
    ^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/gpiozero/devices.py", line 132, in __setattr__
    return super(GPIOBase, self).__setattr__(name, value)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/gpiozero/output_devices.py", line 448, in value
    self._write(value)
  File "/usr/local/lib/python3.12/site-packages/gpiozero/output_devices.py", line 435, in _write
    super(PWMOutputDevice, self)._write(value)
  File "/usr/local/lib/python3.12/site-packages/gpiozero/output_devices.py", line 96, in _write
    self.pin.state = self._value_to_state(value)
    ^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/gpiozero/pins/__init__.py", line 285, in <lambda>
    lambda self, value: self._set_state(value),
                        ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/gpiozero/pins/pigpio.py", line 244, in _set_state
    value = int(value * self.factory.connection.get_PWM_range(self.number))
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pigpio.py", line 1543, in get_PWM_range
    return _u2i(_pigpio_command(self.sl, _PI_CMD_PRG, user_gpio, 0))
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pigpio.py", line 1025, in _pigpio_command
    sl.s.send(struct.pack('IIII', cmd, p1, p2, 0))
BrokenPipeError: [Errno 32] Broken pipe

Diagnostics dump

No response

RedMeKool commented 6 months ago

I have no clue how to fix this. I only use RPI as the host of HA and have not seen this behaviour