"""ZHA quirk for the smart-light effects cluster. The light serves a manufacturer-specific cluster (0xFD00, manufacturer code 0xC0DE) through which Home Assistant picks an animated scene and tunes it. ZHA cannot talk to a cluster it has no definition for, so this quirk supplies one and turns its attributes into entities: * a select for the effect (Off, Rainbow, Pulse, Comet) * a number for the speed, and one for the intensity The scene plays in the light's own colour and brightness, so the light's on/off, brightness and colour controls keep working while one runs. The identifiers here have to match the firmware: src/effects_cluster.rs. Install: copy this file into a folder under the Home Assistant config directory, point ZHA at it in configuration.yaml, and restart Home Assistant: zha: custom_quirks_path: /config/custom_zha_quirks/ The Zigbee device is then listed with the extra entities. Untested against a running ZHA: the import fallbacks below are there because the quirk authoring API has moved between releases. """ import zigpy.types as t from zigpy.zcl.foundation import BaseAttributeDefs, ZCLAttributeDef try: from zhaquirks.clusters import CustomCluster except ImportError: # older zha-quirks from zhaquirks import CustomCluster try: from zhaquirks.builder import EntityType, QuirkBuilder except ImportError: # older zha-quirks from zigpy.quirks.v2 import QuirkBuilder from zigpy.quirks.v2.homeassistant import EntityType CLUSTER_ID = 0xFD00 # a development code: the device has no manufacturer code of its own MANUFACTURER_CODE = 0xC0DE class SmartLightEffect(t.enum8): """The scene playing.""" Off = 0x00 Rainbow = 0x01 Pulse = 0x02 Comet = 0x03 class SmartLightEffectsCluster(CustomCluster): """The light's effects cluster.""" cluster_id = CLUSTER_ID ep_attribute = "smart_light_effects" # without this, ZHA would use the device's node descriptor code manufacturer_id_override = MANUFACTURER_CODE class AttributeDefs(BaseAttributeDefs): """Attribute definitions.""" effect = ZCLAttributeDef( id=0x0000, type=SmartLightEffect, is_manufacturer_specific=True, ) speed = ZCLAttributeDef( id=0x0001, type=t.uint8_t, is_manufacturer_specific=True, ) intensity = ZCLAttributeDef( id=0x0002, type=t.uint8_t, is_manufacturer_specific=True, ) ( QuirkBuilder("smart-light", "smart-light.ws2812") .adds(SmartLightEffectsCluster) .enum( SmartLightEffectsCluster.AttributeDefs.effect.name, SmartLightEffect, SmartLightEffectsCluster.cluster_id, entity_type=EntityType.STANDARD, translation_key="effect", fallback_name="Effect", ) .number( SmartLightEffectsCluster.AttributeDefs.speed.name, SmartLightEffectsCluster.cluster_id, min_value=0, max_value=255, step=1, entity_type=EntityType.STANDARD, translation_key="effect_speed", fallback_name="Effect speed", ) .number( SmartLightEffectsCluster.AttributeDefs.intensity.name, SmartLightEffectsCluster.cluster_id, min_value=0, max_value=255, step=1, entity_type=EntityType.STANDARD, translation_key="effect_intensity", fallback_name="Effect intensity", ) .add_to_registry() )