Skip to content

error on second handshake #58

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dvelayos
Copy link

@dvelayos dvelayos commented May 7, 2022

recently,, i've updated HA to 2022.4 version; with the upgrade, the HomeAssistant-Tapo-P100-Control integration stopped working, so i updated everything (the integration, the PyP100 library) in order to get it working again

i've managed to get the plugs recognized at start (the setup_platform method goes ok with my 4 switches), but, when HA invokes the update method of each one, on the P100Plug class instances, it raises an exception on the handshake; i confirmed this error with this simple test code:

# Setup connection with devices/cloud
p100 = PyP100.P100(ipAddress, email, password)

try:
    p100.handshake()
    p100.login()
    data = p100.getDeviceInfo()

    encodedName = data["result"]["nickname"]
    name = b64decode(encodedName)
    print(name)
    p100.handshake()  """this line throws an exception"""
    p100.login()
except Exception as e:
    print("Could not connect to plug. Possibly invalid credentials::{}".format(str(e)))

the error is raised on the second handshake; the PyP100, on the handshake method, tries to recover the result;

encryptedKey = r.json()["result"]["key"]

but the result subindex does not exists; the response is

{'error_code': 9999}

i've managed to get it working modifying the update method, adding a try-catch on both methods (handshake and login). It seems that the second handshake-login invocation raises an error for some reason (i don't know if its a problem of timing, or something related with a new firmware)

anyway, it seems that those invocations are not needed for the tapo p100 in order to work (i've tested it and the switches works like a charm, even throwing both exceptions)

def update(self):
     try:
         self._p100.handshake()
     except Exception as e:
         _LOGGER.error("handshake error:{}".format(str(e)))

     try:
         self._p100.login()
     except Exception as e:
         _LOGGER.error("login error:{}".format(str(e)))

     data = self._p100.getDeviceInfo()

     encoded_name = data["result"]["nickname"]
     name = b64decode(encoded_name)
     self._name = name.decode("utf-8")

     self._is_on = data["result"]["device_on"]
     self._unique_id = data["result"]["device_id"]

…omeAssistant-Tapo-P100-Control integration stopped working, so i updated everything (the integration, the PyP100 library) in order to get it working again

i've managed to get the plugs recognized at start (the setup_platform method goes ok with my 4 switches), but, when HA invokes the update method of each one, on the P100Plug class instances, it raises an exception on the handshake; i confirmed this error with this simple test code:

```
# Setup connection with devices/cloud
p100 = PyP100.P100(ipAddress, email, password)

try:
    p100.handshake()
    p100.login()
    data = p100.getDeviceInfo()

    encodedName = data["result"]["nickname"]
    name = b64decode(encodedName)
    print(name)
    p100.handshake()  """this line throws an exception"""
    p100.login()
except Exception as e:
    print("Could not connect to plug. Possibly invalid credentials::{}".format(str(e)))
```

the error is raised on the second handshake; the PyP100, on the handshake method, tries to recover the result;

`encryptedKey = r.json()["result"]["key"]`

but the result subindex does not exists; the response is

`{'error_code': 9999}`

i've managed to get it working modifying the update method, adding a try-catch on both methods (handshake and login). It seems that the second handshake-login invocation raises an error for some reason (i don't know if its a problem of timing, or something related with a new firmware)

anyway, it seems that those invocations are not needed for the tapo p100 in order to work (i've tested it and the switches works like a charm, even throwing both exceptions)

   ```
 def update(self):
        try:
            self._p100.handshake()
        except Exception as e:
            _LOGGER.error("handshake error:{}".format(str(e)))

        try:
            self._p100.login()
        except Exception as e:
            _LOGGER.error("login error:{}".format(str(e)))

        data = self._p100.getDeviceInfo()

        encoded_name = data["result"]["nickname"]
        name = b64decode(encoded_name)
        self._name = name.decode("utf-8")

        self._is_on = data["result"]["device_on"]
        self._unique_id = data["result"]["device_id"]
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants