albertogeniola / MerossIot

Async Python library for controlling Meross devices
https://albertogeniola.github.io/MerossIot/
MIT License
484 stars 88 forks source link

MSS310H is not supported? #31

Closed virtualdj closed 5 years ago

virtualdj commented 5 years ago

Hi, I own a Meross MSS310H (hardware version 2) and was trying your library to get consumption data and switch on and off the plug from my Linux NAS.

I've tried on a Ubuntu VM to install Python 3 and your library but when I run the script on the README file I do not get any device:

user@ubuntu:~/meross$ python3 meross.py
Listing Devices...

So I tried to edit the /usr/local/lib/python3.4/dist-packages/meross_iot/api.py file to uncomment line 73 (instruction print(jsondata)) and this is the output I get:

user@ubuntu:~/meross$ python3 meross.py
Listing Devices...
{'info': 'Success', 'apiStatus': 0, 'data': {'userid': '170119', 'token': '**cut**', 'key': '**cut**', 'email': '**cut**'}, 'timeStamp': 1550308953, 'sysStatus': 0}
{'info': 'Success', 'apiStatus': 0, 'data': None, 'timeStamp': '2019-02-16 17:22:34', 'sysStatus': 0}
{'info': 'Success', 'apiStatus': 0, 'data': [{'channels': [{}], 'userDevIcon': '', 'devIconId': 'device031_it', 'deviceType': 'mss310h', 'hdwareVersion': '2.0.0', 'bindTime': 1549389138, 'region': 'eu', 'uuid': '2912265024316329086934298f186e3d', 'iconType': 1, 'domain': 'eu-iot.meross.com', 'subType': 'it', 'fmwareVersion': '2.1.6', 'skillNumber': '', 'reservedDomain': 'eu-smart.meross.com', 'onlineStatus': 1, 'devName': 'Socket'}], 'timeStamp': 1550308954, 'sysStatus': 0}

AFAIK this confirms that the data is correctly pulled from the Meross servers, just the library has to be adapted to support it. Do you think it will be possible?

albertogeniola commented 5 years ago

Hi @virtualdj , yeah, the device is listed among the ones that are available. However, the library does not recognize its device id (MSS310H) so it doen't support that plug. Anyways, there are good chances that the hardware is supported by the library, but I cannot confirm it.

To better investigate, I can add the device ID among the ones that are supported and give you a new version of the library. You should "test it" and report it works or not. If it does, I will then release that version to the public. Would it be ok for you?

virtualdj commented 5 years ago

Of course, I'm available to run test if you need!

Just FYI I've tried to add to device_factory.py the line:

elif device_type.lower() == "mss310h":
    return Mss310(token, key, user_id, **device_specs)

... hoping that the same "class" would be enough, but then I get:

user@ubuntu:~/meross$ python3 meross.py
Listing Devices...
Traceback (most recent call last):
  File "meross.py", line 11, in <module>
    devices = httpHandler.list_supported_devices()
  File "/usr/local/lib/python3.4/dist-packages/meross_iot/api.py", line 124, in list_supported_devices
    device = build_wrapper(self._token, self._key, self._userid, deviceType, dev)
  File "/usr/local/lib/python3.4/dist-packages/meross_iot/device_factory.py", line 14, in build_wrapper
    return Mss310(token, key, user_id, **device_specs)
  File "/usr/local/lib/python3.4/dist-packages/meross_iot/supported_devices/power_plugs.py", line 134, in __init__
    tls_version=ssl.PROTOCOL_TLS,
AttributeError: 'module' object has no attribute 'PROTOCOL_TLS'

Thanks!

albertogeniola commented 5 years ago

Hi, you are on the right path. The problem is that the library is somehow referring to the wrong SSL module...

It seems you are using python3.4, while this library requires python 3.6+ to work correctly. Would you mind to update your python version and try again with the modified source?

virtualdj commented 5 years ago

It seems you are using python3.4, while this library requires python 3.6+ to work correctly.

