From b2592a2f4c62c555aa7d26a81cb433ca17253e39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Lov=C3=A9n?= Date: Mon, 17 Oct 2022 09:20:00 +0200 Subject: [PATCH] Fix dim levels --- .gitignore | 3 +- README.md | 40 +++++++++++++++++++ custom_components/plejd/light.py | 6 +-- .../plejd/pyplejd/plejd_device.py | 14 ++++--- 4 files changed, 54 insertions(+), 9 deletions(-) create mode 100644 README.md diff --git a/.gitignore b/.gitignore index 9201006..f784824 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ /*/ !.gitignore !custom_components/ -**/__pycache__/ \ No newline at end of file +**/__pycache__/ +!README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..c28bed7 --- /dev/null +++ b/README.md @@ -0,0 +1,40 @@ +Plejd integration for Home Assistant +=== + +This integration is a work in progress. + +I do not guarantee it will work or even that it will not harm your system. I don't see what harm it *could* cause, but I promise nothing. + +## Installation for testing + +- Make sure you have a working Bluetooth integration in Home Assistant (a bluetooth proxy should work too) +- Put the `plejd` directory in your `/custom_components`. +- Restart Home Assistant +- Hopefully, your Plejd mesh will be auto discovered and you should see a message popping up in your integrations page. +- Log in with the credentials you use in the Plejd app when prompted (email address and password) + +## Current limitations + +- I only have a single DIM-01 device, so that's the only one I know for sure works. +- Only one channel per device is expected to work right now. E.g. only one lamp connected to a DIM-02 will show up in Home Assistant. + +## About connections + +Plejd devices doesn't seem to like to have multiple connections going. +Once a controller like the official Plejd app or Home Assistant connects, they will hide their precense from everyone else until a time after that connection is broken. + +That means that if you only have one Plejd device you may not be able to use Home Assistant and the app to controll the device at the same time, and either may have a hard time connecting while the other is running. + +Even after turning off the app or Home Assistant it may take 30 minutes to several hours before the othe rcan connect again. Turning off bluetooth on the last connected device or cutting power to the Plejd for a minute may help. + + +## Getting more debug information + +Add this to your Home Assistant configuration.yaml to get as much information as possible + +```yaml +logger: + default: warn + logs: + custom_components.plejd: debug +``` diff --git a/custom_components/plejd/light.py b/custom_components/plejd/light.py index 2909ba1..8231bd6 100644 --- a/custom_components/plejd/light.py +++ b/custom_components/plejd/light.py @@ -40,7 +40,7 @@ class PlejdLight(LightEntity, CoordinatorEntity): @property def available(self): - return self._data.get("state", None) is not None + return self.device.available @property def device_info(self): @@ -68,11 +68,11 @@ class PlejdLight(LightEntity, CoordinatorEntity): @property def is_on(self): - return self._data.get("state") + return self.device.state @property def brightness(self): - return self._data.get("dim",0) + return self.device.dim @property def supported_color_modes(self): diff --git a/custom_components/plejd/pyplejd/plejd_device.py b/custom_components/plejd/pyplejd/plejd_device.py index 0e9ef5c..bb656e2 100644 --- a/custom_components/plejd/pyplejd/plejd_device.py +++ b/custom_components/plejd/pyplejd/plejd_device.py @@ -20,10 +20,10 @@ HARDWARE_TYPES = { "7": Device("REL-01", SWITCH, False), "8": Device("SPR-01", SWITCH, False), "10": Device("WRT-01", SWITCH, False), - "11": Device("DIM-01", LIGHT, True), + "11": Device("DIM-01-2P", LIGHT, True), "13": Device("Generic", LIGHT, False), - "14": Device("DIM-01", LIGHT, True), - "15": Device("DIM-02", LIGHT, True), + "14": Device("DIM-01-LC", LIGHT, True), + "15": Device("DIM-02-LC", LIGHT, True), "17": Device("REL-01-2P", SWITCH, False), "18": Device("REL-02", SWITCH, False), "20": Device("SPR-01", SWITCH, False), @@ -43,13 +43,17 @@ class PlejdDevice: self._state = None self._dim = None + @property + def available(self): + return self._state is not None + @property def state(self): - return self._state + return self._state if self.available else False @property def dim(self): - return self._dim/255 + return self._dim/255 if self.available else 0 @property def BLE_address(self):