core: Dyson Integration unable to log on

The problem

Starting within the last 24 hours the Dyson integration has stopped working when HA is being restarted. It can no longer log on to the Dyson cloud account.

Environment

  • Home Assistant Core release with the issue: 0.113.3
  • Last working Home Assistant Core release (if known): 0.113.3
  • Operating environment (OS/Container/Supervised/Core): OS
  • Integration causing this issue: Dyson
  • Link to integration documentation on our website: https://www.home-assistant.io/integrations/dyson/

Problem-relevant configuration.yaml

dyson:
  username: !secret dyson_user
  password: !secret dyson_password
  language: DE
  devices:
    - device_id: !secret dyson_device_id # eg: Pure Cool Link device
      device_ip: 192.168.0.19

Traceback/Error logs

2020-08-06 17:45:15 INFO (MainThread) [homeassistant.setup] Setting up dyson
2020-08-06 17:45:15 INFO (SyncWorker_5) [homeassistant.components.dyson] Creating new Dyson component
2020-08-06 17:45:15 INFO (SyncWorker_5) [homeassistant.components.dyson] Creating new Dyson component
2020-08-06 17:45:15 ERROR (SyncWorker_5) [homeassistant.components.dyson] Not connected to Dyson account. Unable to add devices
2020-08-06 17:45:15 ERROR (SyncWorker_5) [homeassistant.components.dyson] Not connected to Dyson account. Unable to add devices
2020-08-06 17:45:15 INFO (MainThread) [homeassistant.setup] Setup of domain dyson took 0.7 seconds
2020-08-06 17:45:15 ERROR (MainThread) [homeassistant.setup] Setup failed for dyson: Integration failed to initialize.

Additional information

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 5
  • Comments: 54 (3 by maintainers)

Most upvoted comments

The user-agent appears to be DysonLink/29019 CFNetwork/1188 Darwin/20.0.0

Hey guys, sorry about the delay, I just got back and saw my inbox. Thank you for figuring out what the issue was. I’ll push a an update for libpurecool immediately. I’ll let you know when it’s done.

is there an easier way than via portainer console to replace the whole file? I don’t use docker compose… copy paste in the console in portainer?

In console you could use curl

  1. cd /usr/local/lib/python3.8/site-packages/libpurecool/
  2. mv dyson.py dyson.py.old or rm dyson.py
  3. curl -O https://raw.githubusercontent.com/etheralm/libpurecool/90a17ecc32ff17196044773b55649364444508b9/libpurecool/dyson.py

I think that the problem is caused by a Dyson server. The Dyson server’s filtering and blocking a python request. That’s because I had solved the problem after adding a “User-Agent: curl/7.64.0” to web request as a below.

--- libpurecool/dyson.py.org    2020-08-06 17:21:28.046324038 +0900
+++ libpurecool/dyson.py        2020-08-07 16:57:22.738101057 +0900
@@ -39,6 +39,7 @@
         self._country = country
         self._logged = False
         self._auth = None
+        self._headers = {'User-Agent': 'curl/7.64.0'}
 
     def login(self):
         """Login to dyson web services."""
@@ -52,7 +53,7 @@
         }
         login = requests.post(
             "https://{0}/v1/userregistration/authenticate?country={1}".format(
-                DYSON_API_URL, self._country), request_body, verify=False)
+                DYSON_API_URL, self._country), headers=self._headers, data=request_body, verify=False)
         # pylint: disable=no-member
         if login.status_code == requests.codes.ok:
             json_response = login.json()
@@ -68,10 +69,10 @@
         if self._logged:
             device_response = requests.get(
                 "https://{0}/v1/provisioningservice/manifest".format(
-                    DYSON_API_URL), verify=False, auth=self._auth)
+                    DYSON_API_URL), headers=self._headers, verify=False, auth=self._auth)
             device_v2_response = requests.get(
                 "https://{0}/v2/provisioningservice/manifest".format(
-                    DYSON_API_URL), verify=False, auth=self._auth)
+                    DYSON_API_URL), headers=self._headers, verify=False, auth=self._auth)
             devices = []
             for device in device_response.json():
                 if is_360_eye_device(device):

