Skip to content

Commit

Permalink
Rewrite gateway send logic
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed Mar 31, 2024
1 parent 62c14da commit db96eb1
Showing 1 changed file with 25 additions and 29 deletions.
54 changes: 25 additions & 29 deletions custom_components/xiaomi_gateway3/core/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,42 +127,38 @@ async def prepare_gateway(self) -> bool:
async def send(self, device: XDevice, data: dict):
if device.type == GATEWAY:
# support multispec in lumi and miot formats
if "cmd" in data:
lumi_data = (
{
"cmd": data["cmd"],
"did": "lumi.0",
"params": [i for i in data["params"] if "res_name" in i],
}
if "method" in data
else data
)
if "cmd" in data and "method" in data:
lumi_data = {
"cmd": data["cmd"],
"did": "lumi.0",
"params": [i for i in data["params"] if "res_name" in i],
}
miot_data = {
"method": data["method"],
"params": [i for i in data["params"] if "siid" in i],
}
await self.lumi_send(device, lumi_data)

if "method" in data:
miot_data = (
{
"method": data["method"],
"params": [i for i in data["params"] if "siid" in i],
}
if "cmd" in data
else data
)
await self.miot_send(device, miot_data)
elif "cmd" in data:
await self.lumi_send(device, data)
elif "method" in data:
await self.miot_send(device, data)

elif device.type == ZIGBEE:
# support multispec in lumi and silabs format
if "cmd" in data:
lumi_data = (
{"cmd": data["cmd"], "did": data["did"], "params": data["params"]}
if "commands" in data
else data
)
if "cmd" in data and "commands" in data:
lumi_data = {
"cmd": data["cmd"],
"did": data["did"],
"params": data["params"],
}
silabs_data = {"commands": data["commands"]}
await self.lumi_send(device, lumi_data)

if "commands" in data:
silabs_data = {"commands": data["commands"]} if "cmd" in data else data
await self.silabs_send(device, silabs_data)
elif "cmd" in data:
await self.lumi_send(device, data)
elif "commands" in data:
await self.silabs_send(device, data)

elif device.type in (MESH, GROUP):
await self.miot_send(device, data)
Expand Down

0 comments on commit db96eb1

Please sign in to comment.