shenxn / libdyson Goto Github PK
View Code? Open in Web Editor NEWPython library for dyson devices
License: Apache License 2.0
Python library for dyson devices
License: Apache License 2.0
python3 get_devices.py
Traceback (most recent call last):
File "get_devices.py", line 3, in
from libdyson.cloud import DysonAccount
File "/home/warneke/projects/home/libdyson/libdyson/cloud/init.py", line 3, in
from .account import DysonAccount, DysonAccountCN # noqa: F401
File "/home/warneke/projects/home/libdyson/libdyson/cloud/account.py", line 6, in
import requests
File "/usr/lib/python3/dist-packages/requests/init.py", line 95, in
from urllib3.contrib import pyopenssl
File "/usr/lib/python3/dist-packages/urllib3/contrib/pyopenssl.py", line 46, in
import OpenSSL.SSL
File "/usr/lib/python3/dist-packages/OpenSSL/init.py", line 8, in
from OpenSSL import crypto, SSL
File "/usr/lib/python3/dist-packages/OpenSSL/crypto.py", line 1553, in
class X509StoreFlags(object):
File "/usr/lib/python3/dist-packages/OpenSSL/crypto.py", line 1573, in X509StoreFlags
CB_ISSUER_CHECK = _lib.X509_V_FLAG_CB_ISSUER_CHECK
AttributeError: module 'lib' has no attribute 'X509_V_FLAG_CB_ISSUER_CHECK'
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 72, in apport_excepthook
from apport.fileutils import likely_packaged, get_recent_crashes
File "/usr/lib/python3/dist-packages/apport/init.py", line 5, in
from apport.report import Report
File "/usr/lib/python3/dist-packages/apport/report.py", line 32, in
import apport.fileutils
File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 12, in
import os, glob, subprocess, os.path, time, pwd, sys, requests_unixsocket
File "/usr/lib/python3/dist-packages/requests_unixsocket/init.py", line 1, in
import requests
File "/usr/lib/python3/dist-packages/requests/init.py", line 95, in
from urllib3.contrib import pyopenssl
File "/usr/lib/python3/dist-packages/urllib3/contrib/pyopenssl.py", line 46, in
import OpenSSL.SSL
File "/usr/lib/python3/dist-packages/OpenSSL/init.py", line 8, in
from OpenSSL import crypto, SSL
File "/usr/lib/python3/dist-packages/OpenSSL/crypto.py", line 1553, in
class X509StoreFlags(object):
File "/usr/lib/python3/dist-packages/OpenSSL/crypto.py", line 1573, in X509StoreFlags
CB_ISSUER_CHECK = _lib.X509_V_FLAG_CB_ISSUER_CHECK
AttributeError: module 'lib' has no attribute 'X509_V_FLAG_CB_ISSUER_CHECK'
Original exception was:
Traceback (most recent call last):
File "get_devices.py", line 3, in
from libdyson.cloud import DysonAccount
File "/home/warneke/projects/home/libdyson/libdyson/cloud/init.py", line 3, in
from .account import DysonAccount, DysonAccountCN # noqa: F401
File "/home/warneke/projects/home/libdyson/libdyson/cloud/account.py", line 6, in
import requests
File "/usr/lib/python3/dist-packages/requests/init.py", line 95, in
from urllib3.contrib import pyopenssl
File "/usr/lib/python3/dist-packages/urllib3/contrib/pyopenssl.py", line 46, in
import OpenSSL.SSL
File "/usr/lib/python3/dist-packages/OpenSSL/init.py", line 8, in
from OpenSSL import crypto, SSL
File "/usr/lib/python3/dist-packages/OpenSSL/crypto.py", line 1553, in
class X509StoreFlags(object):
File "/usr/lib/python3/dist-packages/OpenSSL/crypto.py", line 1573, in X509StoreFlags
CB_ISSUER_CHECK = _lib.X509_V_FLAG_CB_ISSUER_CHECK
AttributeError: module 'lib' has no attribute 'X509_V_FLAG_CB_ISSUER_CHECK'
Trying to get the credentials and getting this exception.
After installing all the requirements, consistently running into the following error.
Please choose your account region
1: Mainland China
2: Rest of the World
Region [1/2]: 2
Region code: US
Email: [email protected]
Traceback (most recent call last):
File "get_devices.py", line 22, in
verify = account.login_email_otp(email, region)
File "/Users/gmathur/Downloads/libdyson/libdyson/cloud/account.py", line 127, in login_email_otp
auth=False,
File "/Users/gmathur/Downloads/libdyson/libdyson/cloud/account.py", line 114, in request
raise DysonInvalidAuth
libdyson.exceptions.DysonInvalidAuth
Hello,
First of all, thank you for the working local integration. My TP09 is now FINALLY in HA. Would it be possible to update the database for the newer models too please? The one missing for me is Purifier Hot+Cool Formaldehyde™ (HP09, Device Type is 527K).
Thank you!
❯ python get_devices.py
Please choose your account region
1: Mainland China
2: Rest of the World
Region [1/2]: 1
Phone number: 188XXXXXXXX
Verification code:
After this, there is no verification code on my phone sms message.
Hi Guys,
sorry for beeing a total Noob. But i have just started playing around with my RaspPi and Home Assistant a while ago. And i am not familiar with all the stuff here and iam not sure where to start tbh. I used to have the dyson fan integration but as you know this stopped working. I would like to integrate them again but i dont have the stickers that were provided by dyson.
I have no clue what to do with this libdyson and where to clone/download it or where to run it. On HA or run it on a virtual environement on my pc? Sorry. If you could just point me in the right direction i would take the time and learn all the needed stuff but right now iam pretty lost :D
thanks and regards
Hi.
First of all, thank you for the great library.
I have tried to use this library with PURE_HOT_COOL_LINK(455), but all the commands about changing the state do not work. (I can get the state without any problem).
from libdyson import DEVICE_TYPE_PURE_HOT_COOL_LINK, DysonPureHotCoolLink
import logging
import sys
root = logging.getLogger()
root.setLevel(logging.DEBUG)
handler = logging.StreamHandler(sys.stdout)
handler.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
handler.setFormatter(formatter)
root.addHandler(handler)
DEVICE_TYPE = DEVICE_TYPE_PURE_HOT_COOL_LINK
HOST = '192.168.1.83'
DEVICE_SERIAL = 'G5V-JP-<redacted>'
DEVICE_PASSWORD = '<redacted>'
device = DysonPureHotCoolLink(DEVICE_SERIAL, DEVICE_PASSWORD, DEVICE_TYPE)
device.connect(HOST)
print('Before: ', device._status)
device.disable_auto_mode()
device.turn_off()
print('After: ', device._status)
2021-07-05 22:36:53,802 - libdyson.dyson_device - DEBUG - Connected with result code 0
2021-07-05 22:36:53,802 - libdyson.dyson_device - INFO - Connected to device G5V-JP-<redacted>
2021-07-05 22:36:54,045 - libdyson.dyson_device - DEBUG - New state: {'msg': 'CURRENT-STATE', 'time': '2021-07-05T13:36:53.000Z', 'mode-reason': '', 'state-reason': 'MODE', 'dial': 'OFF', 'rssi': '-42', 'product-state': {'fmod': 'AUTO', 'fnst': 'FAN', 'fnsp': 'AUTO', 'qtar': '0003', 'oson': 'ON', 'rhtm': 'ON', 'filf': '3869', 'ercd': 'NONE', 'nmod': 'OFF', 'wacd': 'NONE', 'hmod': 'OFF', 'hmax': '2970', 'hsta': 'OFF', 'ffoc': 'OFF', 'tilt': 'OK'}, 'scheduler': {'srsc': '65dd', 'dstv': '0000', 'tzid': '0001'}}
2021-07-05 22:36:54,142 - libdyson.dyson_device - DEBUG - New environmental state: {'msg': 'ENVIRONMENTAL-CURRENT-SENSOR-DATA', 'time': '2021-07-05T13:36:53.001Z', 'data': {'tact': '2975', 'hact': '0066', 'pact': '0009', 'vact': '0000', 'sltm': 'OFF'}}
Before: {'fmod': 'AUTO', 'fnst': 'FAN', 'fnsp': 'AUTO', 'qtar': '0003', 'oson': 'ON', 'rhtm': 'ON', 'filf': '3869', 'ercd': 'NONE', 'nmod': 'OFF', 'wacd': 'NONE', 'hmod': 'OFF', 'hmax': '2970', 'hsta': 'OFF', 'ffoc': 'OFF', 'tilt': 'OK'}
After: {'fmod': 'AUTO', 'fnst': 'FAN', 'fnsp': 'AUTO', 'qtar': '0003', 'oson': 'ON', 'rhtm': 'ON', 'filf': '3869', 'ercd': 'NONE', 'nmod': 'OFF', 'wacd': 'NONE', 'hmod': 'OFF', 'hmax': '2970', 'hsta': 'OFF', 'ffoc': 'OFF', 'tilt': 'OK'}
For some reason, the endpoint doesn't seem to be available right now and Dyson for some reason decided to return malformed JSON {error: "Endpoint is not available currently"}
Which then causes this error at libdyson/cloud/account.py:162
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)
It seems to throw a 429 error when this is the case so that can probably be used to help prevent this issue.
In home assistant this manifests as a Unknown Error
Lib was working great until the other day when it just stopped connecting. I'm using this as apart of the Home Assistant integration but I get the error Failed to connect. I tried the CLI tool and get this error:
python3 get_devices.py
Please choose your account region
1: Mainland China
2: Rest of the World
Region [1/2]: 2
Region code: US
Email: XXX
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/urllib3/contrib/pyopenssl.py", line 485, in wrap_socket
cnx.do_handshake()
File "/usr/lib/python3/dist-packages/OpenSSL/SSL.py", line 1915, in do_handshake
self._raise_ssl_error(self._ssl, result)
File "/usr/lib/python3/dist-packages/OpenSSL/SSL.py", line 1647, in _raise_ssl_error
_raise_current_error()
File "/usr/lib/python3/dist-packages/OpenSSL/_util.py", line 54, in exception_from_error_queue
raise exception_type(errors)
OpenSSL.SSL.Error: [('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')]
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 665, in urlopen
httplib_response = self._make_request(
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 376, in _make_request
self._validate_conn(conn)
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 996, in validate_conn
conn.connect()
File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 366, in connect
self.sock = ssl_wrap_socket(
File "/usr/lib/python3/dist-packages/urllib3/util/ssl.py", line 370, in ssl_wrap_socket
return context.wrap_socket(sock, server_hostname=server_hostname)
File "/usr/lib/python3/dist-packages/urllib3/contrib/pyopenssl.py", line 491, in wrap_socket
raise ssl.SSLError("bad handshake: %r" % e)
ssl.SSLError: ("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')])",)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/requests/adapters.py", line 439, in send
resp = conn.urlopen(
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 719, in urlopen
retries = retries.increment(
File "/usr/lib/python3/dist-packages/urllib3/util/retry.py", line 436, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='appapi.cp.dyson.com', port=443): Max retries exceeded with url: /v3/userregistration/email/userstatus?country=US (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')])")))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/rmcnutt/libdyson/libdyson/cloud/account.py", line 107, in request
response = requests.request(
File "/usr/lib/python3/dist-packages/requests/api.py", line 60, in request
return session.request(method=method, url=url, **kwargs)
File "/usr/lib/python3/dist-packages/requests/sessions.py", line 533, in request
resp = self.send(prep, **send_kwargs)
File "/usr/lib/python3/dist-packages/requests/sessions.py", line 646, in send
r = adapter.send(request, **kwargs)
File "/usr/lib/python3/dist-packages/requests/adapters.py", line 514, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='appapi.cp.dyson.com', port=443): Max retries exceeded with url: /v3/userregistration/email/userstatus?country=US (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')])")))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "get_devices.py", line 22, in
verify = account.login_email_otp(email, region)
File "/home/rmcnutt/libdyson/libdyson/cloud/account.py", line 127, in login_email_otp
response = self.request(
File "/home/rmcnutt/libdyson/libdyson/cloud/account.py", line 117, in request
raise DysonNetworkError
libdyson.exceptions.DysonNetworkError
HI!
I can connect to the Dyson via home bridge... but not via HA...
So the serial and credentials are good, but I tried several version in the drop down menu (purifier cool, pure cool formaldehyde) and the result is always failed to connect...
Any idea?
Thanks a lot!
get_devices.py
consistently returns an error for me. Initially it was returning libdyson.exceptions.DysonInvalidAuth
, then I logged out of the app, and now it returns libdyson.exceptions.DysonServerError
all the time.
Please choose your account region
1: Mainland China
2: Rest of the World
Region [1/2]: 2
Region code: US
Email: ...
Traceback (most recent call last):
File "/Users/virusman/Private/code/python/libdyson/get_devices.py", line 22, in <module>
verify = account.login_email_otp(email, region)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/virusman/Private/code/python/libdyson/libdyson/cloud/account.py", line 122, in login_email_otp
response = self.request(
^^^^^^^^^^^^^
File "/Users/virusman/Private/code/python/libdyson/libdyson/cloud/account.py", line 116, in request
raise DysonServerError
libdyson.exceptions.DysonServerError
This is originally reported in shenxn/ha-dyson#1 (comment) by @lolongan.
Here is the log
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/config_entries.py", line 248, in async_setup
result = await component.async_setup_entry(hass, self) # type: ignore
File "/config/custom_components/dyson_cloud/__init__.py", line 43, in async_setup_entry
devices = await hass.async_add_executor_job(account.devices)
File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/usr/local/lib/python3.8/site-packages/libdyson/cloud/account.py", line 173, in devices
devices.append(DysonDeviceInfo.from_raw(raw))
File "/usr/local/lib/python3.8/site-packages/libdyson/cloud/device_info.py", line 31, in from_raw
decrypt_password(raw["LocalCredentials"]),
File "/usr/local/lib/python3.8/site-packages/libdyson/cloud/utils.py", line 29, in decrypt_password
encrypted = base64.b64decode(encrypted_password)
File "/usr/local/lib/python3.8/base64.py", line 80, in b64decode
s = _bytes_from_decode_data(s)
File "/usr/local/lib/python3.8/base64.py", line 45, in _bytes_from_decode_data
raise TypeError("argument should be a bytes-like object or ASCII "
TypeError: argument should be a bytes-like object or ASCII string, not 'NoneType'
ERROR (MainThread) [homeassistant.config_entries] Error occurred loading configuration flow for integration dyson_cloud: cannot impor
t name 'DysonPurifierHumidifyCoolFormaldehyde' from 'libdyson' (/usr/local/lib/python3.10/site-packages/libdyson/__init__.py)
Hello,
is it possible that someone can add the 'DysonPurifierHumidifyCoolFormaldehyde' version of the Dyson pure cool tower (TP04)
to the code?
Thanks.
I have two Dyson Purifier+Cool Formaldehyde. One with device type 358E and one with device type 358K.
I could connect the device type 358E in Home Assistant, but for the device type 358K I'm getting the error "Failed to connect".
Since we're getting issues like shenxn/ha-dyson#116 and shenxn/ha-dyson#115 we should get a new release instead of relying on git pulls of the dependency.
@Kakise can you actually do that
Would it be possible to add support for cleaning specific zones?
I know this isn’t supported (yet) by HA but maybe it could be used by send_command
- https://www.home-assistant.io/integrations/vacuum/#service-vacuumsend_command
Error when running get_devices.py
What should I do?
$ python3 get_devices.py
Please choose your account region
1: Mainland China
2: Rest of the World
Region [1/2]: 2
Region code: JP
Email: [email protected]
Traceback (most recent call last):
File "/home/takumig/libdyson/get_devices.py", line 22, in
verify = account.login_email_otp(email, region)
File "/home/takumig/libdyson/libdyson/cloud/account.py", line 122, in login_email_otp
response = self.request(
File "/home/takumig/libdyson/libdyson/cloud/account.py", line 114, in request
raise DysonInvalidAuth
libdyson.exceptions.DysonInvalidAuth
Hello,
Would it be possible to implement the empty water tank status for humidifiers? This notifies the app, so I know it's there somewhere, but not sure how to figure out what is needed to pull in the status via libdyson.
Thanks!
This happens every once in a while for me, recently. I run prometheus-dyson (https://github.com/seanrees/prometheus-dyson)
but it doesn't seem like that's very involved here (eg the code doesn't make it to calling the callback).
Adding a None check seems simple but might just paper it over, I don't know why info
would be None there.
This is after several days of runtime:
Traceback (most recent call last):
File "/usr/lib64/python3.10/threading.py", line 1009, in _bootstrap_inner
self.run()
File "/home/aug/.local/lib/python3.10/site-packages/zeroconf/_services/browser.py", line 532, in run
self._fire_service_state_changed_event(event)
File "/home/aug/.local/lib/python3.10/site-packages/zeroconf/_services/browser.py", line 416, in _fire_service_state_changed_event
self._service_state_changed.fire(
File "/home/aug/.local/lib/python3.10/site-packages/zeroconf/_services/__init__.py", line 55, in fire
h(**kwargs)
File "/home/aug/.local/lib/python3.10/site-packages/zeroconf/_services/browser.py", line 177, in on_change
getattr(listener, _ON_CHANGE_DISPATCH[state_change])(zeroconf, service_type, name)
File "/home/aug/.local/lib/python3.10/site-packages/libdyson/discovery.py", line 81, in add_service
self._dyson_discovery.device_discovered(info)
File "/home/aug/.local/lib/python3.10/site-packages/libdyson/discovery.py", line 37, in device_discovered
if info.type == TYPE_DYSON_360_EYE:
AttributeError: 'NoneType' object has no attribute 'type'
Hey there,
Whenever I try using get_devices.py
, it fails to log me in and says I am UNREGISTERED
, even though I can confirm that I can login with the same email on the web and I am currently also logged in with the same account on my iPhone.
Do you know why this might be happening?
Thanks
After installing the requirements and following this tutorial I cannot connect to my Dyson Pure Humidify+Cool since I keep getting libdyson.exceptions.DysonConnectTimeout
after calling getDevice()
. I've ensured that the credentials and IP address are correct, I've also deleted the mobile apps, with no luck. Does anyone have tips on how to fix it?
Hi,
My dyson local integration started reporting everything as unavailable, so I figured I'd delete then re-add it.
Unfortunately I can't get get_devices.py to work anymore, after entering my verification code I always get :
Traceback (most recent call last):
File "get_devices.py", line 30, in <module>
devices = account.devices()
File "/dev/libdyson/libdyson/cloud/account.py", line 178, in devices
devices.append(DysonDeviceInfo.from_raw(raw))
File "/dev/libdyson/libdyson/cloud/device_info.py", line 31, in from_raw
decrypt_password(raw["LocalCredentials"]),
File "/dev/libdyson/libdyson/cloud/utils.py", line 24, in decrypt_password
cipher = Cipher(
TypeError: __init__() missing 1 required positional argument: 'backend'
$ python3 --version
Python 3.8.6
Thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.