How to create a custom component from a folder structure that has no component folder?

Everyone seems to say “create a custom component” and all of the examples show root file/folder structures where a ‘components’ folder exists …but how do you create a custom component from a folder structure where it does NOT exist …

I need to make a custom component of this python script …

/usr/local/lib/python3.8/site-packages/pyvesync/vesyncswitch.py

What must it look like in my custom-components folder?

Copy all of this:

To config/custom_components/vesync

Edit what you have to in that location and restart. It will be used in place of the core integration.

Or am I misunderstanding your question?

Thank you for the help but yes, I believe you are misunderstanding my question.

The python file which appears to need editing/has the issue is not in the vesync component folder.

The file in question exists in /usr/local/lib/python3.8/site-packages/pyvesync/vesyncswitch.py

It is the vesyncswitch.py file I need to be edited. How do I ‘place’ that file in the custom component folder to simulate it’s original file structure?

On a related note … if it is only a single file that I needed to be edited in the vesync component folder you have provided, am I still required to copy ALL of the files to the custom component folder for it to function correctly?

All the files.

Ok, cool.

And to the other issue of pyvesync?

/usr/local/lib/python3.8/site-packages/pyvesync/vesyncswitch.py

No idea, sorry.

Ok, thanks.

Any idea where I can find out this information?

Pyvesync is what is called a library. Can you use any of the pyvesync packages on pypi.org? Like this one? https://pypi.org/project/pyvesync/
If yes, you can have the pyvesync library installed into HA Core via the manifest.json file.
And then make sure to call the needed pyvesync-functions where needed in the other py-files.

I wish it were far easier than that. Home Assistant, neither the HassOS nor the Supervised install give them the ability to do what you suggest, and even if it/I could … I’d clearly have solved the issue by now and update the Github page. In short, I don’t know how to do what you’re suggesting to do nor does it sounds easier than either solution below.

The apparent solution is incredibly easy in essence but made to be incredibly hard in practice. I’m just looking for the easy way to change a particular python file in the Home Assistant Core or, if that is simply not possible or allowed, to be able to install “non”- component .py file as a custom-component. It appears few people, if any(???), know how to achieve either?

Is there a way to use pip install to install the pyvesync library from the link you suggest WITHOUT having it automatically install the most recent one? That is I want to install the pyvesync library from October 2020. Can I do that?

I did a little digging, I see that the HA Core vesync code points to pyvesync version 1.2.0. While trying to find that version on Pypi I noticed that someone else is taking care of pyvesync now and that the latest version is 1.3.1: https://github.com/webdjoe/pyvesync
Does that new version contain the fix you are looking for? If yes, follow @tom_l 's advice, and then change the version number to 1.3.1 in the manifest.json file. After that, restart HA Core and add the Vesync Integration when it is not already there.

Thank you for the continued troubleshooting here.

A couple of additional information points. I have my issue added to the ‘current’ issues on the Home Assitant Github Core repository. The person who initially had the same issue was able to resolve his issue by following the instructions I gave him that had been suggested to me by another person from the Home Assistant Community (in an original topic of mine explaining my issue).

That person whom I helped fix his issue confirmed this … it would suggest, to me, that the 1.2.0 version is actually the last version in which the vesync issue did NOT exist.

Thanks for the info. That seems to correct my issue (for now). I’m running core in virtual environment and updating pyvesync to 1.3.x breaks the integration. I didn’t realize that the vesync integration calls pyvesync…

The issue remains in 2021.3.4

Here is the information from my previous Home Assistant Community forum post …

I know this issue is a month old so not sure if you still have the issue. I was encountering the same error and found out it was due to me having a couple of the 3-way switches. I haven’t looked into the issue that deeply but my guess is when it sees the switch, it’s looking to see if it has the feature of ‘is_dimmable’ and it’s not assigned. If you know how to edit that file (vesyncswitch.py), you can add it to the feature_dict like it is below (the ESWL03) and that seems to solve the issue.

Copy to clipboard
feature_dict = {
‘ESWL01’: [],
‘ESWL03’: [],
‘ESWD16’: [‘dimmable’]
}

Suffice to say, with my current install of Home Assistant Supervised(Supervisor?) I am unable to either 1) edit the pyvesync file in my home assistant core, 2) install or downgrade my current pyvesync version from 1.3.1 to 1.2.0 or 3) install the ‘working’ version of pyvesync as a custom component.

If someone knows how I can do this maintaining the Supervised install, then great … otherwise it appears I will need to look at installing the Core install just so I can fix this issue for myself.

Thank you.

Which manifest.json file? … home assistant core contains more than 1.

How do I confirm what pyvesync I am running, as I am of the belief we (anyone with an up to date HA) is running 1.3.1, not 1.2.0.

I looked at the vesync component in the HA Core dev branch: https://github.com/home-assistant/core/blob/73c6728e98e2e853afa9bd80b3a689c2d56e49e3/homeassistant/components/vesync/manifest.json
It says 1.2.0.

You should opt for 3) that is the quickest way to make work what you want.

Let’s take this step by step. Are you able to create a custom_components subdirectory on you Home Assistant Core filesystem? In the config directory?

