Hi. My greenchoice sensor (v1.5.0) isn't working anymore. I get this error in the home-assistant log.
2024-11-15 21:38:02.576 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up greenchoice platform for sensor
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 365, in _async_setup_platform
await asyncio.shield(awaitable)
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/greenchoice/sensor.py", line 107, in setup_platform
throttled_api_update(greenchoice_api)
File "/usr/src/homeassistant/homeassistant/util/__init__.py", line 184, in wrapper
result = method(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/greenchoice/sensor.py", line 124, in throttled_api_update
api_result = api.update()
^^^^^^^^^^^^
File "/config/custom_components/greenchoice/api.py", line 207, in update
self.update_usage_values(self.result)
File "/config/custom_components/greenchoice/api.py", line 223, in update_usage_values
meter_readings = self.get_meter_readings()
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/greenchoice/api.py", line 126, in get_meter_readings
return MeterReadings.from_dict(meter_json)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/greenchoice/model.py", line 300, in from_dict
productTypes=[MeterProduct.from_dict(r) for r in data.get("productTypes")],
^^^^^^^^
AttributeError: 'list' object has no attribute 'get'
I added this line in api.py at line 123 to dump the value sent from api.py to model.py:
_LOGGER.debug(f"Result of get_meter_readings: {meter_json}")
So if I look for the cause: In line 300 it is indeed expecting a dictionary with a key productTypes
productTypes=[MeterProduct.from_dict(r) for r in data.get("productTypes")],
But the value sent from api.py to model.py is a list, not a dict. And this list (of course) does not have a key "productTypes" (it does not have any keys, because it is a list).
Hi. My greenchoice sensor (v1.5.0) isn't working anymore. I get this error in the home-assistant log.
I added this line in
api.py
at line 123 to dump the value sent fromapi.py
tomodel.py
:And got this value:
So if I look for the cause: In line 300 it is indeed expecting a dictionary with a key
productTypes
But the value sent from
api.py
tomodel.py
is a list, not a dict. And this list (of course) does not have a key "productTypes" (it does not have any keys, because it is a list).Did the API change again?