Hello everyone,
I’ve managed to make a small update on this library to make it compatible with multiple devices, unfortunately I am no developer therefore I don’t even know how to purpose the change on github.
For those of you wanting to have multiple devices in one single account replace the following code on init.py:
for a in appliances:
appliancesStr = "[id="+a["id"]+" type="+a["type"]+" name="+a["name"]+"]"
if a["onlineStatus"] == "1":
appliancesStr += " is online,"
else:
appliancesStr += " is offline,"
if a["activeStatus"] == "1":
appliancesStr += " is active.\n"
else:
appliancesStr += " is not active.\n"
_LOGGER.info("midea-dehumi: "+appliancesStr)
#The first appliance having type="0xA1" is returned for default (TODO: otherwise, 'deviceId' configuration option can be used)
targetDevice = None
if not deviceId:
if appliances is not None:
for a in appliances:
if a["type"] == "0xA1":
deviceId = str(a["id"])
targetDevice = a
else:
if appliances is not None:
for a in appliances:
if a["type"] == "0xA1" and deviceID == str(a["id"]):
targetDevice = a
if targetDevice:
_LOGGER.info("midea-dehumidifier: device type 0xA1 found.")
hass.data[MIDEA_API_CLIENT] = client
_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.")
return True
else:
_LOGGER.error("midea-dehumidifier: device type 0xA1 not found.")
return False
to:
for a in appliances:
appliancesStr = "[id="+a["id"]+" type="+a["type"]+" name="+a["name"]+"]"
if a["onlineStatus"] == "1":
appliancesStr += " is online,"
else:
appliancesStr += " is offline,"
if a["activeStatus"] == "1":
appliancesStr += " is active.\n"
else:
appliancesStr += " is not active.\n"
_LOGGER.info("midea-dehumi: "+appliancesStr)
#The first appliance having type="0xA1" is returned for default (TODO: otherwise, 'deviceId' configuration option can be used)
hass.data[MIDEA_API_CLIENT] = client
targetDevice = None
if not deviceId:
if appliances is not None:
for a in appliances:
if a["type"] == "0xA1":
deviceId = str(a["id"])
targetDevice = a
hass.data[MIDEA_API_CLIENT] = client
_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
if targetDevice:
# _LOGGER.info("midea-dehumidifier: device type 0xA1 found.")
# hass.data[MIDEA_API_CLIENT] = client
# _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.")
return True
else:
_LOGGER.error("midea-dehumidifier: device type 0xA1 not found.")
return False
I’ve also removed the lines:
_LOGGER.info("midea-dehumidifier: loading sensor entity sub-component...")
load_platform(hass, 'sensor', DOMAIN, {MIDEA_TARGET_DEVICE: targetDevice}, config)
and used the hass to fetch the sensor from the humidifier as it is more stable.
I’ve updated as well with tank_show and made a commit let’s hope it is approved.