Breina / ha-artnet-led

DMX lighting Integration for Home Assistant. Using the HA Color Mode update and Pyartnet library to control lights in multiple DMX universes over ethernet with the Art-Net protocol.
MIT License
124 stars 10 forks source link

ValueError: mutable default GoodInput for field good_input is not allowed #28

Closed apoxhu closed 1 year ago

apoxhu commented 1 year ago

Hey

Getting exception using Home Assistant 2023.3.6 (core) edit: using Python 3.11.2 (main, Feb 11 2023, 14:06:23)

Logger: homeassistant.loader
Source: custom_components/artnet_led/client/__init__.py:240
Integration: artnet_led ([documentation](https://github.com/Breina/ha-artnet-led), [issues](https://github.com/Breina/ha-artnet-led/issues))
First occurred: 4:08:44 AM (3 occurrences)
Last logged: 4:14:36 AM

Unexpected exception importing platform custom_components.artnet_led.light
Traceback (most recent call last):
  File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/homeassistant/loader.py", line 779, in get_platform
    cache[full_name] = self._import_platform(platform_name)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/homeassistant/loader.py", line 796, in _import_platform
    return importlib.import_module(f"{self.pkg_path}.{platform_name}")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/data/com.termux/files/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 "/data/data/com.termux/files/home/.homeassistant/custom_components/artnet_led/light.py", line 40, in <module>
    from custom_components.artnet_led.bridge.artnet_controller import ArtNetController
  File "/data/data/com.termux/files/home/.homeassistant/custom_components/artnet_led/bridge/artnet_controller.py", line 11, in <module>
    from custom_components.artnet_led.client import PortAddress
  File "/data/data/com.termux/files/home/.homeassistant/custom_components/artnet_led/client/__init__.py", line 240, in <module>
    @dataclass
     ^^^^^^^^^
  File "/data/data/com.termux/files/usr/lib/python3.11/dataclasses.py", line 1220, in dataclass
    return wrap(cls)
           ^^^^^^^^^
  File "/data/data/com.termux/files/usr/lib/python3.11/dataclasses.py", line 1210, in wrap
    return _process_class(cls, init, repr, eq, order, unsafe_hash,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/data/com.termux/files/usr/lib/python3.11/dataclasses.py", line 958, in _process_class
    cls_fields.append(_get_field(cls, name, type, kw_only))
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/data/com.termux/files/usr/lib/python3.11/dataclasses.py", line 815, 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

My config is

light:
  - platform: artnet_led
    host: 10.0.0.255
    max_fps: 25
    refresh_every: 0
    node_type: artnet-direct
    universes:
      0:
        devices:
        - channel: 0
          name: Lite1
          type: rgb
        - channel: 3
          name: Lite2
          type: rgb
        - channel: 6
          name: Lite3
          type: rgb
Breina commented 1 year ago

Thanks for the good repot! I can partially reproduce this when running the code locally, not within HA.

The Docker image which I use for testing of HA 2023.3.6 uses Python version 3.10.10, which doesn't seem to have this issue.

Let me work on a fix, give me a sec. :)

Breina commented 1 year ago

@apoxhu I've released version v0.1.3 to fix this. Can you check it out and report back please?

apoxhu commented 1 year ago

Sure thanks for the quick fix, but still getting similar error, now for field "Port"

Logger: homeassistant.loader
Source: custom_components/artnet_led/client/artnet_server.py:68
Integration: artnet_led ([documentation](https://github.com/Breina/ha-artnet-led), [issues](https://github.com/Breina/ha-artnet-led/issues))
First occurred: 3:02:45 PM (2 occurrences)
Last logged: 3:02:58 PM

Unexpected exception importing platform custom_components.artnet_led.light
Traceback (most recent call last):
  File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/homeassistant/loader.py", line 779, in get_platform
    cache[full_name] = self._import_platform(platform_name)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/homeassistant/loader.py", line 796, in _import_platform
    return importlib.import_module(f"{self.pkg_path}.{platform_name}")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/data/com.termux/files/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 "/data/data/com.termux/files/home/.homeassistant/custom_components/artnet_led/light.py", line 40, in <module>
    from custom_components.artnet_led.bridge.artnet_controller import ArtNetController
  File "/data/data/com.termux/files/home/.homeassistant/custom_components/artnet_led/bridge/artnet_controller.py", line 12, in <module>
    from custom_components.artnet_led.client.artnet_server import ArtNetServer
  File "/data/data/com.termux/files/home/.homeassistant/custom_components/artnet_led/client/artnet_server.py", line 68, in <module>
    @dataclass
     ^^^^^^^^^
  File "/data/data/com.termux/files/usr/lib/python3.11/dataclasses.py", line 1220, in dataclass
    return wrap(cls)
           ^^^^^^^^^
  File "/data/data/com.termux/files/usr/lib/python3.11/dataclasses.py", line 1210, in wrap
    return _process_class(cls, init, repr, eq, order, unsafe_hash,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/data/com.termux/files/usr/lib/python3.11/dataclasses.py", line 958, in _process_class
    cls_fields.append(_get_field(cls, name, type, kw_only))
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/data/com.termux/files/usr/lib/python3.11/dataclasses.py", line 815, in _get_field
    raise ValueError(f'mutable default {type(f.default)} for field '
ValueError: mutable default <class 'custom_components.artnet_led.client.Port'> for field port is not allowed: use default_factory
Breina commented 1 year ago

Ah sorry for not catching that! Can you try v0.1.4 please, pretty sure this should cover all of the cases.

apoxhu commented 1 year ago

Awesome! It works now! Thank you!