Skip to content

Commit

Permalink
Merge pull request #26 from TheMicDiet/wrgb2
Browse files Browse the repository at this point in the history
add support for further wrgb2 models
  • Loading branch information
TheMicDiet committed May 16, 2024
2 parents 6ffaeaa + 2eea840 commit 83bb482
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@
from .device import get_device_from_address, get_model_class_from_name
from .weekday_encoding import WeekdaySelect

UART_SERVICE_UUID = "6E400001-B5A3-F393-E0A9-E50E24DCCA9E"
UART_RX_CHAR_UUID = "6E400002-B5A3-F393-E0A9-E50E24DCCA9E"
UART_TX_CHAR_UUID = "6E400003-B5A3-F393-E0A9-E50E24DCCA9E"


app = typer.Typer()

msg_id = commands.next_message_id()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
CODE2MODEL = {}
for name, obj in inspect.getmembers(sys.modules[__name__]):
if inspect.isclass(obj) and issubclass(obj, BaseDevice):
CODE2MODEL[obj._model_code] = obj
for model_code in obj._model_codes:
CODE2MODEL[model_code] = obj


def get_model_class_from_name(device_name: str) -> Callable[[BLEDevice], BaseDevice]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ class AIIA2(BaseDevice):
"""Chihiros A II A 2 device Class."""

_model_name = "A II A2"
_model_code = "DYNA2"
_model_codes = ["DYNA2"]
_colors: dict[str, int] = {
# TODO validate that
"white": 0,
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,10 @@ def __get__(self, owner_self: object, owner_cls: ABCMeta) -> str: # type: ignor


class BaseDevice(ABC):
"""Base device class used by device classes.
TODO: Make it an abstract class
"""
"""Base device class used by device classes."""

_model_name: str | None = None
_model_code: str = ""
_model_codes: list[str] = []
_colors: dict[str, int] = {}
_msg_id = commands.next_message_id()
_logger: logging.Logger
Expand Down Expand Up @@ -99,9 +96,9 @@ def model_name(self) -> str | None:
return self._model_name

@_classproperty
def model_code(self) -> str:
"""Return the model code."""
return self._model_code
def model_codes(self) -> list[str]:
"""Return the model codes."""
return self._model_codes

@property
def colors(self) -> dict[str, int]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Fallback(BaseDevice):
"""Fallback device used when a device is not completely supported yet."""

_model_name = "fallback"
_model_code = ""
_model_codes = []
_colors: dict[str, int] = {
"white": 0,
"red": 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class TinyTerrariumEgg(BaseDevice):
"""Tiny Terraform egg device Class."""

_model_name = "Tiny Terrarium Egg"
_model_code = "DYDD"
_model_codes = ["DYDD"]
_colors: dict[str, int] = {
"red": 0,
"green": 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ class WRGBII(BaseDevice):
"""Chihiros WRGB II device Class."""

_model_name = "WRGB II"
_model_code = "DYNWRGB"
_model_code = ["DYNWRGB", "DYNW30", "DYNW45", "DYNW60", "DYNW90", "DYNW120"]
_colors: dict[str, int] = {
# TODO validate that
"white": 0,
"red": 1,
"green": 2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ class WRGBIIPro(BaseDevice):
"""Chihiros WRGB II Pro device Class."""

_model_name = "WRGB II Pro"
_model_code = "DYWPRO"
_model_codes = ["DYWPRO"]
# FIXME: channel for white doesn't work
_colors: dict[str, int] = {
"white": 0,
"red": 1,
Expand Down
22 changes: 21 additions & 1 deletion custom_components/chihiros/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,26 @@
"local_name": "DYNWRGB*",
"connectable": true
},
{
"local_name": "DYNW30*",
"connectable": true
},
{
"local_name": "DYNW45*",
"connectable": true
},
{
"local_name": "DYNW60*",
"connectable": true
},
{
"local_name": "DYNW90*",
"connectable": true
},
{
"local_name": "DYNW120*",
"connectable": true
},
{
"local_name": "DYWPRO*",
"connectable": true
Expand All @@ -31,7 +51,7 @@
"documentation": "https://github.com/TheMicDiet/chihiros-led-control",
"issue_tracker": "https://github.com/TheMicDiet/chihiros-led-control/issues",
"iot_class": "assumed_state",
"version": "0.1.2",
"version": "0.2.0",
"requirements": [
"bleak==0.21.1",
"bleak_retry_connector==3.5.0",
Expand Down

0 comments on commit 83bb482

Please sign in to comment.