Skip to content

Commit

Permalink
Add support CK-BL602-W102SW18-01(226) #1425
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed Sep 7, 2024
1 parent 8363fb1 commit 499fe0b
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 2 deletions.
10 changes: 10 additions & 0 deletions custom_components/sonoff/core/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
XZigbeeSwitches,
XSwitchPOWR3,
XDetach,
XBoolSwitch,
)

# supported custom device_class
Expand Down Expand Up @@ -371,6 +372,15 @@ def spec(cls, base: str = None, enabled: bool = None, **kwargs) -> type:
211: [Switch1, Switch2, Switch3, XT5Light, XT5Action], # T5-3C-86
# https://github.com/AlexxIT/SonoffLAN/issues/1251
212: [Switch1, Switch2, Switch3, Switch4, XT5Light, XT5Action], # T5-4C-86
226: [
XBoolSwitch,
LED,
RSSI,
spec(XSensor, param="phase_0_c", uid="current"),
spec(XSensor, param="phase_0_p", uid="power"),
spec(XSensor, param="phase_0_v", uid="voltage"),
spec(XEnergyTotal, param="totalPower", uid="energy"),
], # CK-BL602-W102SW18-01(226)
1000: [XRemoteButton, Battery], # zigbee_ON_OFF_SWITCH_1000
# https://github.com/AlexxIT/SonoffLAN/issues/1195
1256: [spec(XSwitch)], # ZCL_HA_DEVICEID_ON_OFF_LIGHT
Expand Down
4 changes: 2 additions & 2 deletions custom_components/sonoff/core/ewelink/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,8 @@ def update_device(self, device: XDevice):
uiid = device["extra"]["uiid"]

# [5] POW, [32] POWR2, [182] S40, [190] POWR3 - one channel, only cloud update
# [181] THR316D/THR320D
if uiid in (5, 32, 182, 190, 181):
# [181] THR316D/THR320D, [226] CK-BL602-W102SW18-01
if uiid in (5, 32, 182, 190, 181, 226):
if self.can_cloud(device):
params = {"uiActive": 60}
asyncio.create_task(self.cloud.send(device, params, timeout=0))
Expand Down
13 changes: 13 additions & 0 deletions custom_components/sonoff/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,16 @@ async def async_turn_on(self, **kwargs):

async def async_turn_off(self):
await self.ewelink.send_cloud(self.device, {"relaySeparation": 0})


class XBoolSwitch(XEntity, SwitchEntity):
params = {"switch"}

def set_state(self, params: dict):
self._attr_is_on = params["switch"]

async def async_turn_on(self, *args, **kwargs):
await self.ewelink.send(self.device, {"switch": True})

async def async_turn_off(self):
await self.ewelink.send(self.device, {"switch": False})
62 changes: 62 additions & 0 deletions tests/test_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
XSwitchTH,
XToggle,
XZigbeeSwitches,
XBoolSwitch,
)
from . import init, save_to, DEVICEID, DummyRegistry

Expand Down Expand Up @@ -1959,3 +1960,64 @@ def test_snzb_03p():
assert entities[1].state == "on"
assert entities[2].state == 100
assert entities[3].state == -68


def test_226():
device = {
"extra": {"uiid": 226},
"params": {
"bindInfos": "***",
"version": 8,
"rssi": -77,
"fwVersion": "1.0.0",
"switch": True,
"pulse": "off",
"pulseWidth": 1000,
"sledOnline": "on",
"startup": "off",
"prepaid_support": True,
"alarm_v_min": -1,
"alarm_v_max": -1,
"alarm_c_min": -1,
"alarm_c_max": -1,
"alarm_p_min": -1,
"alarm_p_max": -1,
"availablePower": 0,
"prepaidEnale": False,
"prepaidLowBalanceAlert": False,
"prepaidLowest": 0,
"min_p_upper": 5000,
"min_p_lower": 1,
"max_p_upper": 15000,
"max_p_lower": 1,
"min_v_upper": 220,
"min_v_lower": 76,
"max_v_upper": 300,
"max_v_lower": 220,
"max_c_upper": 63,
"max_c_lower": 0.1,
"calibrateFlag": False,
"ssid": "***",
"bssid": "***",
"staMac": "***",
"totalPower": 0.7,
"phase_0_c": 1.13,
"phase_0_v": 241.08,
"phase_0_p": 51.83,
"uiActive": 60,
},
"model": "CK-BL602-W102SW18-01(226)",
}

entities = get_entitites(device)

switch: SwitchEntity = next(e for e in entities if isinstance(e, XBoolSwitch))
assert switch.state == "on"
current: XSensor = next(e for e in entities if e.uid == "current")
assert current.state == 1.13
current: XSensor = next(e for e in entities if e.uid == "power")
assert current.state == 51.83
current: XSensor = next(e for e in entities if e.uid == "voltage")
assert current.state == 241.08
energy: XSensor = next(e for e in entities if e.uid == "energy")
assert energy.state == 0.7

0 comments on commit 499fe0b

Please sign in to comment.