__init__.py is now required
jeffjl74 opened this issue · 2 comments
jeffjl74 commented
I only tested the empty_text_sensor component, but I suspect the following is true for each component.
Somewhere between ESPHome versions 1.16.2 and 1.18.0, it became a requirement for the component folder to contain an __init__.py
file, even if that file is empty. Otherwise, the compile fails with the following errors:
src/main.cpp:16:1: error: 'empty_text_sensor' does not name a type
empty_text_sensor::EmptyTextSensor *empty_text_sensor_emptytextsensor;
^
src/main.cpp: In function 'void setup()':
src/main.cpp:148:3: error: 'empty_text_sensor_emptytextsensor' was not declared in this scope
empty_text_sensor_emptytextsensor = new empty_text_sensor::EmptyTextSensor();
^
src/main.cpp:148:43: error: 'empty_text_sensor' does not name a type
empty_text_sensor_emptytextsensor = new empty_text_sensor::EmptyTextSensor();
To fix this problem, I added an __init__.py
file with nothing in it, leaving the text_sensor.py
as-is.
marekmarecki commented
Esphome Version: 2022.12.3
I had different error, but your solution helped nonetheless.
INFO Generating C++ source...
Traceback (most recent call last):
File "/path/esphome/venv/bin/esphome", line 8, in <module>
sys.exit(main())
File "/path/esphome/venv/lib/python3.10/site-packages/esphome/__main__.py", line 960, in main
return run_esphome(sys.argv)
File "/path/esphome/venv/lib/python3.10/site-packages/esphome/__main__.py", line 947, in run_esphome
rc = POST_CONFIG_ACTIONS[args.command](args, config)
File "/path/esphome/venv/lib/python3.10/site-packages/esphome/__main__.py", line 355, in command_compile
exit_code = write_cpp(config)
File "/path/esphome/venv/lib/python3.10/site-packages/esphome/__main__.py", line 177, in write_cpp
return write_cpp_file()
File "/path/esphome/venv/lib/python3.10/site-packages/esphome/__main__.py", line 195, in write_cpp_file
writer.write_cpp(code_s)
File "/path/esphome/venv/lib/python3.10/site-packages/esphome/writer.py", line 329, in write_cpp
copy_src_tree()
File "/path/esphome/venv/lib/python3.10/site-packages/esphome/writer.py", line 231, in copy_src_tree
source_files += component.resources
File "/path/esphome/venv/lib/python3.10/site-packages/esphome/loader.py", line 97, in resources
for resource in importlib.resources.contents(self.package):
File "/usr/lib/python3.10/importlib/resources.py", line 169, in contents
reader = _common.get_resource_reader(package)
File "/usr/lib/python3.10/importlib/_common.py", line 52, in get_resource_reader
return reader(spec.name) # type: ignore
File "<frozen importlib._bootstrap_external>", line 1321, in get_resource_reader
File "/usr/lib/python3.10/importlib/readers.py", line 111, in __init__
raise ValueError('Invalid path')
ValueError: Invalid path