siku2 / hass-dingz

Home Assistant support for dingz wall switches
MIT License
14 stars 5 forks source link

IndexError: list index out of range #9

Closed Sn00x closed 1 year ago

Sn00x commented 2 years ago

Thanks @siku2 for your effort for the dingz integration in Home Assistant - I think you make it easier for many people to configure these smart switches.

I use several switches in blind or mixed mode (light/blinds). After v0.1.5 caused problems with the indication of the entities, they get listed with v0.1.6, but the following errors still occur in the logfile:

Logger: homeassistant
Source: custom_components/dingz/light.py:102
Integration: dingz
First occurred: 17:00:08 (550 occurrences)
Last logged: 17:17:14

Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 134, in _handle_refresh_interval
    await self._async_refresh(log_failures=True, scheduled=True)
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 265, in _async_refresh
    update_callback()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 325, in _handle_coordinator_update
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 505, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 538, in _async_write_ha_state
    state = self._stringify_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 511, in _stringify_state
    if (state := self.state) is None:
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 935, in state
    return STATE_ON if self.is_on else STATE_OFF
  File "/config/custom_components/dingz/light.py", line 118, in is_on
    return self._dingz_dimmer.on
  File "/config/custom_components/dingz/light.py", line 102, in _dingz_dimmer
    return self._dingz_state.dimmers[self._index]
IndexError: list index out of range

The error counter increases steadily and relatively quickly.

A second error that is logged, which is also apparent, but occurs less frequently, but probably has the same cause:

Logger: homeassistant.components.websocket_api.http.connection
Source: custom_components/dingz/light.py:102
Integration: Home Assistant WebSocket API (documentation, issues)
First occurred: 17:11:33 (30 occurrences)
Last logged: 17:20:39

