From 44c67dc0ed8f409144ac83a23ae0459093ea4661 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 14 Nov 2021 23:26:53 -0600 Subject: [PATCH] Simplify model db protocol determination (#162) --- flux_led/models_db.py | 175 +++++++++++++----------------------------- 1 file changed, 55 insertions(+), 120 deletions(-) diff --git a/flux_led/models_db.py b/flux_led/models_db.py index 5f344753..07809fd8 100755 --- a/flux_led/models_db.py +++ b/flux_led/models_db.py @@ -14,6 +14,13 @@ STATE_RED, STATE_WARM_WHITE, ) +from .protocol import ( + PROTOCOL_LEDENET_8BYTE, + PROTOCOL_LEDENET_9BYTE, + PROTOCOL_LEDENET_ADDRESSABLE, + PROTOCOL_LEDENET_ORIGINAL, + PROTOCOL_LEDENET_ORIGINAL_ADDRESSABLE, +) LEDENETModel = namedtuple( "LEDENETModel", @@ -22,12 +29,10 @@ "models", # The model names from discovery "description", # Description of the model "always_writes_white_and_colors", # Devices that don't require a separate rgb/w bit aka rgbwprotocol - "nine_byte_read_protocol", # Devices that use the 9 byte protocol to read state + "protocol", # The device protocol "mode_to_color_mode", # A mapping of mode aka byte 2 to color mode that overrides color_modes "color_modes", # The color modes to use if there is no mode_to_color_mode_mapping "channel_map", # Used to remap channels - "addressable", # The device has addressable LEDs - "original_addressable", # The device has addressable LEDs, but uses the old original addressable protocol ], ) @@ -97,456 +102,380 @@ models=[], description="Original LEDENET", always_writes_white_and_colors=False, # Formerly rgbwprotocol - nine_byte_read_protocol=False, + protocol=PROTOCOL_LEDENET_ORIGINAL, mode_to_color_mode={}, color_modes={COLOR_MODE_RGB}, channel_map={}, - addressable=False, - original_addressable=False, ), LEDENETModel( model_num=0x04, models=["AK001-ZJ200"], description="UFO LED WiFi Controller", # AKA ZJ-WFUF-170F always_writes_white_and_colors=True, # Formerly rgbwprotocol - nine_byte_read_protocol=False, + protocol=PROTOCOL_LEDENET_8BYTE, mode_to_color_mode={}, color_modes={COLOR_MODE_RGBW}, # Formerly rgbwcapable channel_map={}, - addressable=False, - original_addressable=False, ), LEDENETModel( model_num=0x06, models=["AK001-ZJ2147"], description="Magic Home Branded RGBW Controller", always_writes_white_and_colors=False, # Formerly rgbwprotocol - nine_byte_read_protocol=False, + protocol=PROTOCOL_LEDENET_8BYTE, mode_to_color_mode=GENERIC_RGBW_MAP, color_modes={COLOR_MODE_RGBW}, # Formerly rgbwcapable channel_map={}, - addressable=False, - original_addressable=False, ), LEDENETModel( model_num=0x07, models=[], description="Magic Home Branded RGBCW Controller", always_writes_white_and_colors=False, # Formerly rgbwprotocol - nine_byte_read_protocol=True, + protocol=PROTOCOL_LEDENET_9BYTE, mode_to_color_mode=GENERIC_RGBWW_MAP, color_modes={COLOR_MODE_RGBWW}, # Formerly rgbwcapable channel_map={}, - addressable=False, - original_addressable=False, ), LEDENETModel( model_num=0x08, models=[], description="Magic Home Branded RGB Controller with MIC", always_writes_white_and_colors=True, # Formerly rgbwprotocol - nine_byte_read_protocol=False, + protocol=PROTOCOL_LEDENET_8BYTE, mode_to_color_mode=GENERIC_RGB_MAP, color_modes={COLOR_MODE_RGB}, channel_map={}, - addressable=False, - original_addressable=False, ), LEDENETModel( model_num=0x09, models=[], description="CCT Ceiling Light", always_writes_white_and_colors=False, # Formerly rgbwprotocol - nine_byte_read_protocol=False, + protocol=PROTOCOL_LEDENET_8BYTE, mode_to_color_mode={}, color_modes={COLOR_MODE_CCT}, # Formerly rgbwcapable channel_map={}, - addressable=False, - original_addressable=False, ), LEDENETModel( model_num=0x0B, models=[], description="Smart Switch 1c", always_writes_white_and_colors=False, # Formerly rgbwprotocol - nine_byte_read_protocol=False, + protocol=PROTOCOL_LEDENET_8BYTE, mode_to_color_mode={}, color_modes={}, # no color modes channel_map={}, - addressable=False, - original_addressable=False, ), LEDENETModel( model_num=0x0E, models=["AK001-ZJ2104"], description="Floor Lamp", always_writes_white_and_colors=False, # Formerly rgbwprotocol - nine_byte_read_protocol=True, + protocol=PROTOCOL_LEDENET_9BYTE, mode_to_color_mode={0x01: COLOR_MODES_RGB_CCT}, color_modes=COLOR_MODES_RGB_CCT, channel_map={}, - addressable=False, - original_addressable=False, ), LEDENETModel( model_num=0x10, models=[], description="Christmas Light", always_writes_white_and_colors=False, # Formerly rgbwprotocol - nine_byte_read_protocol=False, + protocol=PROTOCOL_LEDENET_8BYTE, mode_to_color_mode={}, color_modes={COLOR_MODE_RGB}, # Formerly rgbwcapable channel_map={}, - addressable=False, - original_addressable=False, ), LEDENETModel( model_num=0x1A, models=[], description="Christmas Light", always_writes_white_and_colors=False, # Formerly rgbwprotocol - nine_byte_read_protocol=False, + protocol=False, mode_to_color_mode={}, color_modes={COLOR_MODE_RGB}, # Formerly rgbwcapable channel_map={}, - addressable=False, - original_addressable=False, ), LEDENETModel( model_num=0x16, models=[], description="Magnetic Light CCT", always_writes_white_and_colors=False, # Formerly rgbwprotocol - nine_byte_read_protocol=False, + protocol=PROTOCOL_LEDENET_8BYTE, mode_to_color_mode={}, color_modes={COLOR_MODE_CCT}, # Formerly rgbwcapable channel_map={}, - addressable=False, - original_addressable=False, ), LEDENETModel( model_num=0x17, models=[], description="Magnetic Light Dimable", always_writes_white_and_colors=False, # Formerly rgbwprotocol - nine_byte_read_protocol=False, + protocol=PROTOCOL_LEDENET_8BYTE, mode_to_color_mode={}, color_modes={COLOR_MODE_DIM}, # Formerly rgbwcapable channel_map={STATE_WARM_WHITE: STATE_RED, STATE_RED: STATE_WARM_WHITE}, - addressable=False, - original_addressable=False, ), LEDENETModel( model_num=0x18, models=[], description="Plant Light", always_writes_white_and_colors=False, # Formerly rgbwprotocol - nine_byte_read_protocol=False, + protocol=PROTOCOL_LEDENET_8BYTE, mode_to_color_mode={}, color_modes={}, # no color modes -- UNVERIFIED channel_map={}, - addressable=False, - original_addressable=False, ), LEDENETModel( model_num=0x1B, models=[], description="Spray Light", always_writes_white_and_colors=False, # Formerly rgbwprotocol - nine_byte_read_protocol=False, + protocol=PROTOCOL_LEDENET_8BYTE, mode_to_color_mode={}, color_modes={COLOR_MODE_RGB}, channel_map={}, - addressable=False, - original_addressable=False, ), LEDENETModel( model_num=0x19, models=[], description="Smart Socket 2 USB", always_writes_white_and_colors=False, # Formerly rgbwprotocol - nine_byte_read_protocol=False, + protocol=PROTOCOL_LEDENET_8BYTE, mode_to_color_mode={}, color_modes={}, # no color modes channel_map={}, - addressable=False, - original_addressable=False, ), LEDENETModel( model_num=0x1C, models=[], description="Table Light CCT", always_writes_white_and_colors=False, # Formerly rgbwprotocol - nine_byte_read_protocol=False, + protocol=PROTOCOL_LEDENET_8BYTE, mode_to_color_mode={}, color_modes={COLOR_MODE_CCT}, # Formerly rgbwcapable channel_map={}, - addressable=False, - original_addressable=False, ), LEDENETModel( model_num=0x21, models=["AK001-ZJ2101", "AK001-ZJ2104"], description="Smart Bulb Dimmable", always_writes_white_and_colors=True, # Verified required with AK001-ZJ200 bulb - nine_byte_read_protocol=False, + protocol=PROTOCOL_LEDENET_8BYTE, mode_to_color_mode={}, color_modes={COLOR_MODE_DIM}, # Formerly rgbwcapable channel_map={STATE_WARM_WHITE: STATE_RED, STATE_RED: STATE_WARM_WHITE}, - addressable=False, - original_addressable=False, ), LEDENETModel( model_num=0x25, models=["AK001-ZJ200"], description="WiFi RGBCW Controller", always_writes_white_and_colors=False, # Formerly rgbwprotocol - nine_byte_read_protocol=True, + protocol=PROTOCOL_LEDENET_9BYTE, mode_to_color_mode=BASE_MODE_MAP, color_modes={COLOR_MODE_RGBWW}, # Formerly rgbwcapable channel_map={}, - addressable=False, - original_addressable=False, ), LEDENETModel( model_num=0x33, models=["AK001-ZJ2145", "AK001-ZJ2146"], description="Magic Home Branded RGB Controller", always_writes_white_and_colors=True, # Formerly rgbwprotocol - nine_byte_read_protocol=False, + protocol=PROTOCOL_LEDENET_8BYTE, mode_to_color_mode=GENERIC_RGB_MAP, color_modes={COLOR_MODE_RGB}, channel_map={}, - addressable=False, - original_addressable=False, ), LEDENETModel( model_num=0x35, models=["AK001-ZJ2145", "AK001-ZJ2101", "AK001-ZJ2104"], description="Smart Bulb RGBCW", always_writes_white_and_colors=False, # Formerly rgbwprotocol - nine_byte_read_protocol=True, + protocol=PROTOCOL_LEDENET_9BYTE, mode_to_color_mode={0x01: COLOR_MODES_RGB_CCT, 0x17: COLOR_MODES_RGB_CCT}, color_modes=COLOR_MODES_RGB_CCT, channel_map={}, - addressable=False, - original_addressable=False, ), LEDENETModel( model_num=0x41, models=[], description="Magic Home Branded Single Channel Controller", always_writes_white_and_colors=False, # Formerly rgbwprotocol - nine_byte_read_protocol=False, + protocol=PROTOCOL_LEDENET_8BYTE, mode_to_color_mode={}, # Only mode should be 0x41 color_modes={COLOR_MODE_DIM}, # Formerly rgbwcapable channel_map={STATE_WARM_WHITE: STATE_RED, STATE_RED: STATE_WARM_WHITE}, - addressable=False, - original_addressable=False, ), LEDENETModel( model_num=0x44, models=[], description="Smart Bulb RGBW", always_writes_white_and_colors=False, # Formerly rgbwprotocol - nine_byte_read_protocol=False, + protocol=PROTOCOL_LEDENET_8BYTE, mode_to_color_mode={}, color_modes=COLOR_MODES_RGB_W, # Formerly rgbwcapable channel_map={}, - addressable=False, - original_addressable=False, ), LEDENETModel( model_num=0x45, models=[], description=None, # Unknown always_writes_white_and_colors=False, # Formerly rgbwprotocol - nine_byte_read_protocol=False, + protocol=PROTOCOL_LEDENET_8BYTE, mode_to_color_mode={}, color_modes={COLOR_MODE_RGB, COLOR_MODE_DIM}, # Formerly rgbwcapable channel_map={}, - addressable=False, - original_addressable=False, ), LEDENETModel( model_num=0x52, models=[], description="Smart Bulb CCT", always_writes_white_and_colors=False, # Formerly rgbwprotocol - nine_byte_read_protocol=False, + protocol=PROTOCOL_LEDENET_8BYTE, mode_to_color_mode={}, color_modes={COLOR_MODE_CCT}, # Formerly rgbwcapable channel_map={}, - addressable=False, - original_addressable=False, ), LEDENETModel( model_num=0x54, models=["HF-LPB100-ZJ200"], description="Downlight RGBW", always_writes_white_and_colors=False, # Formerly rgbwprotocol - nine_byte_read_protocol=False, + protocol=PROTOCOL_LEDENET_8BYTE, mode_to_color_mode={}, color_modes=COLOR_MODES_RGB_W, # Formerly rgbwcapable channel_map={}, - addressable=False, - original_addressable=False, ), LEDENETModel( model_num=0x62, models=[], description="Magic Home Controller CCT", always_writes_white_and_colors=False, # Formerly rgbwprotocol - nine_byte_read_protocol=False, + protocol=PROTOCOL_LEDENET_8BYTE, mode_to_color_mode={}, color_modes={COLOR_MODE_CCT}, # Formerly rgbwcapable channel_map={}, - addressable=False, - original_addressable=False, ), LEDENETModel( model_num=0x81, models=[], description=None, # Unknown always_writes_white_and_colors=True, # Formerly rgbwprotocol - nine_byte_read_protocol=False, + protocol=PROTOCOL_LEDENET_8BYTE, mode_to_color_mode={}, color_modes={COLOR_MODE_RGBW}, # Formerly rgbwcapable channel_map={}, - addressable=False, - original_addressable=False, ), LEDENETModel( model_num=0x93, models=[], description="Smart Switch 1C", always_writes_white_and_colors=False, # Formerly rgbwprotocol - nine_byte_read_protocol=False, + protocol=PROTOCOL_LEDENET_8BYTE, mode_to_color_mode={}, color_modes={}, # no color modes channel_map={}, - addressable=False, - original_addressable=False, ), LEDENETModel( model_num=0x94, models=[], description="Smart Switch 1c Watt", always_writes_white_and_colors=False, # Formerly rgbwprotocol - nine_byte_read_protocol=False, + protocol=PROTOCOL_LEDENET_8BYTE, mode_to_color_mode={}, color_modes={}, # no color modes channel_map={}, - addressable=False, - original_addressable=False, ), LEDENETModel( model_num=0x95, models=[], description="Smart Switch 2c", always_writes_white_and_colors=False, # Formerly rgbwprotocol - nine_byte_read_protocol=False, + protocol=PROTOCOL_LEDENET_8BYTE, mode_to_color_mode={}, color_modes={}, # no color modes channel_map={}, - addressable=False, - original_addressable=False, ), LEDENETModel( model_num=0x96, models=[], description="Smart Switch 4c", always_writes_white_and_colors=False, # Formerly rgbwprotocol - nine_byte_read_protocol=False, + protocol=PROTOCOL_LEDENET_8BYTE, mode_to_color_mode={}, color_modes={}, # no color modes channel_map={}, - addressable=False, - original_addressable=False, ), LEDENETModel( model_num=0x97, # 0x97 models=["AK001-ZJ2134"], description="Smart Socket 1c", always_writes_white_and_colors=False, # Formerly rgbwprotocol - nine_byte_read_protocol=False, + protocol=PROTOCOL_LEDENET_8BYTE, mode_to_color_mode={}, color_modes={}, # no color modes channel_map={}, - addressable=False, - original_addressable=False, ), LEDENETModel( model_num=0xA1, models=[], description="RGB Symphony [Addressable]", # https://github.com/Danielhiversen/flux_led/pull/59/files#diff-09e60df19b61f5ceb8d2aef0ade582c2b84979cab660baa27c1ec65725144d76R776 always_writes_white_and_colors=False, - nine_byte_read_protocol=False, # unverified + protocol=PROTOCOL_LEDENET_ORIGINAL_ADDRESSABLE, mode_to_color_mode={}, color_modes=COLOR_MODES_ADDRESSABLE, channel_map={}, - addressable=False, - original_addressable=True, ), LEDENETModel( model_num=0xA2, models=["AK001-ZJ2104"], description="RGB Symphony [Addressable]", always_writes_white_and_colors=False, - nine_byte_read_protocol=False, # unverified + protocol=PROTOCOL_LEDENET_ADDRESSABLE, mode_to_color_mode={}, color_modes=COLOR_MODES_ADDRESSABLE, channel_map={}, - addressable=True, - original_addressable=False, ), LEDENETModel( model_num=0xA3, models=["K001-ZJ2148"], description="Magic Home Branded RGB Symphony [Addressable]", always_writes_white_and_colors=False, - nine_byte_read_protocol=False, # unverified + protocol=PROTOCOL_LEDENET_ADDRESSABLE, mode_to_color_mode={}, color_modes=COLOR_MODES_ADDRESSABLE, channel_map={}, - addressable=True, - original_addressable=False, ), LEDENETModel( model_num=0xD1, models=[], description="Digital Light", always_writes_white_and_colors=False, # Formerly rgbwprotocol - nine_byte_read_protocol=False, + protocol=PROTOCOL_LEDENET_8BYTE, mode_to_color_mode={}, color_modes={}, # no color modes -- UNVERIFIED channel_map={}, - addressable=False, - original_addressable=False, ), LEDENETModel( model_num=0xE1, models=[], description="Ceiling Light", always_writes_white_and_colors=False, # Formerly rgbwprotocol - nine_byte_read_protocol=False, + protocol=PROTOCOL_LEDENET_8BYTE, mode_to_color_mode={}, color_modes={}, # no color modes -- UNVERIFIED channel_map={}, - addressable=False, - original_addressable=False, ), LEDENETModel( model_num=0xE2, models=[], description="Ceiling Light Assist", always_writes_white_and_colors=False, # Formerly rgbwprotocol - nine_byte_read_protocol=False, + protocol=PROTOCOL_LEDENET_8BYTE, mode_to_color_mode={}, color_modes={}, # no color modes -- UNVERIFIED channel_map={}, - addressable=False, - original_addressable=False, ), ] @@ -554,12 +483,18 @@ MODEL_DESCRIPTIONS = {model.model_num: model.description for model in MODELS} CHANNEL_REMAP = {model.model_num: model.channel_map for model in MODELS} ORIGINAL_ADDRESSABLE_MODELS = { - model.model_num for model in MODELS if model.original_addressable + model.model_num + for model in MODELS + if model.protocol == PROTOCOL_LEDENET_ORIGINAL_ADDRESSABLE +} +ADDRESSABLE_MODELS = { + model.model_num + for model in MODELS + if model.protocol == PROTOCOL_LEDENET_ADDRESSABLE } -ADDRESSABLE_MODELS = {model.model_num for model in MODELS if model.addressable} RGBW_PROTOCOL_MODELS = { model.model_num for model in MODELS if model.always_writes_white_and_colors } USE_9BYTE_PROTOCOL_MODELS = { - model.model_num for model in MODELS if model.nine_byte_read_protocol + model.model_num for model in MODELS if model.protocol == PROTOCOL_LEDENET_9BYTE }