dswd / OctoPrint-PSUControl-Tapo

Adds TPLink Smart Plug support to OctoPrint-PSUControl as a sub-plugin
GNU Affero General Public License v3.0
7 stars 2 forks source link

After powerloss on TAPO #9

Open kurguplu opened 1 year ago

kurguplu commented 1 year ago

Hi,

When octoprint starts everything is fine. If TAPO shutdowns due to power loss connection cannot be established (expected result) But when TAPO is repowered error 9999.

At that stage if I restart octoprint connection restores so I am thinking it is due to session. I tried to recreate session from tapo.py but i am not that good at coding.

Regards

kurguplu commented 1 year ago

I solved the issue by adding these code to the tapo.py

Here I create reset function to re initialize (Added right after initilize) def reset(self): self.init(self.address,self.username,self.password)

Now on _request_raw funtion before if data["error_code"] != 0: I added if data["error_code"] == 9999: self.reset() If the code is 9999 now the class is reinitialize and session is recreated. I am sure this is not a right solution. Some one better could find the ways to recreate session without reiniting the whole class.

I also find this in the code if not self.key: self._initialize() Probably for same reason but it is not working.