Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mini R3 DIY Status #1158

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion custom_components/sonoff/core/ewelink/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ async def check_offline(self, device: XDevice):
if i > 0:
await asyncio.sleep(5)

ok = await self.local.send(device, command="getState")
ok = await self.local.send(device, command="info")
if ok in ("online", "error"):
device["local_ts"] = time.time() + LOCAL_TTL
device["local"] = True
Expand Down Expand Up @@ -231,7 +231,11 @@ def cloud_update(self, msg: dict):
def local_update(self, msg: dict):
mainid: str = msg["deviceid"]
device: XDevice = self.devices.get(mainid)

params: dict = msg.get("params")
if not params:
params = msg.get("data")

# check device in known devices list
if not device:
# check payload already decrypted (DIY devices)
Expand Down
3 changes: 1 addition & 2 deletions custom_components/sonoff/core/ewelink/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,12 @@ async def send(
if resp["error"] == 0:
_LOGGER.debug(f"{log} <= {resp}")

if "iv" in resp:
if "data" in resp:
msg = {
"deviceid": device["deviceid"],
"localtype": device["localtype"],
"seq": resp["seq"],
"data": resp["data"],
"iv": resp["iv"],
}
if params and params.get("subDevId"):
msg["subdevid"] = params["subDevId"]
Expand Down
7 changes: 7 additions & 0 deletions custom_components/sonoff/switch.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from datetime import timedelta
from homeassistant.components.switch import SwitchEntity

from .core.const import DOMAIN
from .core.entity import XEntity
from .core.ewelink import SIGNAL_ADD_ENTITIES, XRegistry

PARALLEL_UPDATES = 0 # fix entity_platform parallel_updates Semaphore
SCAN_INTERVAL = timedelta(seconds=3) # TODO move to configuration


async def async_setup_entry(hass, config_entry, add_entities):
Expand Down Expand Up @@ -33,6 +35,7 @@ async def async_turn_off(self):
class XSwitches(XEntity, SwitchEntity):
params = {"switches"}
channel: int = 0
_attr_should_poll = True

def __init__(self, ewelink: XRegistry, device: dict):
XEntity.__init__(self, ewelink, device)
Expand All @@ -51,6 +54,10 @@ def set_state(self, params: dict):
except StopIteration:
pass

@property
def is_on(self) -> bool | None:
return self._attr_is_on

async def async_turn_on(self, **kwargs):
params = {"switches": [{"outlet": self.channel, "switch": "on"}]}
await self.ewelink.send_bulk(self.device, params)
Expand Down