@Krocko The easiest way to do it is by mounting the new dyson.py file from the PR to the Docker container. In docker-compose it can be done this way:

volumes:
  - /PATH/TO/LOCAL/FILE/dyson.py:/usr/local/lib/python3.8/site-packages/libpurecool/dyson.py

You can also ssh into the container and edit the file at the location in the snippet above.

Running Home Assistant 0.113.1 inside VM on Ubuntu, have ssh into hassio and used

find name dyson.py No such file or directory

Could someone please tell me where this file is likely to be saved?

This is currently what I have in config.yaml

dyson: username: myemail password: mypassword language: AU devices: - device_id: device_SN device_ip: device_IP

When I start HA I get the following…

Setup failed for dyson: Integration failed to initialize. 16:37:55 – setup.py (ERROR) Not connected to Dyson account. Unable to add devices 16:37:55 – dyson (ERROR)

I have replaced the dyson.py and it is working now. I am using HASS OS on raspberry pi4 btw. now, once it is fixed from home assistant, the copied dyson.py will be replaced, right?

Yes. You won’t have to do anything else, it should just work.

More detail: Two files will be replaced behind the scenes by HA. The manifest.json in the HA dyson integration will include a requirements update, which will trigger HA to download the new Libpurecool library replacing dyson.py again. We’re still awaiting @etheralm reviewing the pull request for the Libpurecool library, so this may be a HA version or two away.

Re-checked and problem has resolved itself, assume Dyson doing some things on their end.

I have always found the Dyson integration is prone to random little connection issues here and there. From what I can tell, if one device is temporarily disconnected it can timeout the setup in HA. It usually requires a restart of HA to fix.

It would be smart to get the HA integration to cache the device list and authentication for some period of time, that would solve most problems. It might also reduce the amount of queries we throw at the dyson servers, making it harder for them to shut down the integration.

I image you have ssh’d into the host os.

You’ll need to install the portainer addon in supervisor and use the console for the homeassistant container (As shown in the pic above). Follow the steps, but if you really don’t understand what you’re doing it might be worth waiting until this goes mainline.

Thank you for your answer. I might not understand what iam doing right now 😄 but thats the only way for me to learn how this stuff works. If i mess something up i have no problem with starting from scratch!

Thanks again ill see where your hint will get me 📦 Best Regards

You don’t need a custom component for this fix. Using portainer to replace the dyson.py file should be the only change required. Are you sure you didn’t just rename the file with the first step and not download the file with the curl command? I’d suggest using the portainer console to,

  1. cd /usr/local/lib/python3.8/site-packages/libpurecool/
  2. ls (if no dyson.py is in the list of files, you didn’t download it correctly)
  3. curl -O https://raw.githubusercontent.com/etheralm/libpurecool/90a17ecc32ff17196044773b55649364444508b9/libpurecool/dyson.py (make sure that’s all in one command, not two lines, if it errors out tell us what you get)

If you’re in a venv it should be in your python site packages, so

/srv/homeassistant/lib/python3.7/site-packages/libpurecool/dyson.py

or

/srv/homeassistant/lib/python3.8/site-packages/libpurecool/dyson.py

Worked for me too. Thanks!

@KibosJ it works!!! thnx for you’re help!

is there an easier way than via portainer console to replace the whole file? I don’t use docker compose… copy paste in the console in portainer?

In console you could use curl

  1. cd /usr/local/lib/python3.8/site-packages/libpurecool/
  2. mv dyson.py dyson.py.old or rm dyson.py
  3. curl -O https://raw.githubusercontent.com/etheralm/libpurecool/90a17ecc32ff17196044773b55649364444508b9/libpurecool/dyson.py

I’ve downloaded portainer onto my HA UI. Where’s “Console”?

Screenshot 2020-08-09 at 09 52 16@2x

I think @Phontana is on to something. I also ran down the API doing both the POST and GET commands and receive a 200 response with the proper JSON payload, however it appears the library thinks it is not getting a proper response and sets the login value to FALSE those making the home assistant integration dump out thinking you never logged in.