SecKatie / wyzeapy

35 stars 26 forks source link

Support for Floodlight #45

Closed jdeath closed 2 years ago

jdeath commented 2 years ago

On/Off tested and worked. Property not tested, but should work. I was wrong 1 is on, 2 is off for P1056

CLAassistant commented 2 years ago

CLA assistant check
All committers have signed the CLA.

JoeSchubert commented 2 years ago

@jdeath

I'm not 100% sure that this is going to work as you intend. When you tested it, it actually toggled the light on and off (not just indicating to Home Assistant that it toggled)?

The reason that I ask is that it looks like you may be mixing up what the PropertyIDs enum is doing vice what the object properties are doing. The PropertyIDs enum is just to get the ID code for the JSON field in Wyze's API response for things like on/off. Which looks like you're using correctly in lines 61-63. However, in the two functions lines 112-116... you're just toggling the object's property. This shouldn't cause anything to be transmitted back to Wyze to actually toggle the light. This occurs in the _run_action function of the base service.

Given the commits attached here... it looks like these should be more like:

    async def floodlight_on(self, camera: Camera):
        await self._run_action(camera, "flood_light", "1")

    async def floodlight_off(self, camera: Camera):
        await self._run_action(camera, "flood_light", "2")

admittedly, the way you're getting the value from the propertyID may work as well and be cleaner than hardcoding the string. But, I'm pretty sure that you'll need to call "_run_action" vice "_set_property" regardless of how you obtain the propertyID code.

JoeSchubert commented 2 years ago

Sorry for the close... touchpad craziness.

jdeath commented 2 years ago

Sorry for the close... touchpad craziness.

I 100% confirm this actually works. The app is making the call this way when I toggle the light, as per the mitm I posted in the homeassistant app. I am controlling the light via homeassistant as we speak. I can try the other method if you think it is cleaner, but I thought best to do it like the app. I couldn't tell where you got the strings in the _run_action commands, as the app was not using that api call.

JoeSchubert commented 2 years ago

@jdeath no worries. If it works, it works. The string is just the enum item's name. Basically, it's just for the run action function to grab the property id from the enum.

I'm not entirely sure where the hook that would cause the base service to call anything when the properties change off the top of my head. But, if it's working it must somewhere.

I just wanted to verify the device followed and not just the HA entity. Glad to hear it is :)