Location of Tuya Core Integration Files

I trying to find the location of the Tuya Integration files so I could possibly edit/overide something in them that pertains to one of my devices. From what I read in the HA documents I need to…

I search through a lot of the system folders but I can’t find the Tuya Integration files. Could someone please point me in the right direction? Thank you.

Your question is very much worded like an XY Problem. What is it you’re trying to achieve? i.e. what is it you want to override, and to what outcome? Editing the underlying files does not sound like a good idea.

Best way to change something on a core integration is to download source code from HA, get the integration files and add it to your custom_components folder

@michaelblight sorry about that. I didn’t get into the details of why on purpose but I could…

I’ve had two issues with the Tuya Integration for awhile and have not been able to get too much help solving them. The first issue is posted but its been open since May 2022. I also opened tickets with Tuya for both of the issues. Their answer to the first isse was that it was something that they would not be addressing at the current time (which I have no idea why) and the second issue will be addressed in a future update (which there hasn’t been in awhile)

The first issue is that when I add a specific device to the Tuya App it breaks something in the code of the Tuya integration and causes any entity in the integration that uses the light domain to become “unsupported” and no longer work. I could still use the devices via the Tuya Local integration and the Tuya App which means the problem is isolated to the HA Core Tuya Integration. (This is the issue that Tuya’s said they would not be addressing at the current time.)

There are two specific devices that cause this to happen and I consider both of them switches but the Tuya integration automatically adds them as lights. One switch is a socket and the other is a wall switch. I checked the Tuya product type for both of them, which is cz and qjdcz, and found them listed in both the light.py and the switch.py files. Here they are in the light file.

# Socket (duplicate of `kg`)
# https://developer.tuya.com/en/docs/iot/s?id=K9gf7o5prgf7s
LIGHTS["cz"] = LIGHTS["kg"]
    # Unknown product with light capabilities
    # Fond in some diffusers, plugs and PIR flood lights
    # Not documented
    "qjdcz": (
        TuyaLightEntityDescription(
            key=DPCode.SWITCH_LED,
            color_mode=DPCode.WORK_MODE,
            brightness=DPCode.BRIGHT_VALUE,
            color_data=DPCode.COLOUR_DATA,
        ),
    ),

…and here they are in the switch file.

# Socket (duplicate of `pc`)
# https://developer.tuya.com/en/docs/iot/s?id=K9gf7o5prgf7s
SWITCHES["cz"] = SWITCHES["pc"]
    # Unknown product with switch capabilities
    # Fond in some diffusers, plugs and PIR flood lights
    # Not documented
    "qjdcz": (
        SwitchEntityDescription(
            key=DPCode.SWITCH_1,
            name="Switch",
        ),
    ),

By using the method described here I want to try and remove those lines of code from the light file to see if it fixes the issue. That method requires me to add the source of the file and so far I have been unable to locate it the light.py file.

The other issue is that one of my cover devices added by the Tuya intergraion operates incorrectly. The open and close functions are reversed. If I try to open the cover it closes and if I try to close the cover it opens. I checked the state of the device on the Tuya IoT and it seems to be sending the correct state to HA. If I use the Tuya App or the Tuya Local integration the cover operates correctly.

The checked the app and I have the ability to change the direction of the motor but that only affects the physical cover. The Tuya Local integration has the option for me to Invert 0-100 position (for *position* mode only) which I use and why I think it works correctly from Tuya Local. When Tuya said that the issue would be addressed in a future update I figured that they would be adding the ability to “invert the position” like the Tuya Local integration.

I’m not that worried about this issue but if I have the time I want to see if I could somehow add code to the cover.py file that is similar to what the Local Tuya integration uses to “invert the position”. I also thought about adding a template sensor to HA that inverts the position but I don’t think that will work.

I apologize for the lengthy explanatin but you asked and I wanted to try and be as clear as possible so you or someone else understands. Thanks.

AH that makes more sense now. Generally if you want to find the source, look up the integration page (eg. google “home assistant tuya integration”). When you find the page it will have the github link on the right, which in this case is core/homeassistant/components/tuya at dev · home-assistant/core · GitHub. For some you need to hunt around from there, but for tuya it looks straightforward. You can get the relevant source files you need from there. I’ve never overridden one of these myself, but as others have said, you would (for example) copy “alarm_control_panel.py” to “/config/custom_components/tuya/alarm_control_panel.py” and then restart HA.Good luck!

@makai that’s exactly what I am trying to do but according to the post at the bottom I need to “recreate the folder path” inside of the custom_components folder. I already downloaded the source code from here but I’m unsure of the exact folder path unless it’s as simple as using this as the path?

/config/custom_components/tuya/light.py

The post also says I need to create a “dummy version in the manifast file” so does that mean that I need to add all of the files from the main Tuya source code folder or can I just add the manifest file and the file I am editing which is light.py?

@michaelblight I was worried that there might be an additional folder that it was in so I wanted to locate it just to make sure. I also read a post and in the documentation that I need to add a verion to the manifest file or it won’t work. If that’s true now I’m wondering if I need the entire contents of the Tuya folder or just the manifest and light files. I’ll have to try it both ways to see what happens. Thanks.

Copy the full tuya folder and paste it in the custom_components folder. Then open tuya/manifest.json file and add this line:

"version": "0.1",

Can’t get this to work and I am not sure I understand correctly.

If I want to change line 189 of “/components/media_source/local_source.py” do I then need to copy the full “media_source” folder (including the files I do not wish to change) to the “config/custom_components/” folder?

And in that case should I add version number to the copied version of the manifest.json in the custom_components folder or the original manifest.json?

Yes

The one in the custom_component folder

Thanks. And I also need to copy all the files in the orginal media_source folder I do not wish to change to the custom_components folder (or only the folder structure and file to be edited)?

All the media_source folder with all files

Thank you!

Ah, even after a few restarts it doesn’t seem to want to work:

# Home Assistant Core

Setup failed for default_config: (DependencyError(...), 'Could not setup dependencies: media_source')

7:11:34 PM – (ERROR) setup.py

Unable to set up dependencies of default_config. Setup failed for dependencies: media_source

7:11:34 PM – (ERROR) setup.py

Setup failed for custom integration media_source: No setup or config entry setup function defined.

7:11:14 PM – (ERROR) setup.py

I copied everything from components/media_source to /custom_component/media_source and added , “version”: “0.1” to the copied manifest.json:

{
  "domain": "media_source",
  "name": "Media Source",
  "codeowners": ["@hunterjm"],
  "dependencies": ["http"],
  "documentation": "https://www.home-assistant.io/integrations/media_source",
  "integration_type": "system",
  "quality_scale": "internal",
  "version": "0.1"
}

I can’t help you here. It should works. Maybe because it’s a default integration :thinking:

No worries and thank you anyway. I think it might have something to do with me running a supervised version. Just tried on a Home Assistant OS version and on that machine it works!

1 Like