Skip to content
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

TP-Link switch stopped working after upgrade to 2023.7.0 (fixed in 2023.7.1) #95938

Closed
wzaatar opened this issue Jul 5, 2023 · 37 comments · Fixed by #96191
Closed

TP-Link switch stopped working after upgrade to 2023.7.0 (fixed in 2023.7.1) #95938

wzaatar opened this issue Jul 5, 2023 · 37 comments · Fixed by #96191

Comments

@wzaatar
Copy link

wzaatar commented Jul 5, 2023

Please read before posting

If you are seeing the problem, please capture a wire shark or tcpdump and post it in this issue.

If you have a different model than the ones listed below please post the model

Otherwise give this issue a 👍 instead of posting to let us know you see the issue.

This will keep the issue nice and clean

The problem

After upgrading to 2023.7.0, the following errors started appearing in the log. Below devices are pingable. I also rebooted them, restarted HA. The same error appears again.

What version of Home Assistant Core has the issue?

core-2023.7.0

What was the last working version of Home Assistant Core?

core-2023.6.x

What type of installation are you running?

Home Assistant OS

Integration causing the issue

TP Link Kasa Smart

Link to integration documentation on our website

https://www.home-assistant.io/integrations/tplink/

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

Logger: homeassistant.config_entries
Source: config_entries.py:1257`
First occurred: 5:14:18 PM (18 occurrences) 
Last logged: 5:35:35 PM

Config entry '**MASKED**' for tplink integration not ready yet: Unable to query the device 172.16.13.53: unexpected end of data: line 1 column 434 (char 433); Retrying in background
Config entry '**MASKED**' for tplink integration not ready yet: Unable to query the device 172.16.13.66: unexpected end of data: line 1 column 435 (char 434); Retrying in background
Config entry '**MASKED**' for tplink integration not ready yet: Unable to query the device 172.16.13.67: unexpected end of data: line 1 column 485 (char 484); Retrying in background
Config entry '**MASKED**' for tplink integration not ready yet: Unable to query the device 172.16.13.64: unexpected end of data: line 1 column 552 (char 551); Retrying in background
Config entry ' **MASKED**' for tplink integration not ready yet: Unable to query the device 172.16.13.63: unexpected end of data: line 1 column 325 (char 324); Retrying in background

Additional information

No response

@home-assistant
Copy link

home-assistant bot commented Jul 5, 2023

Hey there @rytilahti, @TheGardenMonkey, mind taking a look at this issue as it has been labeled with an integration (tplink) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of tplink can trigger bot actions by commenting:

  • @home-assistant close Closes the issue.
  • @home-assistant rename Awesome new title Renames the issue.
  • @home-assistant reopen Reopen the issue.
  • @home-assistant unassign tplink Removes the current integration label and assignees on the issue, add the integration domain after the command.

(message by CodeOwnersMention)


tplink documentation
tplink source
(message by IssueLinks)

@geekofweek
Copy link
Contributor

Noticed the same problem, seems to be an issue introduced with python-kasa 0.5.2. Rolling that back to 0.5.1 and the problem went away

@wzaatar
Copy link
Author

wzaatar commented Jul 5, 2023

Noticed the same problem, seems to be an issue introduced with python-kasa 0.5.2. Rolling that back to 0.5.1 and the problem went away

Possible with HA OS?

@bdraco
Copy link
Member

bdraco commented Jul 5, 2023

Which models are the devices that stopped working?

Is it all the same model?

Do some of the same model work and some don't?

@geekofweek
Copy link
Contributor

In my situation it was both KP115 devices. EP40 and HS300 were not impacted and still functioned. using the kasa-python command line I would get the following errors trying to discover devices:

Discovering devices on 255.255.255.255 for 3 seconds
ERROR    Exception in callback _SelectorDatagramTransport._read_ready()                                                                                                                           base_events.py:1771
         handle: <Handle _SelectorDatagramTransport._read_ready()>                                                                                                                                                   
         Traceback (most recent call last):                                                                                                                                                                          
           File "/usr/local/lib/python3.11/asyncio/events.py", line 80, in _run                                                                                                                                      
             self._context.run(self._callback, *self._args)                                                                                                                                                          
           File "/usr/local/lib/python3.11/asyncio/selector_events.py", line 1169, in _read_ready                                                                                                                    
             self._protocol.datagram_received(data, addr)                                                                                                                                                            
           File "/usr/local/lib/python3.11/site-packages/kasa/discover.py", line 79, in datagram_received                                                                                                            
             info = json_loads(TPLinkSmartHomeProtocol.decrypt(data))                                                                                                                                                
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                                                                                
         orjson.JSONDecodeError: unexpected end of data: line 1 column 382 (char 381)                                                                                                                                
ERROR    Exception in callback _SelectorDatagramTransport._read_ready()                                                                                                                           base_events.py:1771
         handle: <Handle _SelectorDatagramTransport._read_ready()>                                                                                                                                                   
         Traceback (most recent call last):                                                                                                                                                                          
           File "/usr/local/lib/python3.11/asyncio/events.py", line 80, in _run                                                                                                                                      
             self._context.run(self._callback, *self._args)                                                                                                                                                          
           File "/usr/local/lib/python3.11/asyncio/selector_events.py", line 1169, in _read_ready                                                                                                                    
             self._protocol.datagram_received(data, addr)                                                                                                                                                            
           File "/usr/local/lib/python3.11/site-packages/kasa/discover.py", line 79, in datagram_received                                                                                                            
             info = json_loads(TPLinkSmartHomeProtocol.decrypt(data))    

@bdraco bdraco self-assigned this Jul 5, 2023
@wzaatar
Copy link
Author

wzaatar commented Jul 5, 2023

Which models are the devices that stopped working?

Is it all the same model?

Do some of the same model work and some don't?

3rd answer in my case. Some devices of a certain model work, others don’t.

@bdraco
Copy link
Member

bdraco commented Jul 5, 2023

Thanks. Ordered a KP115. Should be here early next week. Will see if I can figure out what's going wrong

@bdraco bdraco changed the title A few TP-Link devices stopped working after upgrade to 2023.7.0 A few TP-Link KP115 stopped working after upgrade to 2023.7.0 Jul 5, 2023
@bdraco bdraco changed the title A few TP-Link KP115 stopped working after upgrade to 2023.7.0 TP-Link KP115 stopped working after upgrade to 2023.7.0 Jul 5, 2023
@bdraco
Copy link
Member

bdraco commented Jul 5, 2023

I bet it's a null/0 byte in the encrypted data and it's prematurely truncating the string in the conversion.

If you can get a wire shark dump of it happening I can probably fix it without waiting for the device

@bdraco
Copy link
Member

bdraco commented Jul 5, 2023

Tcpdump or any type of pcap will work as well

@wzaatar wzaatar changed the title TP-Link KP115 stopped working after upgrade to 2023.7.0 TP-Link switch stopped working after upgrade to 2023.7.0 Jul 5, 2023
@wzaatar
Copy link
Author

wzaatar commented Jul 5, 2023

@bdraco This is not only related to KP115. I have other switches that are behaving the same way, specificallyHS100, HS200, HS220.

@bdraco
Copy link
Member

bdraco commented Jul 5, 2023

Just need one to trigger the issue. Any of the ones not working with the same symptom should probably be enough to find the issue

@bdraco
Copy link
Member

bdraco commented Jul 5, 2023

But thanks for answering my original question and providing the model numbers

@redrob49
Copy link

redrob49 commented Jul 5, 2023

I have 6 Kasa KP125 smart plugs. After upgrading to 2023.7 one of the plugs stopped working and gave me a setup error in Home Assistant. Works without issue in 2023.6.3. All KP125 are the same with hardware version 1.0 and firmware version 1.0.10

@bdraco
Copy link
Member

bdraco commented Jul 5, 2023

I have 6 Kasa KP125 smart plugs. After upgrading to 2023.7 one of the plugs stopped working and gave me a setup error in Home Assistant. Works without issue in 2023.6.3. All KP125 are the same with hardware version 1.0 and firmware version 1.0.10

If you rename that device in the tplink app does it fix it?

@wzaatar
Copy link
Author

wzaatar commented Jul 5, 2023

@geekofweek suggested that a rollback to python-kasa 0.5.1 fixed it for him. Maybe a code diff?

@bdraco
Copy link
Member

bdraco commented Jul 6, 2023

It's likely a problem with the encryption library changes. Rolling back should fix it. Ideally we find source the problem instead of reverting it right away because it just means it will come back next time we upgrade the library.

@keith721
Copy link

keith721 commented Jul 6, 2023

Same problem here, with one HS105 outlet and two separate HS200 switches.

@bdraco
Copy link
Member

bdraco commented Jul 6, 2023

Should be fixed in python-kasa/kasa-crypt#3 if someone wants to install that and test

@bdraco
Copy link
Member

bdraco commented Jul 6, 2023

I pushed that change to my production system and all is well. All was well before though.

Can't test it in person since I'm on an airplane still for another few hours

@wzaatar
Copy link
Author

wzaatar commented Jul 6, 2023

I pushed that change to my production system and all is well. All was well before though.

Can't test it in person since I'm on an airplane still for another few hours

Dedication has no limits! Thanks for your prompt response.

@pyrodex
Copy link

pyrodex commented Jul 6, 2023

Should be fixed in bdraco/kasa-crypt#3 if someone wants to install that and test

Is there a quick way to pull this into an existing HA docker setup? I have a few broken devices but it is weird, its not affecting all my Kasa devices just two EP10s and ironically I have others that are fine....

@bdraco
Copy link
Member

bdraco commented Jul 6, 2023

Should be fixed in bdraco/kasa-crypt#3 if someone wants to install that and test

Is there a quick way to pull this into an existing HA docker setup? I have a few broken devices but it is weird, its not affecting all my Kasa devices just two EP10s and ironically I have others that are fine....

Check out the PR in the container, and do a pip install on it. You'll need to remount /tmp to allow it to execute first

@pyrodex
Copy link

pyrodex commented Jul 6, 2023

Should be fixed in bdraco/kasa-crypt#3 if someone wants to install that and test

Is there a quick way to pull this into an existing HA docker setup? I have a few broken devices but it is weird, its not affecting all my Kasa devices just two EP10s and ironically I have others that are fine....

Never mind, I manually brought in the changes and still seeing issues with the SAME two after that. All my other KASA devices are working and reporting. Just not this two...

@bdraco
Copy link
Member

bdraco commented Jul 6, 2023

I'll do a release of the lib after I finish manual testing. Than you can install the wheel in the container. That will be a lot easier

@wzaatar
Copy link
Author

wzaatar commented Jul 6, 2023

Piggybacking on @pyrodex‘s question: Any temporary fix for HA OS installs?

@bdraco
Copy link
Member

bdraco commented Jul 6, 2023

0.2.1 published

You can install it with the advanced ssh addon with protection mode disabled if you are using x86_64

docker exec -it homeassistant /bin/bash
pip3 install --upgrade kasa-crypt==0.2.1

Than restart ha

@bdraco
Copy link
Member

bdraco commented Jul 6, 2023

For other architectures not x86_64

Wait for https://github.com/home-assistant/core/actions/runs/5470867696 to finish and run the below:

docker exec -it homeassistant /bin/bash
pip3 install --find-links=$WHEELS_LINKS --upgrade kasa-crypt==0.2.1

@keith721
Copy link

keith721 commented Jul 6, 2023

0.2.1 published

You can install it with the advanced ssh addon with protection mode disabled if you are using x86_64

docker exec -it homeassistant /bin/bash
pip3 install --upgrade kasa-crypt==0.2.1

Than restart ha

HAOS 10.2 here on Intel Nuc i3
Applied kasa-crypt==0.2.1 and restarted Home Assistant.
My three devices are not initializing (still). Log content below

2023-07-05 22:32:11.845 WARNING (MainThread) [homeassistant.config_entries] Config entry 'Cable Modem HS105(US)' for tplink integration not ready yet: Unable to connect to the device: 192.168.1.112: ; Retrying in background
2023-07-05 22:32:11.875 WARNING (MainThread) [homeassistant.config_entries] Config entry 'Front Porch' for tplink integration not ready yet: Unable to connect to the device: 192.168.1.119: ; Retrying in background
2023-07-05 22:32:11.883 WARNING (MainThread) [homeassistant.config_entries] Config entry 'Garage Lights' for tplink integration not ready yet: Unable to connect to the device: 192.168.1.245: ; Retrying in background

@bdraco
Copy link
Member

bdraco commented Jul 6, 2023

Unable to connect to the device: 192.168.1.119

@keith721 That is not the same issue as the OP posted so I wouldn't expect the new library to resolve the problem.

Please start a new issue. It might be the same as #95028 though

@redrob49
Copy link

redrob49 commented Jul 6, 2023 via email

@keith721
Copy link

keith721 commented Jul 6, 2023

Understood, but doesn't the encryption/decryption play a role in successfully connecting to these TP-Link devices? They are all on-line, and I can ping them. If my post isn't relevant, please feel free to remove or strike-through it.

Thanks for your speedy efforts!! I'm rolling back to 2023.6.3...

@bdraco
Copy link
Member

bdraco commented Jul 6, 2023

Understood, but doesn't the encryption/decryption play a role in successfully connecting to these TP-Link devices? They are all on-line, and I can ping them. If my post isn't relevant, please feel free to remove or strike-through it.

Thanks for your speedy efforts!! I'm rolling back to 2023.6.3...

The encryption only happens after the connection is established. If the connection cannot be made the encryption can't be the problem

@wzaatar
Copy link
Author

wzaatar commented Jul 6, 2023

I can confirm that kasa-crypt 0.2.1 works perfectly on HA OS / HA Blue ODROID. All switches are now responding. Kudos @bdraco!

@pyrodex
Copy link

pyrodex commented Jul 6, 2023

Yea, the pip worked without issues now.

@bdraco
Copy link
Member

bdraco commented Jul 6, 2023

The dep isn't pinned in HA so the next HA release will automatically build with the new version

@dev-tty
Copy link

dev-tty commented Jul 6, 2023

Thank you for the fix.

Had the same problem on a mix of 15 devices:

HS103(US)
Firmware: 1.1.4 Build 210409 Rel.113427
Hardware: 2.1

HS100(US)
Firmware: 1.2.6 Build 200727 Rel.120528
Hardware: 1.0

HS200(US)
Firmware: 1.1.3 Build 191205 Rel.103557

No problems with the:

KP400(US)
Firmware: 1.0.7 Build 210428 Rel.080330
Hardware: 2.0


HS220(US)
Firmware: 1.0.8 Build 210423 Rel.075507
Hardware: 2.0

@bdraco bdraco added this to the 2023.7.1 milestone Jul 6, 2023
@bdraco bdraco changed the title TP-Link switch stopped working after upgrade to 2023.7.0 TP-Link switch stopped working after upgrade to 2023.7.0 (fixed in 2023.7.1) Jul 6, 2023
@bdraco
Copy link
Member

bdraco commented Jul 6, 2023

Closing this issue as a solution is available and 2023.7.1 is shipping in a few hours via #96006

@bdraco bdraco closed this as completed Jul 6, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Aug 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants