enkama / hass-variables

Home Assistant variables component
90 stars 12 forks source link

AttributeError: 'str' object has no attribute 'keys' #55

Closed finity69x2 closed 1 year ago

finity69x2 commented 1 year ago

here is the error:

2023-04-20 09:19:18.938 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up variable platform for sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 293, in _async_setup_platform
    await asyncio.shield(task)
  File "/config/custom_components/variable/sensor.py", line 93, in async_setup_entry
    async_add_entities([Variable(hass, config, config_entry, unique_id)])
  File "/config/custom_components/variable/sensor.py", line 130, in __init__
    self._attr_extra_state_attributes = self._update_attr_settings(
  File "/config/custom_components/variable/sensor.py", line 207, in _update_attr_settings
    if attrib in attributes.keys():
AttributeError: 'str' object has no attribute 'keys'

I've updated to the latest version.

enkama commented 1 year ago

Hard to reproduce it without any infos.

Snuffy2 commented 1 year ago

Interesting. I'll improve the type checking in that area to prevent that. Do you know what the value of your attributes is for the variable that gave this error?

finity69x2 commented 1 year ago

No, I don't have any variables set up on this install.

The HA I'm running is just a test install that I have and literally just installed the latest version of the integration thru HACS to do some testing on it. And I haven't had time to actually configure any variables with it yet, tho.

So unfortunately that's all the info I have on it. That's literally the only info I have is that log entry.

I was looking in the logs for something else and just stumbled on that log entry.

reboots don't fix it.

Snuffy2 commented 1 year ago

So I'm not sure how that can happen as an integration without any entities won't even be loaded by HA. I removed all of the variables on my Dev install and also cannot reproduce this.

However, I've added some improved error checking to hopefully prevent this if there are badly formatted attributes. I'll have a PR out once I've completed testing.