homeassistant-midea-dehumidifier
homeassistant-midea-dehumidifier copied to clipboard
MideaClient does not support multiple device due "static" content
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?
Could you detail how you did it? I'm interested in your solution.
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
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
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
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 👍
Thanks a lot! :) by the way
Please, feel free to share my code. I'm new on github and I don't know its dynamics..so please share :)
Thank a lot Gianluca! Your code works like a charm! :-)
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.