[547870231088] list index out of range
[547521979920] list index out of range
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 185, in handle_call_service
    await hass.services.async_call(
  File "/usr/src/homeassistant/homeassistant/core.py", line 1495, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1530, in _execute_service
    await handler.job.target(service_call)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 209, in handle_service
    await self.hass.helpers.service.entity_service_call(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 663, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 896, in async_request_call
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 700, in _handle_entity_call
    await result
  File "/usr/src/homeassistant/homeassistant/components/light/__init__.py", line 494, in async_handle_light_on_service
    await light.async_turn_on(**filter_turn_on_params(light, params))
  File "/config/custom_components/dingz/light.py", line 84, in async_turn_on
    await self.coordinator.async_request_refresh()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 141, in async_request_refresh
    await self._debounced_refresh.async_call()
  File "/usr/src/homeassistant/homeassistant/helpers/debounce.py", line 78, in async_call
    await task
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 165, in async_refresh
    await self._async_refresh(log_failures=True)
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 265, in _async_refresh
    update_callback()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 325, in _handle_coordinator_update
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 505, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 538, in _async_write_ha_state
    state = self._stringify_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 511, in _stringify_state
    if (state := self.state) is None:
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 935, in state
    return STATE_ON if self.is_on else STATE_OFF
  File "/config/custom_components/dingz/light.py", line 118, in is_on
    return self._dingz_dimmer.on
  File "/config/custom_components/dingz/light.py", line 102, in _dingz_dimmer
    return self._dingz_state.dimmers[self._index]
IndexError: list index out of range

It would be great if you could look over here again. Thanks!

siku2 commented 2 years ago

Please add the contents of the following endpoints:

where <HOST> can be the IP of your Dingz device.

The first endpoint is used by the integration to detect the configured dimmers and the latter is used to update their states. In your case, it seems like the first endpoint reports an amount of dimmers that isn't matched by the state updates -- hence, the index out of range error.

Sn00x commented 2 years ago

http://<HOST>/api/v1/dimmer_config content (same structure, independent of switch configuration):

{
   "dimmers":[
      {
         "output":"led",
         "name":"Ausgang",
         "feedback":null,
         "feedback_intensity":100
      },
      {
         "output":"led",
         "name":"Ausgang",
         "feedback":null,
         "feedback_intensity":100
      },
      {
         "output":"halogen",
         "name":"Ausgang",
         "feedback":null,
         "feedback_intensity":100
      },
      {
         "output":"halogen",
         "name":"Ausgang",
         "feedback":null,
         "feedback_intensity":100
      }
   ]
}

http://<HOST>/api/v1/state content of a switch in 2 lights and 1 blind configuration:

{
   "dimmers":[
      {
         "on":false,
         "output":0,
         "ramp":0,
         "readonly":false,
         "index":{
            "relative":0,
            "absolute":0
         }
      },
      {
         "on":true,
         "output":34,
         "ramp":5,
         "readonly":false,
         "index":{
            "relative":1,
            "absolute":1
         }
      }
   ],
   "blinds":[
      {
         "moving":"stop",
         "position":100,
         "lamella":100,
         "readonly":false,
         "index":{
            "relative":0,
            "absolute":1
         }
      }
   ],
   "led":{
      "on":false,
      "hsv":"190;100;0",
      "rgb":"FFFFFF",
      "mode":"hsv",
      "ramp":1023
   },
   "sensors":{
      "brightness":0,
      "light_state":"night",
      "room_temperature":20.5,
      "uncompensated_temperature":38.25,
      "temp_offset":0,
      "cpu_temperature":66.67,
      "puck_temperature":36,
      "fet_temperature":35.3,
      "input_state":null,
      "person_present":0,
      "power_outputs":[
         {
            "value":0
         },
         {
            "value":0
         },
         {
            "value":0
         },
         {
            "value":0
         }
      ]
   },
   "thermostat":{
      "active":false,
      "out":0,
      "on":false,
      "enabled":true,
      "target_temp":21,
      "mode":"heating",
      "temp":20.5,
      "min_target_temp":17,
      "max_target_temp":31
   },
   "wifi":{
      "version":"1.3.30",
      "mac":"xxxxxxxxxxxx",
      "ssid":"xxxxx",
      "ip":"xx.xx.xx.xx",
      "mask":"255.255.255.0",
      "gateway":"xx.xx.xx.xx",
      "dns":"xx.xx.xx.xx",
      "static":false,
      "connected":true
   },
   "time":"2021-12-22 20:29:49",
   "config":{
      "timestamp":1639953411
   }
}

http://<HOST>/api/v1/state content of a switch in 2 blinds configuration:

{
   "dimmers":[

   ],
   "blinds":[
      {
         "moving":"stop",
         "position":99,
         "lamella":50,
         "readonly":false,
         "index":{
            "relative":0,
            "absolute":0
         }
      },
      {
         "moving":"stop",
         "position":100,
         "lamella":100,
         "readonly":false,
         "index":{
            "relative":1,
            "absolute":1
         }
      }
   ],
   "led":{
      "on":false,
      "hsv":"0;0;100",
      "rgb":"FFFFFF",
      "mode":"hsv",
      "ramp":1023
   },
...

http://<HOST>/api/v1/state content of a switch in 4 lights configuration:

{
   "dimmers":[
      {
         "on":false,
         "output":0,
         "ramp":0,
         "readonly":true,
         "index":{
            "relative":0,
            "absolute":0
         }
      },
      {
         "on":true,
         "output":100,
         "ramp":0,
         "readonly":false,
         "index":{
            "relative":1,
            "absolute":1
         }
      },
      {
         "on":false,
         "output":0,
         "ramp":0,
         "readonly":false,
         "index":{
            "relative":2,
            "absolute":2
         }
      },
      {
         "on":true,
         "output":2,
         "ramp":0,
         "readonly":false,
         "index":{
            "relative":3,
            "absolute":3
         }
      }
   ],
   "blinds":[

   ],
   "led":{
      "on":false,
      "hsv":"0;0;100",
      "rgb":"FFFFFF",
      "mode":"hsv",
      "ramp":1023
   },
...
siku2 commented 2 years ago

Ah, I see. The problem is that the integration doesn't take into account that all configured dimmers are reported, even if they're not used. This is a bug in the integration that is somewhat difficult to fix, but there's a simple workaround for now:

Just go to the dimmer config page (http://<HOST>/index.html#/dimmers) and switch all unused dimmers to the type "Not connected". That way the integration will no longer try to use them.

Sn00x commented 2 years ago

Unfortunately, the mentioned dimmer config page does not offer the possibility to set the type to "Not connected", as the outputs configured as blinds are not displayed at all.

That is, only the 4 lamps configuration page allows to set the respective type of the 4 outputs. With the 2 lamps 1 blinds configuration only the outputs 1 and 2 are listed, with the 2 blinds configuration none at all (empty configuration page).

Zealand67 commented 2 years ago

I have around the same error logs as Sn00x. My condiguration is blinds on output 3 and 4, output 1 and 2 are configured as I use the for testing to call a shelly api and second for Sonos.

Logs lights: Logger: homeassistant.components.light Source: custom_components/dingz/light.py:102 Integration: Light (documentation, issues) First occurred: 22:58:24 (2 occurrences) Last logged: 22:58:24

Error adding entities for domain light with platform dingz Error while setting up dingz platform for light Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 382, in async_add_entities await asyncio.gather(*tasks) File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 613, in _async_add_entity await entity.add_to_platform_finish() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 748, in add_to_platform_finish self.async_write_ha_state() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 505, in async_write_ha_state self._async_write_ha_state() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 538, in _async_write_ha_state state = self._stringify_state() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 511, in _stringify_state if (state := self.state) is None: File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 935, in state return STATE_ON if self.is_on else STATE_OFF File "/config/custom_components/dingz/light.py", line 118, in is_on return self._dingz_dimmer.on File "/config/custom_components/dingz/light.py", line 102, in _dingz_dimmer return self._dingz_state.dimmers[self._index] IndexError: list index out of range

Logs cover: Logger: homeassistant.components.cover Source: custom_components/dingz/cover.py:43 Integration: Cover (documentation, issues) First occurred: 22:58:24 (2 occurrences) Last logged: 22:58:24

Error adding entities for domain cover with platform dingz Error while setting up dingz platform for cover Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 382, in async_add_entities await asyncio.gather(*tasks) File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 523, in _async_add_entity supported_features=entity.supported_features, File "/usr/src/homeassistant/homeassistant/components/cover/init.py", line 266, in supported_features if self.current_cover_position is not None: File "/config/custom_components/dingz/cover.py", line 61, in current_cover_position return self._dingz_blind.position File "/config/custom_components/dingz/cover.py", line 43, in _dingz_blind return self._dingz_state.blinds[self._index] IndexError: list index out of range

Logs custom: This error originated from a custom integration.

Logger: homeassistant Source: custom_components/dingz/light.py:102 Integration: dingz First occurred: 22:58:29 (23 occurrences) Last logged: 23:00:19

Error doing job: Task exception was never retrieved Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 134, in _handle_refresh_interval await self._async_refresh(log_failures=True, scheduled=True) File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 265, in _async_refresh update_callback() File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 325, in _handle_coordinator_update self.async_write_ha_state() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 505, in async_write_ha_state self._async_write_ha_state() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 538, in _async_write_ha_state state = self._stringify_state() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 511, in _stringify_state if (state := self.state) is None: File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 935, in state return STATE_ON if self.is_on else STATE_OFF File "/config/custom_components/dingz/light.py", line 118, in is_on return self._dingz_dimmer.on File "/config/custom_components/dingz/light.py", line 102, in _dingz_dimmer return self._dingz_state.dimmers[self._index] IndexError: list index out of range

Zealand67 commented 2 years ago

I also encountered that the sensors (temp, lux, motion) are not being updated and show the same value since 12 hours.

siku2 commented 2 years ago

I also encountered that the sensors (temp, lux, motion) are not being updated and show the same value since 12 hours.

You should open a separate issue for that, I don't think it's entirely related to this one.

siku2 commented 1 year ago

Closing this as there is a new version of the integration that might address this.