sbidy / pywizlight

A python connector for WiZ devices
MIT License
456 stars 77 forks source link

Implement support for Wiz Plug #27

Closed simora closed 2 years ago

simora commented 3 years ago

The following works against a Wiz plug.

# cat test_plug.py
import asyncio
import time
import json

from pywizlight.bulb import wizlight, PilotBuilder

async def main():
    light = wizlight("1.2.3.4")
    print(light.__dict__)
    plug_config = await light.getBulbConfig()
    print(json.dumps(plug_config, indent=2))
    # Turns the plug on
    print("Turning plug on")
    await light.turn_on(PilotBuilder())
    state = await light.updateState()
    print(f"Current plug state is {state.get_state()}")
    time.sleep(2)
    # Turns the plug off
    print("Turning plug off")
    await light.turn_off()
    state = await light.updateState()
    print(f"Current plug state is {state.get_state()}")

loop = asyncio.get_event_loop()
loop.run_until_complete(main())

# python3 test_plug.py
{'ip': '1.2.3.4', 'port': 38899, 'state': None, 'mac': None}
{
  "method": "getSystemConfig",
  "env": "pro",
  "result": {
    "mac": "a mac address",
    "homeId": 1234567,
    "roomId": 1234567,
    "moduleName": "ESP10_SOCKET_06",
    "fwVersion": "1.20.0",
    "groupId": 0,
    "drvConf": [
      20,
      2
    ],
    "ewf": [
      255,
      0,
      255,
      255,
      0,
      0,
      0
    ],
    "ewfHex": "ff00ffff000000"
  }
}
Turning plug on
Current plug state is True
Turning plug off
Current plug state is False
sbidy commented 3 years ago

So in my HA integration the "switch" feature is "implemented". In my opinion the plug is working in the same way as a bulb with only a on/of feature. Maybe I'll overload the bulb to provide a "plug" class. Thank you for the report!

sbidy commented 2 years ago

Done with #102