Skip to content

Commit

Permalink
Fix L3-5M-P control issues #1394
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed Sep 8, 2024
1 parent cc10931 commit b2ee4f5
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
8 changes: 8 additions & 0 deletions custom_components/sonoff/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,14 @@ def set_state(self, params: dict):
None,
)

def get_params(self, brightness, color_temp, rgb_color, effect) -> dict:
# fix https://github.com/AlexxIT/SonoffLAN/issues/1394
if brightness is not None and rgb_color is None:
rgb_color = self.rgb_color
if brightness is None and rgb_color is not None:
brightness = self.brightness
return super().get_params(brightness, color_temp, rgb_color, effect)


B02_MODE_PAYLOADS = {
"nightLight": {"br": 5, "ct": 0},
Expand Down
33 changes: 32 additions & 1 deletion tests/test_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -1920,7 +1920,18 @@ def test_zbminil2():

def test_1394():
# https://github.com/AlexxIT/SonoffLAN/issues/1394
entities = get_entitites({"extra": {"uiid": 173}})
device = {
"extra": {"uiid": 173},
"params": {
"bright": 50,
"colorB": 0,
"colorG": 0,
"colorR": 255,
"light_type": 1,
"mode": 1,
},
}
entities = get_entitites(device)
light: XLightL3 = entities[0]

# noinspection PyTypeChecker
Expand All @@ -1936,6 +1947,26 @@ def test_1394():
"mode": 1,
}

await_(light.async_turn_on(brightness=255))
assert registry.send_args[1] == {
"bright": 100,
"colorB": 0,
"colorG": 0,
"colorR": 255,
"light_type": 1,
"mode": 1,
}

await_(light.async_turn_on(rgb_color=(0, 255, 0)))
assert registry.send_args[1] == {
"bright": 50,
"colorB": 0,
"colorG": 255,
"colorR": 0,
"light_type": 1,
"mode": 1,
}


def test_snzb_03p():
device = {
Expand Down

0 comments on commit b2ee4f5

Please sign in to comment.