aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2021-08-12 19:04:39 +0200
committerlonkaars <loek@pipeframe.xyz>2021-08-12 19:04:39 +0200
commita1821bb663f834295d94acaf3a8c531fb30848a9 (patch)
tree06ec24254533d20e466946d598621a8dcfe05b17
parent2319806262c0880c839f923c12cb995e26dbc2c3 (diff)
loading now!
-rw-r--r--.gitignore1
-rw-r--r--__init__.py10
-rw-r--r--__pycache__/driver.cpython-39.pycbin1832 -> 0 bytes
-rw-r--r--light.py78
4 files changed, 73 insertions, 16 deletions
diff --git a/.gitignore b/.gitignore
index 928bcdc..9d557af 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
venv/
+__pycache__/
diff --git a/__init__.py b/__init__.py
index 40b4d90..eb66857 100644
--- a/__init__.py
+++ b/__init__.py
@@ -1,5 +1,11 @@
+from homeassistant.core import HomeAssistant
+
DOMAIN = "beken"
+PLATFORMS = ["light"]
+
+def setup(hass: HomeAssistant, config):
+ hass.data[DOMAIN] = {}
+ return True
-def setup(hass, config):
- hass.states.set("beken.loaded", "yes")
+def setup_entry(hass, entry):
return True
diff --git a/__pycache__/driver.cpython-39.pyc b/__pycache__/driver.cpython-39.pyc
deleted file mode 100644
index 43ddd28..0000000
--- a/__pycache__/driver.cpython-39.pyc
+++ /dev/null
Binary files differ
diff --git a/light.py b/light.py
index c443728..6b5961f 100644
--- a/light.py
+++ b/light.py
@@ -1,26 +1,76 @@
-from homeassistant.components.light import LightEntity, ATTR_BRIGHTNESS, ATTR_COLOR_MODE
-from driver import BekenConnection, makemsg
+import homeassistant.helpers.config_validation as cv
+import voluptuous as vol
+from homeassistant.const import CONF_MAC
+from .driver import BekenConnection, makemsg
+from homeassistant.components.light import (
+ LightEntity,
+
+ SUPPORT_BRIGHTNESS,
+ SUPPORT_COLOR,
+ SUPPORT_WHITE_VALUE,
+
+ ATTR_BRIGHTNESS,
+ ATTR_RGBW_COLOR,
+
+ COLOR_MODE_RGBW,
+ PLATFORM_SCHEMA
+)
+
+PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
+ vol.Required("name"): cv.string,
+ vol.Required("address"): cv.string
+})
+
+SUPPORT_FEATURES_RGB = SUPPORT_BRIGHTNESS | SUPPORT_COLOR
+SUPPORT_FEATURES_WHITE = SUPPORT_BRIGHTNESS
+
+def setup_platform(hass, config, add_entities, discovery_info=None):
+ add_entities([ BekenLight(name=config["name"], address=config["address"]) ])
class BekenLight(LightEntity):
- def __init__(self):
- self._state = {
- "on": False,
- "brightness": 100,
- "lamp": "white",
- "saturation": 0,
- "hue": 0,
- }
+ def __init__(self, **kwargs):
+ self._name = kwargs["name"]
+ self._address = kwargs["address"]
+ self._on = False
+ self._brightness = 255
+ self._rgbw = (255, 255, 255, 255) # r, g, b, w
+
+ @property
+ def color_mode(self):
+ return COLOR_MODE_RGBW
+
+ @property
+ def supported_color_modes(self):
+ return set([ COLOR_MODE_RGBW ])
+
+ @property
+ def supported_features(self):
+ return SUPPORT_BRIGHTNESS | SUPPORT_COLOR | SUPPORT_WHITE_VALUE
+
+ @property
+ def unique_id(self):
+ return self._address
@property
def name(self):
- return "Beken LED"
+ return self._name
@property
def is_on(self):
- return self._state['on']
+ return self._on
+
+ @property
+ def brightness(self):
+ return self._brightness
+
+ @property
+ def rgbw_color(self):
+ return self._rgbw
def turn_on(self, **kwargs):
- self._state['on'] = True
+ self._on = True
+ self._brightness = kwargs.get(ATTR_BRIGHTNESS)
+ self._rgbw = kwargs.get(ATTR_RGBW_COLOR)
def turn_off(self, **kwargs):
- self._state['on'] = False
+ self._on = False