Skip to content

Commit

Permalink
Add support gestures and ambient light for T5-3C-86 #1183
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed Sep 26, 2023
1 parent ab69c84 commit ddc6e8c
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 1 deletion.
4 changes: 4 additions & 0 deletions custom_components/sonoff/core/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
XLightGroup,
XLightL1,
XLightL3,
XT5Light,
)
from ..number import XPulseWidth
from ..remote import XRemote
Expand All @@ -51,6 +52,7 @@
XEnergySensorDualR3,
XEnergySensorPOWR3,
XEnergyTotal,
XT5Action,
)
from ..switch import (
XSwitch,
Expand Down Expand Up @@ -335,6 +337,8 @@ def spec(cls, base: str = None, enabled: bool = None, **kwargs) -> type:
], # Sonoff POWR3
# https://github.com/AlexxIT/SonoffLAN/issues/984
195: [XTemperatureTH], # NSPanel Pro
# T5-3C-86 https://github.com/AlexxIT/SonoffLAN/issues/1183
211: [Switch1, Switch2, Switch3, XT5Light, XT5Action],
1000: [XRemoteButton, Battery], # zigbee_ON_OFF_SWITCH_1000
1256: [spec(XSwitch, base="light")], # ZCL_HA_DEVICEID_ON_OFF_LIGHT
1257: [spec(XLightD1, base="light")], # ZigbeeWhiteLight
Expand Down
30 changes: 30 additions & 0 deletions custom_components/sonoff/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -1027,3 +1027,33 @@ async def async_turn_on(

async def async_turn_off(self, **kwargs) -> None:
await self.ewelink.send(self.device, {"lightswitch": 0})


class XT5Light(XEntity, LightEntity):
params = {"lightSwitch", "lightMode"}

_attr_effect_list = ["0", "1", "2", "3", "4", "5", "6", "7"]
_attr_supported_features = SUPPORT_EFFECT

def set_state(self, params: dict):
if "lightSwitch" in params:
self._attr_is_on = params["lightSwitch"] == "on"

if "lightMode" in params:
self._attr_effect = str(params["lightMode"])

async def async_turn_on(
self, brightness: int = None, effect: str = None, **kwargs
) -> None:
params = {}

if effect and effect != "0":
params["lightMode"] = int(effect)

if not params:
params["lightSwitch"] = "on"

await self.ewelink.send(self.device, params)

async def async_turn_off(self, **kwargs) -> None:
await self.ewelink.send(self.device, {"lightSwitch": "off"})
26 changes: 25 additions & 1 deletion custom_components/sonoff/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,10 +305,11 @@ def internal_available(self) -> bool:


class XRemoteButton(XEntity, SensorEntity):
_attr_native_value = ""

def __init__(self, ewelink: XRegistry, device: dict):
XEntity.__init__(self, ewelink, device)
self.params = {"key"}
self._attr_native_value = ""

def set_state(self, params: dict):
button = params.get("outlet")
Expand All @@ -324,6 +325,29 @@ async def clear_state(self):
self._async_write_ha_state()


class XT5Action(XEntity, SensorEntity):
uid = "action"
_attr_native_value = ""

def __init__(self, ewelink: XRegistry, device: dict):
XEntity.__init__(self, ewelink, device)
self.params = {"triggerType", "slide"}

def set_state(self, params: dict):
if params.get("triggerType") == 2:
self._attr_native_value = "touch"
asyncio.create_task(self.clear_state())

if slide := params.get("slide"):
self._attr_native_value = f"slide_{slide}"
asyncio.create_task(self.clear_state())

async def clear_state(self):
await asyncio.sleep(0.5)
self._attr_native_value = ""
self._async_write_ha_state()


class XUnknown(XEntity, SensorEntity):
_attr_device_class = SensorDeviceClass.TIMESTAMP

Expand Down
40 changes: 40 additions & 0 deletions tests/test_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
XLightL1,
XLightL3,
XLightB05B,
XT5Light,
)
from custom_components.sonoff.number import XNumber, XPulseWidth
from custom_components.sonoff.sensor import (
Expand All @@ -43,6 +44,7 @@
XTemperatureNS,
XUnknown,
XEnergySensorDualR3,
XT5Action,
)
from custom_components.sonoff.switch import (
XSwitch,
Expand Down Expand Up @@ -1596,3 +1598,41 @@ def test_minir4():

switch: SwitchEntity = next(e for e in entities if e.uid == "detach")
assert switch.state == "on"


def test_t5():
entities = get_entitites(
{
"extra": {"uiid": 211},
"params": {
"switches": [
{"outlet": 0, "switch": "on"},
{"outlet": 1, "switch": "off"},
{"outlet": 2, "switch": "off"},
],
"lightSwitch": "off",
"lightMode": 4,
"slide": 2,
},
"model": "T5-3C-86",
}
)

light: XT5Light = entities[3]
assert light.state == "off"
assert light.effect == "4"

light.internal_update({"lightSwitch": "on"})
assert light.state == "on"

light.internal_update({"lightMode": 1})
assert light.effect == "1"

action: XT5Action = entities[4]
assert action.state == ""

action.internal_update({"triggerType": 2})
assert action.state == "touch"

action.internal_update({"slide": 2})
assert action.state == "slide_2"

0 comments on commit ddc6e8c

Please sign in to comment.