bramstroker / homeassistant-powercalc

Custom component to calculate estimated power consumption of lights and other appliances
MIT License
976 stars 258 forks source link

light_setting.hue = int(hs[0] / 360 * 65535) ~~^^^ TypeError: 'NoneType' object is not subscriptable #2380

Closed henfri closed 3 months ago

henfri commented 3 months ago

System Health details

System Information

version core-2024.5.4
installation_type Home Assistant Container
dev false
hassio false
docker true
user root
virtualenv false
python_version 3.12.2
os_name Linux
os_version 6.5.0-rc4
arch x86_64
timezone Europe/Berlin
config_dir /config
Home Assistant Community Store GitHub API | ok -- | -- GitHub Content | ok GitHub Web | ok GitHub API Calls Remaining | 5000 Installed Version | 1.34.0 Stage | running Available Repositories | 1400 Downloaded Repositories | 33 HACS Data | ok
Home Assistant Cloud logged_in | false -- | -- can_reach_cert_server | ok can_reach_cloud_auth | ok can_reach_cloud | ok
Dashboards dashboards | 6 -- | -- resources | 13 views | 6 mode | storage
Recorder oldest_recorder_run | 4. Juli 2024 um 19:37 -- | -- current_recorder_run | 13. Juli 2024 um 21:01 estimated_db_size | 1411.89 MiB database_engine | sqlite database_version | 3.44.2
Spotify api_endpoint_reachable | ok -- | --

Checklist

Describe the issue

This is the same issue as described in https://github.com/bramstroker/homeassistant-powercalc/issues/1920 , I think. That issue is closed asking to open a new issue in case it occurs again:

2024-07-13 21:01:15.081 DEBUG (SyncWorker_25) [custom_components.powercalc.strategy.lut] Loading LUT data file: /config/powercalc-custom-models/friedel/SchlaWand/hs.csv.gz
2024-07-13 21:01:15.104 DEBUG (MainThread) [custom_components.powercalc.strategy.lut] LUT file loaded: 135 lines
2024-07-13 21:01:15.104 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/config/custom_components/powercalc/sensors/power.py", line 378, in appliance_state_listener
    await self._handle_source_entity_state_change(
  File "/config/custom_components/powercalc/sensors/power.py", line 490, in _handle_source_entity_state_change
    self._power = await self.calculate_power(state)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/powercalc/sensors/power.py", line 539, in calculate_power
    power = await self._strategy_instance.calculate(entity_state)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/powercalc/strategy/lut.py", line 166, in calculate
    light_setting.hue = int(hs[0] / 360 * 65535)
                            ~~^^^
TypeError: 'NoneType' object is not subscriptable

Reproduction steps

  1. Configuration as in https://pastebin.com/HA2VQTek
  2. Restart of HA
  3. ...

Debug logs

https://pastebin.com/6J1SyvSx

Diagnostics dump or YAML config

No response

bramstroker commented 3 months ago

Essentially this boils down to be a problem with the attributes of the light. color mode of the light is set to color, but color information is missing. I have just released v1.13.3, which contains better error handling for this error:

It should put an error line in the log now saying the following:

Could not calculate power. no hue/sat set. Please check the attributes of your light in the developer tools

It's prefixed with the light entity id which causes the problem.

There is something wrong with this light, so probably a bug in the integration providing this light in HA. At least with the improved logging we can see which light causes the problem and further investigate.

henfri commented 3 months ago

Thanks! I have updated, and now I have no traceback anymore - but also no warning (loglevel is warning; is that sufficient?)

Greetings, Hendrik

bramstroker commented 3 months ago

Thanks! I have updated, and now I have no traceback anymore - but also no warning (loglevel is warning; is that sufficient?)

Greetings, Hendrik

Probably your light has correct state now after startup or no state change has been reported to Powercalc. The error is logged using error level which is higher than warning so when it happens again you should get an entry in your log.

henfri commented 3 months ago

Ok, thanks. I will keep an eye on it.