script.scaffold broke for fresh installations due to hassfest failure
thargy opened this issue · 0 comments
The problem
When running python3 -m script.scaffold integration
on a fresh devcontainer, as per the instructions for creating an integration, the following error occurs:
...
Running hassfest to pick up new information.
Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "/workspaces/home-assistant-core/script/scaffold/__main__.py", line 117, in <module>
sys.exit(main())
^^^^^^
File "/workspaces/home-assistant-core/script/scaffold/__main__.py", line 70, in main
subprocess.run(["python", "-m", "script.hassfest"], **pipe_null, check=True)
File "/usr/local/lib/python3.12/subprocess.py", line 571, in run
raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['python', '-m', 'script.hassfest']' returned non-zero exit status 1.
Running python -m script.hassfest
directly gives the following error:
...
Found errors. Generating files canceled.
Integration example_domain:
* [ERROR] [TRANSLATIONS] strings.json::options::step::init::data::entity_id contains invalid reference component::NEW_DOMAIN::config::step::user::description: Could not find NEW_DOMAIN
A search of the newly generated custom_component shows that strings.json
contains the following:
{
"config": {
"step": {
"user": {
"description": "New NEW_NAME Sensor",
"data": {
"entity_id": "Input sensor",
"name": "Name"
}
}
}
},
"options": {
"step": {
"init": {
"data": {
"entity_id": "[%key:component::NEW_DOMAIN::config::step::user::description%]"
}
}
}
}
}
Replacing NEW_DOMAIN
with the correct domain (example_domain
here) allows hassfest
to pass using python -m script.hassfest
.
You can then build translations using:
python -m script.translations develop --integration example_domain
However, 2 of the scaffolded tests also fail:
$ python3 -b -m pytest -vvv tests/components/example_domain
...
# Check the entity was updated, no new entity was created
> assert len(hass.states.async_all()) == 1
E assert 0 == 1
E + where 0 = len([])
E + where [] = async_all()
E + where async_all = <homeassistant.core.StateMachine object at 0x7f85dd87bb50>.async_all
E + where <homeassistant.core.StateMachine object at 0x7f85dd87bb50> = <HomeAssistant RUNNING>.states
tests/components/example_domain/test_config_flow.py:113: AssertionError
...
# TODO Check the state of the entity has changed as expected
assert state.state == "unknown"
> assert state.attributes == {}
E AssertionError: assert {'friendly_name': 'My example_domain'} == {}
E
E Left contains 1 more item:
E {'friendly_name': 'My example_domain'}
E
E Full diff:
E - {}
E + {
E + 'friendly_name': 'My example_domain',
E + }
tests/components/example_domain/test_init.py:43: AssertionError
The first failure requires more investigation as hass.states
contains 0 states.
The latter seems to be due to not expecting the automatically added 'friendly_name' attribute and can be easily fixed.
What version of Home Assistant Core has the issue?
core-2024.11.0.dev0
What was the last working version of Home Assistant Core?
No response
What type of installation are you running?
Home Assistant Core
Integration causing the issue
No response
Link to integration documentation on our website
No response
Diagnostics information
No response
Example YAML snippet
No response
Anything in the logs that might be useful for us?
No response
Additional information
No response