allenporter/pyrainbird

Feature request: Add support for more than 16 Zones

Opened this issue · 2 comments

I currently have 18 zones at my home. Rainbird controllers can support 22 stations. Under issue #15, the limit was 8 and they requested it updated to 16, but unsure if that change caused the limit. If so - would you mind updating the limit to 22? Here's the error I see in the logs. Home Assistant is loading the first 16 stations then I believe throwing this error that it failed due to the index out of range on self.states.

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 359, in _async_add_entity
    await entity.async_device_update(warning=False)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 466, in async_device_update
    await task
  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/rainbird/switch.py", line 105, in update
    self._state = self._rainbird.get_zone_state(self._zone)
  File "/usr/local/lib/python3.8/site-packages/pyrainbird/__init__.py", line 125, in get_zone_state
    return self.zones.active(zone)
  File "/usr/local/lib/python3.8/site-packages/pyrainbird/data.py", line 104, in active
    return self.states[number - 1]
IndexError: tuple index out of range

I was just looking at this myself as our system has cray numbering and the last station is station 17 despite having only 11 zones. If you change line 223 of _ ini_.py from
lambda resp: States((mask % resp["activeStations"])[:4]), to
lambda resp: States((mask % resp["activeStations"])[:6]),
and line 92 of data.py from
def init(self, mask="0000"):
def init(self, mask="000000"):
this fixes the issue on my Home Assistant setup

@idoc69 would you be able to enable debug logging and record the response from the server with the active stations in it? I think that would increase our confidence about ability to have tests for this case to ensure it works going forward.