home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
71.13k stars 29.8k forks source link

Entity property caching seems to break some custom components #107149

Closed ppetru closed 8 months ago

ppetru commented 8 months ago

The problem

After the 2024.01 release, the siku2/hass_weatherlink (and apparently others too) stopped working. See siku2/hass-weatherlink#59 for details.

After some debugging, it looks like the property caching code added in #100601 may be the reason. Specifically, CachedProperties.__new__ doesn't seem to pass kwargs to super(). Thus, __init_subclass__ from the custom component doesn't get the arguments it expects.

Caveat: I don't fully understand all the metaclass magic at play here in both core and hass-weatherlink, and could be on the entirely wrong track.

What version of Home Assistant Core has the issue?

core-2024.1.0

What was the last working version of Home Assistant Core?

core-2024.12.3

What type of installation are you running?

Home Assistant OS

Integration causing the issue

hass-weatherlink

Link to integration documentation on our website

No response

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

Logger: homeassistant.loader
Source: loader.py:842
First occurred: 4:39:10 PM (1 occurrences)
Last logged: 4:39:10 PM

Unexpected exception importing platform custom_components.weatherlink.sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/loader.py", line 842, in get_platform
    cache[full_name] = self._import_platform(platform_name)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/loader.py", line 859, in _import_platform
    return importlib.import_module(f"{self.pkg_path}.{platform_name}")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/config/custom_components/weatherlink/sensor.py", line 4, in <module>
    from .sensor_air_quality import *
  File "/config/custom_components/weatherlink/sensor_air_quality.py", line 18, in <module>
    class AirQualitySensor(WeatherLinkSensor, abc=True):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 295, in __new__
    return super().__new__(mcs, name, bases, namespace)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen abc>", line 106, in __new__
  File "/config/custom_components/weatherlink/sensor_common.py", line 45, in __init_subclass__
    sensor_name = kwargs.pop("sensor_name")
                  ^^^^^^^^^^^^^^^^^^^^^^^^^
KeyError: 'sensor_name'

Additional information

No response

ppetru commented 8 months ago

/cc @emontnemery