Started getting an error:
2022-11-10 08:27:14.607 ERROR (MainThread) [homeassistant.config] Package covidsensors setup failed. Integration rest cannot be merged. Expected a dict. (See /config/packages/covidsensors.yaml:0).
This seems to be a result of this
home-assistant:dev
← epenet:fix-rest-init
opened 02:18PM - 07 Nov 22 UTC
## Proposed change
<!--
Describe the big picture of your changes here to com… municate to the
maintainers why we should accept this pull request. If it fixes a bug
or resolves a feature request, be sure to link to that issue in the
additional information section.
-->
Linked to #81551
In 2022.10, passing an empty configuration to `rest` resulted in a successful setup, with a failing coordinator and no sensors.
```yaml
rest:
```
In 2022.11, code was adjusted on the coordinator to ensure we had a valid resource before creating the dataclass, which resulted in a `HomeAssistantError`:
```python
raise HomeAssistantError("Resource not set for RestData")
```
The side effect of this change is that it highlited invalid configurations in the real world (previously throwing errors in logs, but probably ignored, now failing).
This PR adjusts the schema validation to ensure an empty dict first gets converted to an empty list rather than get converted to a list with a single dict
## Type of change
<!--
What type of change does your PR introduce to Home Assistant?
NOTE: Please, check only 1! box!
If your PR requires multiple boxes to be checked, you'll most likely need to
split it into multiple PRs. This makes things easier and faster to code review.
-->
- [ ] Dependency upgrade
- [x] Bugfix (non-breaking change which fixes an issue)
- [ ] New integration (thank you!)
- [ ] New feature (which adds functionality to an existing integration)
- [ ] Deprecation (breaking change to happen in the future)
- [ ] Breaking change (fix/feature causing existing functionality to break)
- [ ] Code quality improvements to existing code or addition of tests
## Additional information
<!--
Details are important, and help maintainers processing your PR.
Please be sure to fill out additional details, if applicable.
-->
- This PR fixes or closes issue: fixes #81551
- This PR is related to issue:
- Link to documentation pull request:
## Checklist
<!--
Put an `x` in the boxes that apply. You can also fill these out after
creating the PR. If you're unsure about any of them, don't hesitate to ask.
We're here to help! This is simply a reminder of what we are going to look
for before merging your code.
-->
- [x] The code change is tested and works locally.
- [x] Local tests pass. **Your PR cannot be merged unless tests pass**
- [x] There is no commented out code in this PR.
- [x] I have followed the [development checklist][dev-checklist]
- [x] The code has been formatted using Black (`black --fast homeassistant tests`)
- [x] Tests have been added to verify that the new code works.
If user exposed functionality or configuration variables are added/changed:
- [ ] Documentation added/updated for [www.home-assistant.io][docs-repository]
If the code communicates with devices, web services, or third-party tools:
- [ ] The [manifest file][manifest-docs] has all fields filled out correctly.
Updated and included derived files by running: `python3 -m script.hassfest`.
- [ ] New or updated dependencies have been added to `requirements_all.txt`.
Updated by running `python3 -m script.gen_requirements_all`.
- [ ] For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
- [ ] Untested files have been added to `.coveragerc`.
<!--
This project is very active and we have a high turnover of pull requests.
Unfortunately, the number of incoming pull requests is higher than what our
reviewers can review and merge so there is a long backlog of pull requests
waiting for review. You can help here!
By reviewing another pull request, you will help raise the code quality of
that pull request and the final review will be faster. This way the general
pace of pull request reviews will go up and your wait time will go down.
When picking a pull request to review, try to choose one that hasn't yet
been reviewed.
Thanks for helping out!
-->
To help with the load of incoming pull requests:
- [ ] I have reviewed two other [open pull requests][prs] in this repository.
[prs]: https://github.com/home-assistant/core/pulls?q=is%3Aopen+is%3Apr+-author%3A%40me+-draft%3Atrue+-label%3Awaiting-for-upstream+sort%3Acreated-desc+review%3Anone+-status%3Afailure
<!--
Thank you for contributing <3
Below, some useful links you could explore:
-->
[dev-checklist]: https://developers.home-assistant.io/docs/en/development_checklist.html
[manifest-docs]: https://developers.home-assistant.io/docs/en/creating_integration_manifest.html
[quality-scale]: https://developers.home-assistant.io/docs/en/next/integration_quality_scale_index.html
[docs-repository]: https://github.com/home-assistant/home-assistant.io
Adjust rest schema validation.
This is the yaml code
rest:
- scan_interval: 3600
resource: https://worldometer.herokuapp.com/api/coronavirus/world/
timeout: 60
sensor:
- name: Coronavirus Active Cases World
value_template: '{{ value_json.data["Active Cases"] }}'
unit_of_measurement: people
json_attributes:
- data
- name: Coronavirus Recovered Cases World
value_template: '{{ value_json.data["Total Recovered"] }}'
unit_of_measurement: people
- name: Coronavirus Confirmed Cases World
value_template: '{{ value_json.data["Total Cases"] }}'
unit_of_measurement: people
- name: Coronavirus Deaths World
value_template: '{{ value_json.data["Total Deaths"] }}'
unit_of_measurement: people
Why is this failing and how do fix it?
ianadd
(ian)
November 10, 2022, 1:35am
2
Same here, just decided to do a restart due to a small change to an unrelated entity.
Changed to 2022.11.2 last evening, so first restart since upgrade. Related ???
Yeah first restart for me too. I ended up restarting the container as a normal restart failed. Turns out there is an issue and a PR to fix this. There was a PR in 2022.11.2 that broke it. Just need to wait for the fix to be merged.
1 Like
hostrup
(Hostrup)
November 10, 2022, 7:31am
4
Hi!
My rest sensors (based on a utility-meter) also broke.
hopefully it will be fixed soon.
br Ronni
Do you have any reference to the issue that is causing this issue and needs to be fixed, please
(I’m really glad I found your post as I could just not see how to code up a rest: sensor with out getting the “Component rest cannot be merged. Expected a dict”
I’d like to track when its fixed and I can return to this work)
Fix is merged so should be in 2022.11.3 I think
Thankyou David
I’m 2022.11.2 so will await 2022.11.3 with interest. I do hope Rest: works as I hope as I’m doing something fairly complex with PUT, Bearer tokens and refresh intervals (as required by the API supplier)
2022.11.3 has been released
I count four fixes related to REST
I’d list them here but it’s too hard from an iPad.
Has anyone been able to test 2022.11.3
Does it fix the REST: sensor definition issues?
(I’m away and can’t do anything with HA till I get home, sorry)
Yes mine is working again after the update
hostrup
(Hostrup)
November 17, 2022, 7:30am
10
So is mine!
so one week without energy monitoring is finally over - and now i can see how expensive energy is again
1 Like