ESPHome is by-and-large a build system to build bespoke C++ programs. The python files you're seeing describe how that yaml file maps to the C++ files.
The core idea is that end users (including people managing custom sensors) as much as possible only have to interact with the yaml file. The yaml file lists what components you want to run and their configurations. A component is in general a subdirectory of esphome/esphome and is intended to be independent of other components.
Those github references in the yaml pull in external components from the community. It's roughly equivalent to dropping another folder into the source tree (noting again that you shouldn't usually need to have the source tree at all).
Running esphome copies all used components into a separate source tree, with substitutions and variables set according to the yaml configuration (defined by the component's python files) and builds a bespoke binary for you that will run on your device.
If you want to include code that's not already an ESPHome component, you will need to make it into one. You can do this in place in the source tree or by creating an external component yourself. You will want to use an existing component as a template for this. Have a look for if ESPHome itself or a community component already exists first because it will make your life so much easier.