jasonacox / tinytuya

Python API for Tuya WiFi smart devices using a direct local area network (LAN) connection or the cloud (TuyaCloud API).
MIT License
879 stars 159 forks source link

fix: call status() reset device #345

Closed xgustavoh closed 1 year ago

xgustavoh commented 1 year ago

Hello, first I would like to apologize for my English!

Recently I had a problem using a Smart Bulb RGBCW7 in version = 3.2, that it was turning off or changing its status "randomly".

I noticed that whenever the status() function was executed, the bulb suffered a "reset" or "turning off".

After seeing the code, I noticed that the dps_cache was exactly to the value that the bulb was getting after the "reset".

When I set the dps_to_request values to `None, the problem didn't happen.


Adding this code in def detect_available_dps(self): solved my problem.

data["dps"] = {k: None for k in data["dps"]}
jasonacox commented 1 year ago

Thanks @xgustavoh ! I'll run some tests to verify

@uzlonewolf can you take a look as well?

uzlonewolf commented 1 year ago

I like the idea, though I think creating a new dict just to update another is kinda convoluted. How about replacing

            if data is not None and "dps" in data:
                data["dps"] = {k: None for k in data["dps"]}
                self.dps_cache.update(data["dps"])

with:

            if data is not None and "dps" in data:
                # save the keys but not the returned values
                for k in data["dps"]:
                    self.dps_cache[k] = None
xgustavoh commented 1 year ago

I like your way too, it even had implementation that way... But, I'm not a python programmer, so I don't know the best practices, I'm going to change right now!

jasonacox commented 1 year ago

Thank you @xgustavoh !! My tests are passing. I'll release it as v1.12.7.