Skip to content

Commit

Permalink
feat(device): add MLI-404002 device with Z2M and ZHA support
Browse files Browse the repository at this point in the history
related to #247
  • Loading branch information
xaviml committed Feb 21, 2021
1 parent 3776757 commit eca13ee
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 4 deletions.
38 changes: 38 additions & 0 deletions apps/controllerx/cx_devices/muller_licht.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from cx_const import DefaultActionsMapping, Light
from cx_core import LightController
from cx_core.controller import Controller
from cx_core.integration import EventData


class MLI404011LightController(LightController):
Expand Down Expand Up @@ -42,3 +44,39 @@ def get_deconz_actions_mapping(self) -> DefaultActionsMapping:
# 11002: "", # fire button
# 12002: "", # heart button
}


class MLI404002Controller(Controller):
def get_zha_action(self, data: EventData) -> str:
command = data["command"]
if command not in ("move", "step"):
return command
args = data["args"]
direction_mapping = {0: "up", 1: "down"}
return f"{command}_{direction_mapping[args[0]]}"


class MLI404002LightController(MLI404002Controller, LightController):
def get_z2m_actions_mapping(self) -> DefaultActionsMapping:
return {
"on": Light.TOGGLE,
"off": Light.TOGGLE,
"brightness_step_up": Light.CLICK_BRIGHTNESS_UP,
"brightness_step_down": Light.CLICK_BRIGHTNESS_DOWN,
"brightness_move_up": Light.HOLD_BRIGHTNESS_UP,
"brightness_move_down": Light.HOLD_BRIGHTNESS_DOWN,
"brightness_stop": Light.RELEASE,
"recall_1": Light.ON_FULL_BRIGHTNESS,
}

def get_zha_actions_mapping(self) -> DefaultActionsMapping:
return {
"on": Light.TOGGLE,
"off": Light.TOGGLE,
"move_up": Light.HOLD_BRIGHTNESS_UP,
"move_down": Light.HOLD_BRIGHTNESS_DOWN,
"stop": Light.RELEASE,
"step_up": Light.CLICK_BRIGHTNESS_UP,
"step_down": Light.CLICK_BRIGHTNESS_DOWN,
"recall": Light.ON_FULL_BRIGHTNESS,
}
37 changes: 37 additions & 0 deletions docs/_data/controllers/MLI-404002.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: MLI-404002 (Müller Licht)
device_support:
- type: Light
domain: light
controller: MLI404002LightController
delay: 500
mapping:
- "Toggle button → Toggle"
- "Click 🔆 → Brighten up (1 step)"
- "Click 🔅 → Dim down (1 step)"
- "Click cold → Color temp down / Left color wheel (1 step) (not for z2m)"
- "Click warm → Color temp up / Right color wheel (1 step) (not for z2m)"
- "Hold 🔆 → Brighten up"
- "Hold 🔅→ Dim down"
integrations:
- name: Zigbee2MQTT
codename: z2m
actions:
- '"on" → Toggle button'
- '"off" → Toggle button'
- brightness_step_down → Click 🔅
- brightness_move_down → Hold 🔅
- brightness_stop → Release 🔅/🔆
- brightness_step_up → Click 🔆
- brightness_move_up → Hold 🔆
- recall_1 → Click arrow back
- name: ZHA
codename: zha
actions:
- '"on" → Toggle button'
- '"off" → Toggle button'
- move_up → Hold 🔆
- move_down → Hold 🔅
- stop → Release 🔅/🔆
- step_up → Click 🔆
- step_down → Click 🔅
- recall → Click arrow back
8 changes: 4 additions & 4 deletions docs/_data/controllers/MLI-404011.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ device_support:
- "Hold 🔆 → Brighten up"
- "Hold 🔅→ Dim down"
integrations:
- name: deCONZ
codename: deconz
- name: Zigbee2MQTT
codename: z2m
actions:
- on → Toggle button
- off → Toggle button
- '"on" → Toggle button'
- '"off" → Toggle button'
- brightness_down_click → Click 🔅
- brightness_down_hold → Hold 🔅
- brightness_down_release → Release 🔅
Expand Down
Binary file added docs/assets/img/MLI-404002.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/MLI-404002.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
layout: controller
title: MLI-404002 (Müller Licht)
device: MLI-404002
---
46 changes: 46 additions & 0 deletions tests/unit_tests/cx_devices/muller_licht_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import pytest
from cx_core.integration import EventData
from cx_devices.muller_licht import MLI404002LightController


@pytest.mark.parametrize(
"data, expected_action",
[
(
{"command": "on", "args": []},
"on",
),
(
{"command": "off", "args": []},
"off",
),
(
{"command": "step", "args": [0, 43, 3]},
"step_up",
),
(
{"command": "move", "args": [0, 100]},
"move_up",
),
(
{"command": "step", "args": [1, 43, 3]},
"step_down",
),
(
{"command": "move", "args": [1, 100]},
"move_down",
),
(
{"command": "stop", "args": []},
"stop",
),
(
{"command": "recall", "args": [16387, 1]},
"recall",
),
],
)
def test_zha_action_MLI404002(data: EventData, expected_action: str):
sut = MLI404002LightController() # type: ignore
action = sut.get_zha_action(data)
assert action == expected_action

0 comments on commit eca13ee

Please sign in to comment.