Ok, my bad … a little digging myself and I realize it’s the manifest.json file in the vesync component … I am a little surprised that the call to 1.2.0 is the current version?

Yes I can create and run a custom component. I think, the question is, can you run a python library (pyvesync) as a custom component?

No you can’t. You will have to create a vesync custom_component first: just copy all the files and dirs from here: https://github.com/home-assistant/core/tree/73c6728e98e2e853afa9bd80b3a689c2d56e49e3/homeassistant/components/vesync
into /config/custom_components/vesync.

Once you have done that, you can change the pyvesync version, just edit the version nr. in manifest.json and restart HA Core. Or you can try the pyvesync_v2 version by changing the requirements line in manifest.json to:

  "requirements": [
    "pyvesync_v2==1.1.0"
  ],

And restart HA Core.

If that still doesn’t work, you could create a folder in the /config/custom_components/vesync dir called pyvesync, copy the files from here: https://github.com/webdjoe/pyvesync/tree/master/src/pyvesync into that dir and edit the files you want. And remove the requirements line from manifest.json I think.
Please note: this should in principle work but you might need to remove the already installed pyvesync version files. They can be found in the HA supervisor-docker if I’m not mistaken. Or maybe they are uninstalled when you remove the requirements line from manifest.json.

Thank you for your help.

I have tried a version of what you have suggested. I am encountering multiple different issues I believe.

I have tried referencing pyvesync_v2==1.1.0 as you suggest but I am unsure if it’s installed the library or not? I can’t seem to use pip install from my Ri’s root to modify everything, and even the library’s that I seem to be able to modify aren’t seemingly the libraries I need to modify. My error log below still is referencing pyhton3.8 packages that, no matter what I do on my Pi root directory, I am not able to gain access to them. The times pip install works it appears to modify python2.7 packages, not the 3.8 version packages, and, as you can see below, the error codes mention 3.8 and their locations (which I cannot access). I have also, at times been given error messages of the ilk of ‘unable to access’ or ‘permission denied’ when trying to look for, or install packages on the Pi root. This continues to lead me to believe I may need to scrap the Supervised version and go to the Core or Docker version of HA to be able to modify the file until it’s included in the HA repository (see Joe Webd comment below).

It also seems like a whole lot of work to circumnavigate a known solution which involves modifying 1 file with maybe less than 100 characters of code.

I have also been able to contact ‘Joe Webd’ one of the contributors to the pyvesync library. He has suggested to me that the ‘fix’ I talk of is included in the ‘already’ release pyvesync version 1.3.1, though, as we know, that’s not yet in the HA core repository. He suggested I submit a PR to the HA repository to update the requirements.txt file. I will look into how to do that and do that.

Logger: homeassistant.config_entries
Source: custom_components/vesync/common.py:30
First occurred: 12:49:21 PM (1 occurrences)
Last logged: 12:49:21 PM

Error setting up entry [email protected] for vesync
Traceback (most recent call last):

  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 248, in async_setup
    result = await component.async_setup_entry(hass, self)  # type: ignore
  File "/config/custom_components/vesync/__init__.py", line 80, in async_setup_entry
    device_dict = await async_process_devices(hass, manager)
  File "/config/custom_components/vesync/common.py", line 30, in async_process_devices
    if not switch.is_dimmable():
  File "/usr/local/lib/python3.8/site-packages/pyvesync/vesyncswitch.py", line 29, in is_dimmable
    if 'dimmable' in feature_dict.get(self.device_type):
TypeError: argument of type 'NoneType' is not iterable

A few quick notes:

  • use pip3 to install python3 packages
  • Codeowners are supposed to maintain HA Core integrations, I think Joe Webd is listed as codeowner so why doesn’t he create the PR for the v1.3.1 update?
  • Fact: getting changes/updates into HA Core is a slow process. Creating a custom_components is relatively quick and easy and when created, then it is fun fixing stuff yourself, when you are able to.

Thank you for your continued comments and efforts.

I’ve had an update to the issue and it appears I may have resolved it. I have not yet confirmed what I am going to say but as simple as it seems, it has also seemingly eluded many people and attempts at solving.

I believe the latest version of pyveseync (1.3.1 on pypi) does indeed fix my issue.

Installing the Vesync integration as a custom component, then modifying the manifest.json file from its current install valued of 1.2.0 to 1.3.1 appears to have fixed the issue, for me. That appears all I needed to do. I guess there was an assumption that the “current” Vesync integration was calling the “latest” pyvesync library and that that library was the issue. That does not appear to be the case.

I do not know if the 1.3.1 library is already in the Home Assitant install or if calling, from the custom component, the 1.3.1 library forces it to be downloaded and installed (even though using pip commands doesn’t appear to work … haven’t/didn’t try pip3). Either way, it appears to have fixed it for me.

I am not sure why the standard HA install only calls 1.2.0.

Glad to hear that it works!

Your assumption is correct: after installing vesync as custom_component, it overrules the exiting Core vesync integration. So when you change the version of pyvesync in the custom_component, that new version is installed.

Standard HA Core calls v1.2.0 because that number is in the vesync manifest.json file, that just how HA Core works.