Skip to content

Commit

Permalink
Add availability and effects => Version 1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
asterix11 committed May 1, 2022
1 parent 6855649 commit 62cbe39
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 6 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
# Jablotron RS485 Home Assistant Integration

For connecting to a JA-121-T using a Modbus to Ethernet adapter.
# Lumic HomeAssistant Integration
For connecting your HomeAssistant instance to the Lumic lighting system.
2 changes: 2 additions & 0 deletions custom_components/lumic/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
name
hardwareAddress
deviceType
online
room {
name
}
Expand All @@ -41,6 +42,7 @@
name
hardwareAddress
deviceType
online
room {
name
}
Expand Down
92 changes: 91 additions & 1 deletion custom_components/lumic/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
from homeassistant.components.light import (
ATTR_BRIGHTNESS,
ATTR_HS_COLOR,
ATTR_EFFECT,
SUPPORT_BRIGHTNESS,
SUPPORT_COLOR,
SUPPORT_EFFECT,
LightEntity,
)
import homeassistant.util.color as color_util
Expand Down Expand Up @@ -122,14 +124,70 @@ def __init__(self, api, device_id, device_uuid, name):
self._brightness = 0
self._hs_color = [0, 0]
self._state = False
self._scenes: list[str] = [
"Normal",
"Flashing",
"DeCongest",
"ColorWipe",
"ColorWipeBackwards",
"ColorWipeRandom",
"RandomColor",
"RandomPixelColorSingle",
"RainbowAll",
"RainbowStream",
"Scanner",
"DualScanner",
"RunningLight",
"Sparkle",
"RandomSparkle",
"HyperSparkle",
"RunningColor",
"LarsonScanner",
"Comet",
"Fireworks",
"RandomFireworks",
"FireFlicker",
"FireFlickerLight",
"FireFlickerHeavy",
"FireFlickerNaturely"
]
self._scenes_mapping: list[int] = [
"0",
"1",
"2",
"3",
"5",
"7",
"8",
"9",
"11",
"12",
"13",
"14",
"18",
"19",
"20",
"25",
"40",
"43",
"44",
"45",
"46",
"48",
"49",
"50",
"55"
]
self._effect = None
self._available = False
self._supported_features = self._determine_features()
self._logger = logging.getLogger(
("%s:%s:<%s>") % (__name__, self.__class__.__name__, self._device_uuid)
)

def _determine_features(self):
"""Get features supported by the device."""
features = SUPPORT_BRIGHTNESS | SUPPORT_COLOR
features = SUPPORT_BRIGHTNESS | SUPPORT_COLOR | SUPPORT_EFFECT

return features

Expand Down Expand Up @@ -162,6 +220,12 @@ async def async_turn_on(self, **kwargs) -> None:
await self._api.setDeviceParameter(
self._device_uuid, "COLOR_WHITE", str(color_white)
)
if ATTR_EFFECT in kwargs:
effect = kwargs[ATTR_EFFECT]
index = self._scenes.index(effect)
await self._api.setDeviceParameter(
self._device_uuid, "MODE", str(self._scenes_mapping[index])
)
if not self._state:
await self._api.setDeviceParameter(self._device_uuid, "STATE", "1")
self._state = True
Expand Down Expand Up @@ -190,6 +254,7 @@ async def async_update(self):
result = await self._api.getDeviceById(self._device_id)

self._mac = result["hardwareAddress"]
self._available = result["online"] == 1

color = None
color_white = None
Expand All @@ -213,6 +278,14 @@ async def async_update(self):
color = i["value"]
if self._supported_features & SUPPORT_COLOR and i["type"] == "COLOR_WHITE":
color_white = i["valueNumeric"]

# Effect
if (
self._supported_features & SUPPORT_EFFECT
and i["type"] == "MODE"
):
index = self._scenes_mapping.index(i["value"])
self._effect = self._scenes[index]

if (color != None and color_white != None):
r, g, b = int("0x%s" % color[1:3], base=16), int("0x%s" % color[3:5], base=16), int("0x%s" % color[5:7], base=16)
Expand Down Expand Up @@ -284,3 +357,20 @@ def min_mireds(self):
def supported_features(self) -> int:
"""Flag supported features."""
return self._supported_features

@property
def effect(self):
"""Return the current effect."""
return self._effect

@property
def effect_list(self):
"""Return the list of supported effects.
URL: https://docs.pro.wizconnected.com/#light-modes
"""
return self._scenes

@property
def available(self):
"""Return if able to retrieve information from device or not."""
return self._available
2 changes: 1 addition & 1 deletion custom_components/lumic/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"domain": "lumic",
"version": "1.0.1",
"name": "Lumic Lighting",
"version": "1.1.0",
"config_flow": true,
"documentation": "https://github.com/asterix11/hass-lumic",
"issue_tracker": "https://github.com/asterix11/hass-lumic/issues",
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "lumic"
version = "1.0.1"
version = "1.1.0"
description = "Lumic Home Assistant Integration"
authors = ["Asterix11 <[email protected]>"]
license = "MIT"
Expand Down

0 comments on commit 62cbe39

Please sign in to comment.