Oops, sorry, I didn't catch that! I've updated to python 3.6 on my old Ubuntu 14.04 LTS and set up the README example script to run with 3.6.

Then I edited the new /usr/local/lib/python3.6/dist-packages/meross_iot/device_factory.py as before and now I get a long (verbose) output with JSON (the print(jsondata) is still commented out).

I've attached a file, where I removed some personal information with "#", please let me know if there is other data which should not be kept here.

Anyway, the plug turns on and off, is the output correct? Shouldn't I get numerical output instead of raw JSON and errors?

albertogeniola commented 5 years ago

Well done, the output is ok. Output is in JSON format (dictionary object), so that is ok. Well done. Why don't you test all the APIs on your device and propose a Pull Request so that MS310H owners can start using this library as well?

virtualdj commented 5 years ago

Well done, the output is ok.

Including the UNKNOWN error messages?

Why don't you test all the APIs on your device and propose a Pull Request so that MS310H owners can start using this library as well?

OK, but I'm pretty new to Python (never worked with it apart streamlink), can you point me how should I do it (testing the API, not creating the PR).

albertogeniola commented 5 years ago

I've looked again at the code. It seems that your device is responding with a valid ACK to the ON-OFF but is not setting up the "toggle" property into the payload of the response. Anyways, the message you see is just a debug message. The problem is that the status property is not updated and the getStatus might be wrong. I should investigate better on your device before adding explicit support to it. For now, I'll create the PR myself and add a warning message for MSS310H owners.

image

albertogeniola commented 5 years ago

Alright, you can install the latest version of the package (0.1.4.3). If you want to update the existing library, you can issue the following command:

pip install --upgrade meross-iot

Let me know if it works as expected !

virtualdj commented 5 years ago

Anyways, the message you see is just a debug message. The problem is that the status property is not updated and the getStatus might be wrong. I should investigate better on your device before adding explicit support to it. For now, I'll create the PR myself and add a warning message for MSS310H owners.

OK, I've updated the library and re-run the script but the output doesn't seem different from the previous one. It's attached here as meross-output-2.txt.

Let me know if you need further tests or different scripts to run to improve the library for MSS310H, I'm available.

albertogeniola commented 5 years ago

Hi virtualdj, I don't understand what the problem is. As far as I understood, you're now able to turn the plug ON and OFF, right? If not, could you please explain better?

virtualdj commented 5 years ago

As far as I understood, you're now able to turn the plug ON and OFF, right?

Yes, confirmed!

I don't understand what the problem is.

You said earlier:

the message you see is just a debug message. The problem is that the status property is not updated and the getStatus might be wrong. I should investigate better on your device before adding explicit support to it. For now, I'll create the PR myself and add a warning message for MSS310H owners.

so what I noticed is that even with this new version, the library returns the same output than before (including the "UNKNOWN msg received by ..."). I though it wasn't your expected result... so I asked if there's anything you need to investigate and, if yes, then I'm at your disposal ;-)

zuno commented 5 years ago

Hello Alberto.

I confirm that mss310h works fine for me now.

Thankyou.

I'm available for tests if you need

albertogeniola commented 5 years ago

As far as I understood, you're now able to turn the plug ON and OFF, right?

Yes, confirmed!

I don't understand what the problem is.

You said earlier:

the message you see is just a debug message. The problem is that the status property is not updated and the getStatus might be wrong. I should investigate better on your device before adding explicit support to it. For now, I'll create the PR myself and add a warning message for MSS310H owners.

so what I noticed is that even with this new version, the library returns the same output than before (including the "UNKNOWN msg received by ..."). I though it wasn't your expected result... so I asked if there's anything you need to investigate and, if yes, then I'm at your disposal ;-)

Ah, yeah, I see now. Well, at the moment I cannot prepare any specific implementation to address that issue. But I really appreaciate your help and I'll ask you to test in case I end up with something. Thank you guys!