tetienne / veolia-custom-component

Home Assistant custom component to retrieve information from Veolia
MIT License
9 stars 9 forks source link

Multiple contracts #40

Open m4h3 opened 1 year ago

m4h3 commented 1 year ago

My veolia account has multiple contracts attached (I recently moved to a new house). For some reason, the default contract doesn't have any data, resulting in some error. Only my second contract do have some hourly telemetry data

It seems that the pyolia doesn't support switching/selecting contracts and defaults to the first one. I'll try to understand what needs to be done at the pyolia level to select the contractr and probably update the lib there first.

Reference of the backtrace

2023-08-13 10:39:39.707 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up veolia platform for sensor 
Traceback (most recent call last):                                                                                             
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 370, in _async_setup_platform                   
    await asyncio.gather(*pending)                                                                                             
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 510, in async_add_entities                      
    await asyncio.gather(*tasks)                                                                                               
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 750, in _async_add_entity                       
    await entity.add_to_platform_finish()                                                                                      
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1004, in add_to_platform_finish                          
    self.async_write_ha_state()                                                                                                
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 746, in async_write_ha_state                             
    self._async_write_ha_state()                                                                                               
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 808, in _async_write_ha_state                            
    state = self._stringify_state(available)                                                                                   
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                   
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 752, in _stringify_state                                 
    if (state := self.state) is None:                                                                                          
                 ^^^^^^^^^^                                                                                                    
  File "/config/custom_components/veolia/sensor.py", line 42, in state                                                         
    state = self.coordinator.data[DAILY][-1]                                                                                   
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^                                                                                   
IndexError: list index out of range                         
2023-08-13 11:09:39.169 ERROR (MainThread) [custom_components.veolia] Unexpected error fetching veolia consumption update data:
 list index out of range                                                                                                       
Traceback (most recent call last):                                                                                             
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 283, in _async_refresh                       
    self.data = await self._async_update_data()                                                                                
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 242, in _async_update_data                   
    return await self.update_method()                                                                                          
           ^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                          
  File "/config/custom_components/veolia/__init__.py", line 68, in _get_consumption                                            
    and 0 < previous_data[DAILY][-1] < 10000                                                                                   
            ~~~~~~~~~~~~~~~~~~~~^^^^                                                                                           
IndexError: list index out of range        
DavidTre07 commented 8 months ago

Same from my side, multiple accounts and same error.