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

MideaClient does not support multiple device due "static" content #11

Open
gianlucasullazzo opened this issue Jan 15, 2021 · 11 comments
Open

Comments

@gianlucasullazzo
Copy link

MideaClient cannot support multiple device (like 2 dehumi) because hass.data[MIDEA_API_CLIENT] is the same for all devices.
When hass queries first device status, all other ones will assume that specific status.
I "solved" in my custom_component by creating new client inside MideaDehumidifierDevice constructor (instead of receiving it) but this is not a good solution. Are you planning to develop multi device integration?

@HVPereira
Copy link

Could you detail how you did it? I'm interested in your solution.

@gianlucasullazzo
Copy link
Author

Hi,
in init.py, I pushed into hass.data new client for each appliace:

    if not deviceId:
        if appliances is not None:
            for a in appliances:
                if a["type"] == "0xA1":
                    deviceId = str(a["id"])
                    targetDevice = a
                    client_for_device = MideaClient(username, password, sha256password, cacheTimeInSeconds = 0)
                    res = await hass.async_add_executor_job(client_for_device.login)
                    if res != -1:
                        sessionId = client_for_device.current["sessionId"]
                        _LOGGER.info("midea-dehumi: login success, sessionId=%s", sessionId)
                        hass.data[MIDEA_API_CLIENT + "_" + a["id"]] = client_for_device
                    _LOGGER.info("midea-dehumidifier: loading humidifier entity sub-component...")
                    load_platform(hass, 'humidifier', DOMAIN, {MIDEA_TARGET_DEVICE: targetDevice}, config)
                    _LOGGER.info("midea-dehumidifier: loading sensor entity sub-component...")
                    load_platform(hass, 'sensor', DOMAIN, {MIDEA_TARGET_DEVICE: targetDevice}, config)
                    _LOGGER.info("midea_dehumidifier: platform successfuly initialized.")
    else:
        if appliances is not None:
            for a in appliances:
                if a["type"] == "0xA1" and deviceId == str(a["id"]):
                    targetDevice = a

the key is: hass.data[MIDEA_API_CLIENT + "_" + a["id"]] = client_for_device

In humidifier.py, I changed the way to get client:

self._client = hass.data[MIDEA_API_CLIENT + "_" + targetDevice['id']]

Hope it helps.
If you need further clarification, please ask me.

Regards,
Gianluca

@HVPereira
Copy link

Ok I'll try it soon and revert back to you thanks a lot.... I think this solution it's way better than the one i was proposing..... Maybe barban push this change to his git

@flos76
Copy link

flos76 commented Jan 21, 2021

Hi,
thanks for the work. Unfortunately I can't get your solution to work for me.
I have inserted your code - I hope - in the right location in init.py (line 95, in the code-block following #The first appliance having type="0xA1" is returned...) which seems to work fine. But as soon as I change humidifier.py my home assistant starts throwing 2 error messages about unretrievable task errors...

Is it correct to simply paste your code in the block following
`class MideaDehumidifierDevice(HumidifierEntity):
"""Representation of a Midea/Inventor dehumidifier device."""

def __init__(self, hass, client, targetDevice):`

like this

    #Device modes
    self._modes_dict = DEHUMI_MODES_DICT
    self._available_modes = DEHUMI_MODES_LIST

    #self._client = client
    self._client = hass.data[MIDEA_API_CLIENT + "_" + targetDevice['id']
    self._device = targetDevice
    self._name = "midea_dehumidifier_"+targetDevice['id']
    self._unique_id = 'midea_dehumidifier_' + targetDevice['id']

Unfortunately I don't really understand python-code... am I missing something?
Regards,
Florian

@gianlucasullazzo
Copy link
Author

Hi Florian
attached both files.
init.py.txt
humidifier.py.txt

Regards,
Gianluca

@HVPereira
Copy link

It's working :) I have done all the changes and it is working quite well. Congratulations! And thanks a lot you should share your code with the community

https://community.home-assistant.io/t/midea-dehumi-custom-component-midea-inventor-invmate-eva-ii-pro-wifi-dehumidifier/89638/89

I've added part of your code but you should take the merit for these findings 👍

@HVPereira
Copy link

Thanks a lot! :) by the way

@gianlucasullazzo
Copy link
Author

Please, feel free to share my code.
I'm new on github and I don't know its dynamics..so please share :)

@flos76
Copy link

flos76 commented Jan 23, 2021

Thank a lot Gianluca! Your code works like a charm! :-)

@Bimboboy007
Copy link

Hello, today the error occurred again that the integration Midea Dehumidifier Lan did not load after a new type of server.
Then I immediately took a screenshot.
Bildschirmfoto 2022-01-03 um 23 11 45

@barban-dev
Copy link
Owner

Hi @gianlucasullazzo , I would like to merge your modificatiion in the next release (pushing hass.data new client for each appliace): why do you state that "it is not a good solution" on the first post ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants