How do I make ESPHome include esphome/components/template/switch in the c++ source tree please?

Hi,
I have been urged to move from a customcomponent to a ‘real’ component, and its all going well, except I am struggling to get ESPHome to copy across the esphome/components/template/switch to the generated code.

I can work around it by adding an internal: component to the yaml, but trying to avoid this was why I switched to a ‘real’ component (with a python part).

I thought it would be adding to the cv.adddefine or the cg.add_global, but I havent managed to make it work.

Looking at the actual template_switch.cpp code, I cannot see how it makes the codegen include itself, but it does…

The reason im doing this is because I want my custom component to ‘swawn’ a number of switches (and numbers) that appear in homeassistant. This works great with the workaround of the dummy template switch, but I feel there is a better way… (i am directly creating the template_::TemplateSwitch in the setup() method of my component)

Can anyone help here please?
thank you,
George

Sorry you haven’t received any answers yet. I have the exact same question, and Google landed me here. This seems like a basic necessity for developing esphome components, but I can’t find any documentation on it. The esphome classes that I need are nowhere to be found at compile time… unless I create dummy config in the yaml file.

I’ve searched for documentation on the c++ code generation python scripts, but I haven’t been able to find anything. On the esphome “Contributing” web page, they state:

The details of ESPHome code generation is out-of-scope for this document.

But there is no link for a document that covers this topic. It looks like our only option is to reverse-engineer existing components.