Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RamsesClimateEntityDescription.__init__() missing 1 required keyword-only argument: 'extra_attributes' #119

Closed
zxdavb opened this issue Dec 22, 2023 · 12 comments

Comments

@zxdavb
Copy link
Owner

zxdavb commented Dec 22, 2023

@trvrnrth

This is what I'm seeing:

2023-12-22 22:44:30.777 ERROR (MainThread) [homeassistant.loader] Unexpected exception importing platform custom_components.ramses_cc.binary_sensor
Traceback (most recent call last):
  File "/home/dbonnes/clients/hass/homeassistant/loader.py", line 834, in get_platform
    cache[full_name] = self._import_platform(platform_name)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/dbonnes/clients/hass/homeassistant/loader.py", line 851, in _import_platform
    return importlib.import_module(f"{self.pkg_path}.{platform_name}")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/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 "/home/dbonnes/clients/ramses_cc/custom_components/ramses_cc/binary_sensor.py", line 210, in <module>
    RamsesBinarySensorEntityDescription(
TypeError: RamsesBinarySensorEntityDescription.__init__() missing 1 required keyword-only argument: 'extra_attributes'

2023-12-22 22:44:30.781 ERROR (MainThread) [homeassistant.setup] Unable to prepare setup for platform 'ramses_cc.binary_sensor': Platform not found (Exception importing custom_components.ramses_cc.binary_sensor).

2023-12-22 22:44:30.852 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up ramses_cc platform for sensor
Traceback (most recent call last):
  File "/home/dbonnes/clients/hass/homeassistant/helpers/entity_platform.py", line 360, in _async_setup_platform
    await asyncio.shield(task)
  File "/home/dbonnes/clients/ramses_cc/custom_components/ramses_cc/sensor.py", line 161, in async_setup_platform
    RamsesSensorEntityDescription(
TypeError: RamsesSensorEntityDescription.__init__() missing 1 required keyword-only argument: 'extra_attributes'

2023-12-22 22:44:30.873 ERROR (MainThread) [homeassistant.components.climate] Error while setting up ramses_cc platform for climate
Traceback (most recent call last):
  File "/home/dbonnes/clients/hass/homeassistant/helpers/entity_platform.py", line 360, in _async_setup_platform
    await asyncio.shield(task)
  File "/home/dbonnes/clients/ramses_cc/custom_components/ramses_cc/climate.py", line 285, in async_setup_platform
    RamsesClimateEntityDescription(
TypeError: RamsesClimateEntityDescription.__init__() missing 1 required keyword-only argument: 'extra_attributes'
...
@zxdavb
Copy link
Owner Author

zxdavb commented Dec 22, 2023

I have pulled sensor_types out as SENSOR_TYPES (could be called BINARY_SENSOR_TYPES).

@zxdavb
Copy link
Owner Author

zxdavb commented Dec 22, 2023

required keyword-only argument

Should be optional?

@zxdavb
Copy link
Owner Author

zxdavb commented Dec 22, 2023

I am not familiar with this:

@dataclass(kw_only=True)
class RamsesEntityDescription(EntityDescription):
    """Class describing Ramses entities."""

    has_entity_name: bool = True
    extra_attributes: list[str] = field(default_factory=list)  # dict?

@trvrnrth
Copy link
Contributor

Odd. It works fine for me. These are the docs for creating a new list for the dataclass. It's a list, not a dict as it is a list of device properties to expose as attributes.

@zxdavb
Copy link
Owner Author

zxdavb commented Dec 23, 2023

But:

    RamsesBinarySensorEntityDescription(
        key="active_fault",
        name="Active fault",
        rf_class=Logbook,
        entity_class=RamsesLogbookBinarySensor,
        device_class=BinarySensorDeviceClass.PROBLEM,
        extra_attributes={                                            # this is a dict
            ATTR_ACTIVE_FAULT: "active_fault",
            ATTR_LATEST_EVENT: "latest_event",
            ATTR_LATEST_FAULT: "latest_fault",
        },

@trvrnrth
Copy link
Contributor

🤦 Yes, you're absolutely correct. The default should be a dict (type dict[str, str])! I initially implemented it as a list before changing it to be more flexible but was completely forgetting about that when writing that comment.

@zxdavb
Copy link
Owner Author

zxdavb commented Dec 23, 2023

...but doesn't solve my problem.

@trvrnrth
Copy link
Contributor

We don't actually need it to default to an empty dict. I'm confused as to why that's not working for you but does the following work instead?

    extra_attributes: dict[str, str] | None = None

@zxdavb
Copy link
Owner Author

zxdavb commented Dec 23, 2023

Well.

I had tried

extra_attributes: dict[str, str] | None = field(default_factory=dict)

... which didn't work, but your suggestion does!

@zxdavb
Copy link
Owner Author

zxdavb commented Dec 23, 2023

I'll push that.

zxdavb added a commit that referenced this issue Dec 23, 2023
@zxdavb
Copy link
Owner Author

zxdavb commented Dec 23, 2023

We're both running dev branch of HA, with Python 3.11.6, right?

@trvrnrth
Copy link
Contributor

We're both running dev branch of HA, with Python 3.11.6, right?

I've been running on a slightly out of date dev branch of HA (Dec 3) running with the provided devcontainer which has Python 3.11.4. I also tested on my main install of 2023.12.3. I'll update to latest dev for good measure.

@zxdavb zxdavb closed this as completed Dec 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants