Skip to content

Commit

Permalink
Add support for original rgbw protocol (#380)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored Sep 4, 2022
1 parent 4571e25 commit 4150dca
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 11 deletions.
2 changes: 1 addition & 1 deletion flux_led/aiodevice.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import asyncio
from datetime import datetime
import logging
import time
from datetime import datetime
from typing import Any, Callable, Dict, List, Optional, Tuple, Union

from .aioprotocol import AIOLEDENETProtocol
Expand Down
2 changes: 1 addition & 1 deletion flux_led/aioprotocol.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import asyncio
from asyncio.transports import BaseTransport, WriteTransport
import logging
from asyncio.transports import BaseTransport, WriteTransport
from typing import Any, Callable, Optional, cast

_LOGGER = logging.getLogger(__name__)
Expand Down
8 changes: 6 additions & 2 deletions flux_led/base_device.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import colorsys
from dataclasses import asdict, is_dataclass
from enum import Enum
import logging
import random
import time
from dataclasses import asdict, is_dataclass
from enum import Enum
from typing import Any, Dict, Iterable, List, Optional, Set, Tuple, Type, Union

from .const import ( # imported for back compat, remove once Home Assistant no longer uses
Expand Down Expand Up @@ -90,6 +90,7 @@
PROTOCOL_LEDENET_CCT,
PROTOCOL_LEDENET_ORIGINAL,
PROTOCOL_LEDENET_ORIGINAL_CCT,
PROTOCOL_LEDENET_ORIGINAL_RGBW,
PROTOCOL_LEDENET_SOCKET,
LEDENETAddressableDeviceConfiguration,
LEDENETOriginalRawState,
Expand All @@ -107,6 +108,7 @@
ProtocolLEDENETCCT,
ProtocolLEDENETOriginal,
ProtocolLEDENETOriginalCCT,
ProtocolLEDENETOriginalRGBW,
ProtocolLEDENETSocket,
RemoteConfig,
)
Expand Down Expand Up @@ -137,6 +139,7 @@
ProtocolLEDENETAddressableA3,
ProtocolLEDENETOriginal,
ProtocolLEDENETOriginalCCT,
ProtocolLEDENETOriginalRGBW,
ProtocolLEDENETCCT,
ProtocolLEDENETSocket,
ProtocolLEDENETAddressableChristmas,
Expand Down Expand Up @@ -166,6 +169,7 @@
PROTOCOL_NAME_TO_CLS = {
PROTOCOL_LEDENET_ORIGINAL: ProtocolLEDENETOriginal,
PROTOCOL_LEDENET_ORIGINAL_CCT: ProtocolLEDENETOriginalCCT,
PROTOCOL_LEDENET_ORIGINAL_RGBW: ProtocolLEDENETOriginalRGBW,
PROTOCOL_LEDENET_8BYTE: ProtocolLEDENET8Byte,
PROTOCOL_LEDENET_8BYTE_AUTO_ON: ProtocolLEDENET8ByteAutoOn,
PROTOCOL_LEDENET_8BYTE_DIMMABLE_EFFECTS: ProtocolLEDENET8ByteDimmableEffects,
Expand Down
2 changes: 1 addition & 1 deletion flux_led/const.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""FluxLED Models Database."""

from enum import Enum
import sys
from enum import Enum

if sys.version_info >= (3, 8):
from typing import Final # pylint: disable=no-name-in-module
Expand Down
2 changes: 1 addition & 1 deletion flux_led/fluxled.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
import asyncio
import datetime
import logging
from optparse import OptionGroup, OptionParser, Values
import sys
from optparse import OptionGroup, OptionParser, Values
from typing import Any, List, Optional, Tuple

from .aio import AIOWifiLedBulb
Expand Down
42 changes: 39 additions & 3 deletions flux_led/protocol.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
"""FluxLED Protocols."""

from abc import abstractmethod
import colorsys
import contextlib
from dataclasses import dataclass
import datetime
from enum import Enum
import logging
from abc import abstractmethod
from dataclasses import dataclass
from enum import Enum
from typing import Dict, List, NamedTuple, Optional, Tuple, Union

from .const import (
Expand Down Expand Up @@ -74,6 +74,7 @@ class PowerRestoreStates:

# Protocol names
PROTOCOL_LEDENET_ORIGINAL = "LEDENET_ORIGINAL"
PROTOCOL_LEDENET_ORIGINAL_RGBW = "LEDENET_ORIGINAL_RGBW"
PROTOCOL_LEDENET_ORIGINAL_CCT = "LEDENET_ORIGINAL_CCT"
PROTOCOL_LEDENET_9BYTE = "LEDENET"
PROTOCOL_LEDENET_9BYTE_AUTO_ON = "LEDENET_AUTO_ON"
Expand Down Expand Up @@ -893,6 +894,41 @@ def named_raw_state(self, raw_state: bytes) -> LEDENETOriginalRawState:
return LEDENETOriginalRawState(*raw_bytearray)


class ProtocolLEDENETOriginalRGBW(ProtocolLEDENETOriginal):
@property
def name(self) -> str:
"""The name of the protocol."""
return PROTOCOL_LEDENET_ORIGINAL_RGBW

def construct_levels_change(
self,
persist: int,
red: Optional[int],
green: Optional[int],
blue: Optional[int],
warm_white: Optional[int],
cool_white: Optional[int],
write_mode: LevelWriteMode,
) -> List[bytearray]:
"""The bytes to send for a level change request."""
# sample message for original LEDENET RGBW protocol (w/o checksum at end)
return [
self.construct_message(
bytearray(
[
0x56,
red or 0x00,
green or 0x00,
blue or 0x00,
warm_white or 0x00,
write_mode.value,
0xAA,
]
)
)
]


class ProtocolLEDENETOriginalCCT(ProtocolLEDENETOriginal):
@property
def name(self) -> str:
Expand Down
2 changes: 1 addition & 1 deletion flux_led/scanner.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import asyncio
import contextlib
from datetime import date
import logging
import select
import socket
import sys
import time
from datetime import date
from typing import Dict, List, Optional, Tuple, Union, cast

from .const import (
Expand Down
2 changes: 1 addition & 1 deletion flux_led/utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import ast
from collections import namedtuple
import colorsys
import contextlib
import datetime
from collections import namedtuple
from typing import Iterable, List, Optional, Tuple, Union, cast

import webcolors # type: ignore
Expand Down

0 comments on commit 4150dca

Please sign in to comment.