ha-artnet-led
ha-artnet-led copied to clipboard
Error with python3.11
Running HA with python3.11, I get this error. See https://docs.python.org/3.11/whatsnew/3.11.html#dataclasses Maybe adding a __hash__ method will fix it.
2023-05-26 17:39:45.808 ERROR (MainThread) [homeassistant.loader] Unexpected exception importing platform custom_components.artnet_led.light
Traceback (most recent call last):
File "/home/nuc/.local/lib/python3.11/site-packages/homeassistant/loader.py", line 833, in get_platform
cache[full_name] = self._import_platform(platform_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/nuc/.local/lib/python3.11/site-packages/homeassistant/loader.py", line 850, 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 1206, in _gcd_import
File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
File "<frozen importlib._bootstrap>", line 1149, 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/nuc/.homeassistant/custom_components/artnet_led/light.py", line 40, in <module>
from custom_components.artnet_led.bridge.artnet_controller import ArtNetController
File "/home/nuc/.homeassistant/custom_components/artnet_led/bridge/artnet_controller.py", line 11, in <module>
from custom_components.artnet_led.client import PortAddress
File "/home/nuc/.homeassistant/custom_components/artnet_led/client/__init__.py", line 240, in <module>
@dataclass
^^^^^^^^^
File "/usr/lib/python3.11/dataclasses.py", line 1221, in dataclass
return wrap(cls)
^^^^^^^^^
File "/usr/lib/python3.11/dataclasses.py", line 1211, in wrap
return _process_class(cls, init, repr, eq, order, unsafe_hash,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/dataclasses.py", line 959, in _process_class
cls_fields.append(_get_field(cls, name, type, kw_only))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/dataclasses.py", line 816, in _get_field
raise ValueError(f'mutable default {type(f.default)} for field '
ValueError: mutable default <class 'custom_components.artnet_led.client.GoodInput'> for field good_input is not allowed: use default_factory
This hack fixed it for the moment. I added it to the classes GoodInput, GoodOutputA, Port and ArtIpProgCommand
def __hash__(self): # jms
return hash(123456789)
def __eq__(self, other):
return (
self.__class__ == other.__class__
)
I think a more proper fix is as such:
https://github.com/Breina/ha-artnet-led/commit/4865772d6d9266be6bedb54f95168477a59a2de1#diff-678b746f282cdb4a9a03b580a9fad1ea634cdbd7f0250db20cc862b85c22b49a