tinkerborg / thinq2-python

Reverse-engineered client for LG ThinQ v2 IoT devices
GNU General Public License v3.0
69 stars 20 forks source link

Issue with washing machine #3

Closed vaxi87 closed 4 years ago

vaxi87 commented 4 years ago

Hi,

First of all, thank you for making this tool!

I tried with one of my AC, and it was working, but only with e-mail/password login, it does not work with e.g. Facebook auth.

When I added my washing machine to my account in LG ThinQ app, I got the following error:

Traceback (most recent call last): File "example.py", line 53, in <module> devices = thinq.mqtt.thinq_client.get_devices() ... marshmallow.exceptions.ValidationError: {'result': {'item': {0: {'countryCode': ['Missing data for required field.'], 'area': ['Missing data for required field.'], 'blackboxYn': ['Missing data for required field.'], 'userNo': ['Missing data for required field.'], 'modelCountryCode': ['Missing data for required field.'], 'snapshot': ['Missing data for required field.'], 'fwVer': ['Not a valid string.']}}}}

tinkerborg commented 4 years ago

Interesting, I haven't tried with Facebook specifically, but Google did work in my testing. What country are you in?

Regarding the above error, can you please try the code in the thinq-log branch? This should log the raw response body from the get_devices() call.

Also I have modified the example.py to write out application state immediately after auth, so after the next run you shouldn't have to keep going through the auth flow to debug this.

vaxi87 commented 4 years ago

I'm running the command with the following: COUNTRY_CODE=HU LANGUAGE_CODE=hu-HU

I've tried the thinq-log branch, so I can see the response JSON now, it contains my 2 ACs, and the washing machine as well, but the error above still exists, and the script is terminated.

Edit: "platformType":"thinq1" for my washing machine. maybe this causes the error.

tinkerborg commented 4 years ago

I don't have any V1 devices to test with, and V1 devices are supported by sampsyo/wideq, so for now I'll have it ignore V1 devices. Will look at this after work tonight.

vaxi87 commented 4 years ago

It would be awesome if the script can ignore v1 devices :) Thanks!

tinkerborg commented 4 years ago

DeviceCollection should now filter out thinq1 devices. Can you please try again (also @stefxx)?

stefxx commented 4 years ago

Thanks! After I see the JSON with my devices, I get this error:

Traceback (most recent call last): File "example.py", line 57, in devices = thinq.mqtt.thinq_client.get_devices() File "Python\Python38\site-packages\uplink\builder.py", line 101, in call return execution.start( File "Python\Python38\site-packages\uplink\clients\io\execution.py", line 97, in start return self._io.execute(self) File "Python\Python38\site-packages\uplink\clients\io\execution.py", line 122, in execute return self._io.execute(executable)

lots and lots more errors removed et me know if you need all that

File "Python\Python38\site-packages\marshmallow\schema.py", line 1220, in _invoke_processors data = processor(data, original_data, many=many, **kwargs) File "thinq2-python-thinq-log\thinq2\schema.py", line 35, in polymorphism field_type = factory(item) File "thinq2-python-thinq-log\thinq2\model\thinq.py", line 71, in polymorph = dict(snapshot=lambda x: device_types.get(x.device_type, Device)) AttributeError: 'dict' object has no attribute 'device_type'

tinkerborg commented 4 years ago

This one makes sense if you have at least one v2 device that isn't a washer or dryer. Will try to get basic support for those added soon. I think I have all the model info needed for that.

On Fri, May 8, 2020, 3:27 PM stefxx notifications@github.com wrote:

Thanks! After I see the JSON with my devices, I get this error:

Traceback (most recent call last): File "example.py", line 57, in devices = thinq.mqtt.thinq_client.get_devices() File "Python\Python38\site-packages\uplink\builder.py", line 101, in call return execution.start( File "Python\Python38\site-packages\uplink\clients\io\execution.py", line 97, in start return self._io.execute(self) File "Python\Python38\site-packages\uplink\clients\io\execution.py", line 122, in execute return self._io.execute(executable)

... lots and lots more errors removed ... let me know if you need all that ...

data = self._invoke_processors(

File "Python\Python38\site-packages\marshmallow\schema.py", line 1220, in _invoke_processors data = processor(data, original_data, many=many, **kwargs) File "thinq2-python-thinq-log\thinq2\schema.py", line 35, in polymorphism field_type = factory(item) File "thinq2-python-thinq-log\thinq2\model\thinq.py", line 71, in polymorph = dict(snapshot=lambda x: device_types.get(x.device_type, Device)) AttributeError: 'dict' object has no attribute 'device_type'

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/tinkerborg/thinq2-python/issues/3#issuecomment-625978710, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADVJF6PCD22DPQROBOI7NN3RQRMJZANCNFSM4M4DX4ZQ .

stefxx commented 4 years ago

No, I do not have a washer. A few v1 devices, and one v2 device (Air Conditioner).

Thanks for your great work so far!

vaxi87 commented 4 years ago

It is working for me, I can see my 2 ACs on the list, and when I turn on/off them via ThinQ app, I can see the events in my terminal!

tinkerborg commented 4 years ago

@vaxi87 Awesome! It's not really exposed yet, but there's already code in here to load the model definition for a device and generate a dataclass/marshmallow schema. Next step will be to use this to create a device class with all status fields populated, then make that observable. After that will come issuing commands, then we should have everything needed to build this into a homeassistant component.

@stefxx Now that I'm back home and looking at the code again, I actually don't expect this to fail with non-laundry devices; they should just lack the status information mentioned above for now. I did simplify the mechanism that handles the polymorphism when loading devices from JSON, though. Can you try latest code in master?

stefxx commented 4 years ago

Sure! It seems we are getting close. I cleanup up my environment and tried again with the latest master code. It shows my username, user number, list my only v2 device, and start to listen but crashes immediately with the following error:

Listening for device events. Use Ctrl-C/SIGINT to quit.

Traceback (most recent call last): File "example.py", line 79, in thinq.mqtt.connect() File "thinq2-python\thinq2\controller\mqtt.py", line 25, in connect self.client.connect(endpoint.hostname, endpoint.port) File "thinq2-python\thinq2\util__init__.py", line 10, in inner memo[key] = func(*args, **kwargs) File "thinq2-python\thinq2\controller\mqtt.py", line 44, in client client.tls_set_context(self.ssl_context) File "thinq2-python\thinq2\controller\mqtt.py", line 67, in ssl_context context.load_cert_chain(certfile=client_cert.name, keyfile=private_key.name) PermissionError: [Errno 13] Permission denied

Permission denied? Is this something local on my machine?

tinkerborg commented 4 years ago

Permission denied? Is this something local on my machine?

This is likely another platform compatibility issue. The new device use MQTT via AWS IoT platform, this is establishing an SSL context to connect to that. This is a new issue, let's follow up in issue #4