jnimmo / hass-dmx

Home Assistant DMX over IP Integration
MIT License
107 stars 46 forks source link

cannot import name 'ATTR_WHITE_VALUE' #68

Open feradelectronics opened 1 year ago

feradelectronics commented 1 year ago

Get error recently with HA

log error:

Logger: homeassistant.config Source: custom_components/dmx/light.py:40 Integration: dmx (documentation) First occurred: 8:37:24 AM (1 occurrences) Last logged: 8:37:24 AM

Platform error: light Traceback (most recent call last): File "/config/custom_components/dmx/light.py", line 25, in from homeassistant.components.light import ( ImportError: cannot import name 'ATTR_WHITE_VALUE' from 'homeassistant.components.light' (/usr/src/homeassistant/homeassistant/components/light/init.py)

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/config.py", line 878, in async_process_component_config platform = p_integration.get_platform(domain) File "/usr/src/homeassistant/homeassistant/loader.py", line 681, in get_platform cache[full_name] = self._import_platform(platform_name) File "/usr/src/homeassistant/homeassistant/loader.py", line 698, in _import_platform return importlib.import_module(f"{self.pkg_path}.{platform_name}") File "/usr/local/lib/python3.10/importlib/init.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1050, in _gcd_import File "", line 1027, in _find_and_load File "", line 1006, in _find_and_load_unlocked File "", line 688, in _load_unlocked File "", line 883, in exec_module File "", line 241, in _call_with_frames_removed File "/config/custom_components/dmx/light.py", line 40, in from homeassistant.components.light import ( ImportError: cannot import name 'ATTR_WHITE_VALUE' from 'homeassistant.components.light' (/usr/src/homeassistant/homeassistant/components/light/init.py)

kic68 commented 1 year ago

Unfortunately/naturally I am getting the same error. Just upgraded to HA 2022.9.0. Could be related to https://github.com/home-assistant/core/pull/47720

303Bryan commented 1 year ago

Same issue here... It does look related to: LightEntity no longer supports white_value in 2022.9

Platform error light.dmx - cannot import name 'ATTR_WHITE_VALUE' from 'homeassistant.components.light' (/usr/src/homeassistant/homeassistant/components/light/init.py) Platform error light.dmx - cannot import name 'ATTR_WHITE_VALUE' from 'homeassistant.components.light' (/usr/src/homeassistant/homeassistant/components/light/init.py)

tobias-friedrich commented 1 year ago

Same here after upgrade to HA 2022.9.0 It goes away when downgrading to HA 2022.8.7.

Breina commented 1 year ago

Just for providing a solution here, you can switch over to my fork which has a complete compatible configuration and supports HA 2022.9: https://github.com/Breina/ha-artnet-led

acronce commented 1 year ago

I'm seeing the same problem after updating to 2022.9.1. I'll give @Breina's fork a try.

acronce commented 1 year ago

I couldn't even restart HA due to the ATTR_WHITE_VALUE error. I guess it considers a failed integration as a configuration issue.

To work around this I edited the dmx/light.py script to remove references to ATTR_WHITE_VALUE and SUPPORT_WHITE_VALUE, as well as the few lines of code that used those values. That allowed me to pass the configuration test and reboot.

As a side effect, this fixed the hass-dmx integration for me. But I'm still planning on moving given that this project doesn't seem very well supported currently.

kic68 commented 1 year ago

https://github.com/Breina/ha-artnet-led is really working fine... you have to slightly change your configuration, but just follow the good documentation and you're immediately up and running. In fact you can have both HACS repos active at the same time (while still being below 2022.9.0) and adapt your existing configuration to the new format, then have the validity checked until all is fine before restarting homeassistant.

My diff (controlling aquarium lights this way) looks like this:

-- platform: dmx
+- platform: artnet_led
   host: aquarium.local
-  default_type: dimmer
   port: 6454
-  dmx_channels: 512 
-  default_level: 255
-  universe: 0
-  devices:
-    - channel: 1
-      name: Aquarium Polar
-    - channel: 2
-      name: Aquarium Day
-    - channel: 3
-      name: Aquarium Sunset
+  universes:
+    0:
+      output_correction: quadratic
+      devices:
+        - channel: 1
+          type: dimmer
+          name: Aquarium Polar
+        - channel: 2
+          type: dimmer
+          name: Aquarium Day
+        - channel: 3
+          type: dimmer
+          name: Aquarium Sunset
jacobmellin commented 1 year ago

I fixed this (temporarily) by commenting out ATTR_WHITE_VALUE and SUPPORT_WHITE_VALUE from the import statement in dmx/light.py and setting them explicitly below, like so:

try:
    from homeassistant.components.light import (
        ATTR_BRIGHTNESS,
        ATTR_HS_COLOR,
        ATTR_TRANSITION,
#        ATTR_WHITE_VALUE,
        ATTR_COLOR_TEMP,
        LightEntity,
        PLATFORM_SCHEMA,
        SUPPORT_BRIGHTNESS,
        SUPPORT_COLOR,
        SUPPORT_WHITE_VALUE,
        SUPPORT_TRANSITION,
        SUPPORT_COLOR_TEMP,
    )
except ImportError:
    from homeassistant.components.light import (
        ATTR_BRIGHTNESS,
        ATTR_HS_COLOR,
        ATTR_TRANSITION,
#        ATTR_WHITE_VALUE,
        ATTR_COLOR_TEMP,
#        Light as LightEntity,
        LightEntity,
        PLATFORM_SCHEMA,
        SUPPORT_BRIGHTNESS,
        SUPPORT_COLOR,
#        SUPPORT_WHITE_VALUE,
        SUPPORT_TRANSITION,
        SUPPORT_COLOR_TEMP,
    )
from homeassistant.util.color import color_rgb_to_rgbw
from homeassistant.helpers.restore_state import RestoreEntity
from homeassistant.core import callback
import homeassistant.helpers.config_validation as cv
import homeassistant.util.color as color_util
import voluptuous as vol

ATTR_WHITE_VALUE = 255
SUPPORT_WHITE_VALUE = True

I also had to change Light as LightEntity to LightEntity.