Skip to content

Commit

Permalink
feat(device): add Z2M support for ZS230002 (Linkind)
Browse files Browse the repository at this point in the history
related to #347 @kloodhu
  • Loading branch information
xaviml committed Aug 23, 2021
1 parent 8298dc1 commit a00d568
Show file tree
Hide file tree
Showing 11 changed files with 91 additions and 2 deletions.
1 change: 1 addition & 0 deletions apps/controllerx/controllerx.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from cx_devices.aurora import *
from cx_devices.ikea import *
from cx_devices.legrand import *
from cx_devices.linkind import *
from cx_devices.livarno import *
from cx_devices.lutron import *
from cx_devices.muller_licht import *
Expand Down
1 change: 1 addition & 0 deletions apps/controllerx/cx_const.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class Light:
HOLD_XY_COLOR_TOGGLE = "hold_xycolor_toggle"
XYCOLOR_FROM_CONTROLLER = "xycolor_from_controller"
COLORTEMP_FROM_CONTROLLER = "colortemp_from_controller"
BRIGHTNESS_FROM_CONTROLLER = "brightness_from_controller"


class MediaPlayer:
Expand Down
15 changes: 15 additions & 0 deletions apps/controllerx/cx_core/type/light_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ def get_predefined_actions_mapping(self) -> PredefinedActionsMapping:
),
Light.XYCOLOR_FROM_CONTROLLER: self.xycolor_from_controller,
Light.COLORTEMP_FROM_CONTROLLER: self.colortemp_from_controller,
Light.BRIGHTNESS_FROM_CONTROLLER: self.brightness_from_controller,
}

async def check_remove_transition(self, on_from_user: bool) -> bool:
Expand Down Expand Up @@ -523,6 +524,20 @@ async def colortemp_from_controller(self, extra: Optional[EventData]) -> None:
return
await self._on(color_temp=extra["action_color_temperature"])

@action
async def brightness_from_controller(self, extra: Optional[EventData]) -> None:
if extra is None:
self.log("No event data present", level="WARNING")
return
if isinstance(self.integration, Z2MIntegration):
if "action_level" not in extra:
self.log(
"`action_level` is not present in the MQTT payload",
level="WARNING",
)
return
await self._on(brightness=extra["action_level"])

@property
async def supported_color_modes(self) -> Set[str]:
if self._supported_color_modes is None or self.update_supported_features:
Expand Down
20 changes: 20 additions & 0 deletions apps/controllerx/cx_devices/linkind.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from cx_const import DefaultActionsMapping, Light
from cx_core import LightController


class ZS23000278LightController(LightController):
def get_z2m_actions_mapping(self) -> DefaultActionsMapping:
return {
"on": Light.ON,
"off": Light.OFF,
"brightness_step_up": Light.CLICK_BRIGHTNESS_UP,
"brightness_step_down": Light.CLICK_BRIGHTNESS_DOWN,
"brightness_move_to_level": Light.BRIGHTNESS_FROM_CONTROLLER,
"brightness_move_up": Light.HOLD_BRIGHTNESS_UP,
"brightness_move_down": Light.HOLD_BRIGHTNESS_DOWN,
"brightness_stop": Light.RELEASE,
"color_temperature_move": Light.COLORTEMP_FROM_CONTROLLER,
"color_temperature_move_up": Light.CLICK_COLOR_TEMP_UP,
"color_temperature_move_down": Light.CLICK_COLOR_TEMP_DOWN,
"color_move": Light.XYCOLOR_FROM_CONTROLLER,
}
31 changes: 31 additions & 0 deletions docs/_data/controllers/ZS230002.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: ZS230002 (Linkind)
device_support:
- type: Light
domain: light
controller: ZS23000278LightController
delay: 350
mapping:
- "Click on/off → Toggle"
- "Click arrow up in dim mode → Brighten up (1 step)"
- "Click arrow down in dim mode → Dim down (1 step)"
- "Hold arrow up in dim mode → Brighten up"
- "Hold arrow down in dim mode → Dim down"
- "Click arrow up in color temp mode → Color temp up (1 step)"
- "Click arrow down in color temp mode → Color temp down (1 step)"

integrations:
- name: Zigbee2MQTT
codename: z2m
actions:
- '"on" → Click on/off'
- '"off" → Click on/off'
- "brightness_step_up → Click arrow up in dim mode"
- "brightness_step_down → Click arrow down in dim mode"
- "brightness_move_to_level → "
- "brightness_move_up → Hold arrow up in dim mode"
- "brightness_move_down → Hold arrow down in dim mode"
- "brightness_stop → Release arrow up/down"
- "color_temperature_move → "
- "color_temperature_move_up → Click arrow up in color temp mode"
- "color_temperature_move_down → Click arrow down in color temp mode"
- "color_move → "
Binary file added docs/assets/img/ZS230002.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions docs/controllers/ZS230002.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
layout: controller
title: ZS230002 (Linkind)
device: ZS230002
---
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
entity_state: "on"
fired_actions: ["brightness_move_to_level"]
extra:
action_level: 42
expected_calls:
- service: light/turn_on
data:
entity_id: light.my_light
brightness: 42
9 changes: 9 additions & 0 deletions tests/integ_tests/linkind_ZS23000278_z2m/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
example_app:
module: controllerx
class: ZS23000278LightController
integration:
name: z2m
listen_to: mqtt
controller: my_controller
light: light.my_light

Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ expected_calls:
data:
entity_id: light.my_light
xy_color: !!python/tuple [0.12, 0.08]
expected_calls_count: 1
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ expected_calls:
data:
entity_id: light.my_light
xy_color: !!python/tuple [0.12, 0.08]
expected_calls_count: 1

0 comments on commit a00d568

Please sign in to comment.