Help with implementing a custom library

Dear developers
Im trying to update an abandoned custom_components integration but since my programming skills in python / hassio are limited I need some guidance.

Even though i managed to update the file structure and other python functions of the integration to work in the latest version of hassio, there’s this code:

 from my_custom_lib import MyClient 

which fails the initial setup procedure.

my_custom_lib folder is inside hassio/config/deps/lib/python3.6/site-packages/ and contains library python files.

How can I make hassio load my_custom_lib files?

1 Like

Can we get more info? What files does your custom component have? what does the manifest.json have in it? What are the errors in the logs?

Have you read these docs?

hello.
The file structure is:

  • custom_components
    – inventor_hub
    init.py
    — climate.py
    — sensor.py
    — inventor_hub.py
    — manifest.json

the manifest file:

{
  "domain": "inventor_hub",
  "name": "Inventor HUB",
  "documentation": "https://github.com/soppilif/inventor_hub",
  "dependencies": [],
  "codeowners": [ "@smartHomeHub"],

  "requirements": ["midea-inventor-lib"],
  "homeassistant": "0.99.3",
  "updater": {
    "version": "1.8.0",
    "releaseNotes": "-- Added support for the latest HASS.IO<br> Based on the repository of @smartHomeHub",
    "files": [
      "__init__.py",
      "climate.py",
      "sensor.py",
      "inventor_hub.py",
      "manifest.json"
    ]
  }
}

It tries to load the library:

from midea_inventor_lib import MideaClient

which is in the pypi directory

but hassio logs say:

(MainThread) [homeassistant.setup] Setup failed for inventor_hub: No setup function defined.

I don’t think this error is related to the import. I think you don’t have the correct setup function defined, possibly in your __init__.py.

yes, you’re right
Once i copy/pasted the code from inventor_hub.py to init.py it changed the error to:

[homeassistant.setup] Unable to prepare setup for platform inventor_hub.climate: Platform not found (cannot import name ‘SUPPORT_TARGET_HUMIDITY_LOW’ from ‘homeassistant.components.climate’ (/usr/src/homeassistant/homeassistant/components/climate/init.py))

which probably means that i need to find the equivalent names of the latest hassio for

from homeassistant.components.climate import (
    ClimateDevice, ATTR_CURRENT_HUMIDITY, ATTR_HUMIDITY, ATTR_MIN_HUMIDITY, ATTR_MAX_HUMIDITY,
	SUPPORT_TARGET_HUMIDITY, SUPPORT_TARGET_HUMIDITY_LOW, SUPPORT_TARGET_HUMIDITY_HIGH,
    SUPPORT_FAN_MODE, SUPPORT_OPERATION_MODE, SUPPORT_ON_OFF,
    ATTR_FAN_MODE, ATTR_FAN_LIST, ATTR_OPERATION_MODE, ATTR_OPERATION_LIST,
    PLATFORM_SCHEMA)
1 Like

hope you get this right :smiley: !
cheering for you!

1 Like

unfortunately it requires advanced knowledge of python for it to work with the latest version of hassio, which I dont have.
Not only files and folders structure have changed but also the havc functions.
Old version of the integration has functions and calls which no longer exist.

any devs that have a little bit of free time to check this out :smiley: ?

1 Like

I second that request!

Did some more digging to it.
Seems that both the structure and the commands have changed. What I did with the same module (Πατριδα υποθετω ετσι?) since I have the EVA II dehumidifier, is that I copied both folders (midea_dehumi & midea_inventor_lib) in the custom_components folder. Before I had the midea_inventor_lib in the /config/deps/lib… etc and it couldn’t find it. I guess another upgrade broke that.
Also, you’ll need to rename the midea_dehumi.py to init.py and create a manifest.json with the following:

{
    "domain": "midea_dehumi",
    "name": "midea_dehumi",
    "documentation": "https://github.com/barban-dev/midea_inventor_dehumidifier",
    "dependencies": [],
    "codeowners": ["@barban-dev"],
    "requirements": ["midea_inventor_lib==1.0.3"]
  }

In every folder (climate folder, sensor folder) you take the .py files and rename them to it’s component file (eg. climate.py, sensor.py)
In final terms, you’ll need to have the midea_dehumi folder inside custom_components folder with the following files:
init.py
manifest.json
climate.py
sensor.py
And of course the midea_inventor_lib inside custom_components too.

Now the first module will load and find your dehumidifier from the cloud (yay!).
The second and real PITA problem is that, apart from hass upgrading and breaking the custom_components tree, it also changed naming and structure of the climate control. …Sigh…
SUPPORT_TARGET_HUMIDITY_LOW has been removed
SUPPORT_TARGET_HUMIDITY_HIGH has been removed
SUPPORT_OPERATION_MODE I guess has become HVAC_MODES
SUPPORT_ON_OFF I guess has become HVAC_MODE_OFF
ATTR_FAN_LIST I guess has become ATTR_FAN_MODES
ATTR_OPERATION_MODE I guess has become ATTR_HVAC_MODE
ATTR_OPERATION_LIST I guess has become ATTR_HVAC_MODES
I don’t know a lot of python, but I’m good with programming logic, so I’ll give it a shot if I can convert it to something workable. Of course it will take a very long time since I’ll go by chances and not by programming knowledge!
I hope a person with knowledge can do it though! That would be heaven!

1 Like

In reply to my previous comment, I’m working at the midea_dehumi package!

1 Like

great news.
This is where i got stuck… coping with the removed properties and integrating the new hvac ones.

any progress on this :slight_smile: ?

Not from me (yet anyway). Since I don’t have programming skills, I’m working with logic and comparing with other climate devices which are updated. So far I’ve done nothing but a hole!

i did the same, but i’m at a dead end ρε γμτ.

Good news everybody! (I hope you read that with the proffessors voice from Futurama)
I’ve successfully converted the script to properly recognise the Midea Dehumidifier and be able to see the humidity percentage and set fan speeds. Seems I’ve surpassed the problem that hvac_mode was not implemented. Current problem to solve is setting power modes (smart mode, clothes dry etc) and be able to turn it on or off. But we’re on a good path!
If someone wants, I can post the current zip which is working like I said above until I fix it completely!

2 Likes

yeahaaaa :D!
good work !

Ok, I’ve made a hole so far. For some reason other climate devices use proper HVAC modes and our isn’t. Which is correct, since it was created pre-hvac mode era, but I can’t figure out how to both get HVAC modes for Hass to be happy AND Midea operation modes to be happy. For now Only current humidity works and fan set works. You cannot turn it on or off from hass or set a mode.
Anyway, here’s the link for the partially working component, since the wall I hit will probably take a long time to resolve. Hope someone with knowledge can do better than me.
Click to Download

hummm the file is corrupted and the rar doesnt open :-s