Brightness method in custom light platform

Hello everyone!

I tried to integrate light device to HA. But I couldn’t add brightness level to my platform like in this example Example Light Platform. Even if I add brightness method to my class, then in the UI the “Effect” is invisible - when I press it, it becomes visible. But this “Effect” doesn’t allow change brightness.

Could someone help me to add brightness to my class?

Brightness doesn’t work even for minimal structure of light platform, without my custom device protocol. For example, file /custom_components/light/example_light.py is:

from homeassistant.components.light import ATTR_BRIGHTNESS, Light


def setup_platform(hass, config, add_devices, discovery_info=None):
    add_devices([MyExampleLight()])


class MyExampleLight(Light):

    def __init__(self,):
        self._name = "My example light"
        self._state = None
        self._brightness = None

    @property
    def name(self):
        return self._name

    @property
    def brightness(self):
        return self._brightness

    @property
    def is_on(self):
        return self._state

    def turn_on(self, **kwargs):
        self._brightness = kwargs.get(ATTR_BRIGHTNESS, 255)
        self._state = True

    def turn_off(self, **kwargs):
        self._state = False

    def update(self):
        pass

And configuration.yaml is:

light:
  - platform: example_light

Thank you in advance.

Roman

Your class misses supported_features property which should looks like this

@property_
def supported_features(self):
        """Flag supported features.
        This method is optional. Removing it indicates to Home Assistant
        that brightness is not supported for this light.
        """
        return SUPPORT_BRIGHTNESS  # or use 1 instead of the constant