Beispiel #1
0
def setup_platform(hass, config, add_entities, discovery_info=None):
    """Set up the PWM LED lights."""

    leds = []
    for led_conf in config[CONF_LEDS]:
        driver_type = led_conf[CONF_DRIVER]
        pins = led_conf[CONF_PINS]
        opt_args = {}
        if CONF_FREQUENCY in led_conf:
            opt_args["freq"] = led_conf[CONF_FREQUENCY]
        if driver_type == CONF_DRIVER_GPIO:
            driver = GpioDriver(pins, **opt_args)
        elif driver_type == CONF_DRIVER_PCA9685:
            if CONF_ADDRESS in led_conf:
                opt_args["address"] = led_conf[CONF_ADDRESS]
            driver = Pca9685Driver(pins, **opt_args)
        else:
            _LOGGER.error("Invalid driver type")
            return

        name = led_conf[CONF_NAME]
        led_type = led_conf[CONF_TYPE]
        if led_type == CONF_LED_TYPE_SIMPLE:
            led = PwmSimpleLed(SimpleLed(driver), name)
        elif led_type == CONF_LED_TYPE_RGB:
            led = PwmRgbLed(RgbLed(driver), name)
        elif led_type == CONF_LED_TYPE_RGBW:
            led = PwmRgbLed(RgbwLed(driver), name)
        else:
            _LOGGER.error("Invalid led type")
            return
        leds.append(led)

    add_entities(leds)
Beispiel #2
0
def setup_platform(
    hass: HomeAssistant,
    config: ConfigType,
    add_entities: AddEntitiesCallback,
    discovery_info: DiscoveryInfoType | None = None,
) -> None:
    """Set up the PWM LED lights."""
    _LOGGER.warning(
        "The pigpio Daemon PWM LED integration is deprecated and will be removed "
        "in Home Assistant Core 2022.4; this integration is removed under "
        "Architectural Decision Record 0019, more information can be found here: "
        "https://github.com/home-assistant/architecture/blob/master/adr/0019-GPIO.md"
    )

    leds = []
    for led_conf in config[CONF_LEDS]:
        driver_type = led_conf[CONF_DRIVER]
        pins = led_conf[CONF_PINS]
        opt_args = {}
        if CONF_FREQUENCY in led_conf:
            opt_args["freq"] = led_conf[CONF_FREQUENCY]
        if driver_type == CONF_DRIVER_GPIO:
            if CONF_HOST in led_conf:
                opt_args["host"] = led_conf[CONF_HOST]
            driver = GpioDriver(pins, **opt_args)
        elif driver_type == CONF_DRIVER_PCA9685:
            if CONF_ADDRESS in led_conf:
                opt_args["address"] = led_conf[CONF_ADDRESS]
            driver = Pca9685Driver(pins, **opt_args)
        else:
            _LOGGER.error("Invalid driver type")
            return

        name = led_conf[CONF_NAME]
        led_type = led_conf[CONF_TYPE]
        if led_type == CONF_LED_TYPE_SIMPLE:
            led = PwmSimpleLed(SimpleLed(driver), name)
        elif led_type == CONF_LED_TYPE_RGB:
            led = PwmRgbLed(RgbLed(driver), name)
        elif led_type == CONF_LED_TYPE_RGBW:
            led = PwmRgbLed(RgbwLed(driver), name)
        else:
            _LOGGER.error("Invalid led type")
            return
        leds.append(led)

    add_entities(leds)
Beispiel #3
0
def setup_platform(hass, config, add_devices, discovery_info=None):
    """Setup the pwm lights."""
    from pwmled.led import SimpleLed
    from pwmled.led.rgb import RgbLed
    from pwmled.led.rgbw import RgbwLed
    from pwmled.driver.gpio import GpioDriver
    from pwmled.driver.pca9685 import Pca9685Driver

    leds = []
    for led_conf in config[CONF_LEDS]:
        driver_type = led_conf[CONF_DRIVER]
        pins = led_conf[CONF_PINS]
        opt_args = {}
        if CONF_FREQUENCY in led_conf:
            opt_args['freq'] = led_conf[CONF_FREQUENCY]
        if driver_type == CONF_DRIVER_GPIO:
            driver = GpioDriver(pins, **opt_args)
        elif driver_type == CONF_DRIVER_PCA9685:
            if CONF_ADDRESS in led_conf:
                opt_args['address'] = led_conf[CONF_ADDRESS]
            driver = Pca9685Driver(pins, **opt_args)
        else:
            _LOGGER.error("Invalid driver type.")
            return

        name = led_conf[CONF_NAME]
        led_type = led_conf[CONF_TYPE]
        if led_type == CONF_LED_TYPE_SIMPLE:
            led = PwmSimpleLed(SimpleLed(driver), name)
        elif led_type == CONF_LED_TYPE_RGB:
            led = PwmRgbLed(RgbLed(driver), name)
        elif led_type == CONF_LED_TYPE_RGBW:
            led = PwmRgbLed(RgbwLed(driver), name)
        else:
            _LOGGER.error("Invalid led type.")
            return
        leds.append(led)

    add_devices(leds)