core: OneWireDirect crash if senor disconected

The problem

If DS18S20 is disconnected class OneWireDirect(OneWire) throws exception

Environment

  • Home Assistant Core release with the issue: 0.115.3.
  • Last working Home Assistant Core release (if known):
  • Operating environment (OS/Container/Supervised/Core): RPI2, Docker
  • Integration causing this issue: OneWire with Direct RPI-IO
  • Link to integration documentation on our website: https://www.home-assistant.io/integrations/onewire/

Problem-relevant configuration.yaml

sensor:
  - platform: onewire

Traceback/Error logs

2020-09-29 21:53:12 ERROR (MainThread) [homeassistant.components.sensor] onewire: Error on device update!
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 346, in _async_add_entity
    await entity.async_device_update(warning=False)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 471, in async_device_update
    await self.hass.async_add_executor_job(self.update)  # type: ignore
  File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/onewire/sensor.py", line 296, in update
    while lines[0].strip()[-3:] != "YES":
IndexError: list index out of range

Additional information

If the DS18S20 is disconnected reading the /sys/bus/w1/devices/28-xxxxxxxxxxxx/w1_slave returns an empty list object. Placing a “if len(lines) > 1:” condition before “while lines[0].strip()[-3:] != “YES”:” fixes the problem.

Actually I came across the problem on startup inside Docker on RPI2 with a fully featured Raspbian. It seams that there is an initialization problem when starting the container, so the first read to w1_slave is always empty (as if sensor would be disconnected). If adding a few second sleep before doing the first reed also fixes the issue.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 17 (11 by maintainers)

Most upvoted comments

New branch available for testing on https://github.com/epenet/home-assistant/tree/onewire-sysbus I look forward to your feedback…