core
core copied to clipboard
Sensor.Rest not able to start after 2022.11.1
The problem
I have a rest sensor that was working before 2022.11.1, and now it isn't able to start anymore. Error returned is: homeassistant.exceptions.HomeAssistantError: Resource not set for RestData
I tried moving the rest sensor from the "sensor" list to the "rest" section, but I have different problem there. Probably a regression caused by the latest update.
What version of Home Assistant Core has the issue?
core-2022.11.1
What was the last working version of Home Assistant Core?
core-2022.10.5
What type of installation are you running?
Home Assistant OS
Integration causing the issue
Rest
Link to integration documentation on our website
https://www.home-assistant.io/integrations/sensor.rest/
Diagnostics information
No response
Example YAML snippet
- platform: rest
resource_template: 'http://192.168.1.70/v1/feeds/ser4:141369-3N40-2417/'
name: Rest ABB
headers:
Authorization: >
X-Digest username=...
json_attributes_path: "$.feeds.ser4:141369-3N40-2417.datastreams"
json_attributes:
- "m64061_1_DayWH"
- "m101_1_WH"
- "m101_1_W"
- "m101_1_PowerPeakToday"
value_template: "OK"
scan_interval: 1800
Anything in the logs that might be useful for us?
No response
Additional information
No response
I can confirm this, using resource: instead of resource_template: didn't make a difference.
I was resolving the resource with a !secret, but it seems like that isn't the culprit here.
This also effects binary_sensors,
Another user has reported multiple restarts have "fixed" the issue.
Moving the sensors to rest: instead of sensor: worked for me, however I didn't change anything about the sensors config itself, but just migrated it to the other configuration scheme.
Oh yes, I tried with the resource_template but before it was resource. I tried to have a look at the source files, I found where the exception is raised, but I didn't find any major changes in the last days that can explain this behavior. It looks like the configuration that the component is getting is empty, at least for the resource part.
Hey @epenet I saw you made some changes to the rest integration, can you have a look at this? Seems like rest sensor is no longer working if placed in the sensor list.
The exception was introduced here: https://github.com/home-assistant/core/pull/80546
https://github.com/home-assistant/core/commit/a70f9b8995fc65d6009c96c5a974576c09e521b2#diff-3239db1c89487f92194be74da0cff7d7829fc5e2fff0721d56545b0fe4e2f968R186
But the check looks correct.
The check looks correct, instead I don’t get the change at line 169, why it has been changed?
Looks right to me,.if we are looking at the same thing. It adds typing to the return value.
Ps. Issue could be older than this change, only that it became an error here.
I was referring at the line where the variable resource is filled (I’m writing from my phone, it’s hard to copy code from here).
I agree that can be something old that cause issue now, but I don’t get why others doesn’t have my same problem (at least non that many), since I’m not doing anything strange.
I don’t have a test environment where I can debug this, anyone can do that?
I think this line is the culprit when the corresponding file is empty:
rest: !include rest.yaml
I have no rest entities (in binary_sensors or sensors or rest). With the above line in the config, I get the error. If I comment it out and restart, the error does not reappear. If I put it back in and restart, the error is back.
I think other people that are moving rest sensors from "sensors.yaml" to "rest.yaml" are 'incidentally' fixing the problem by making the file non-empty, whereas before it was empty and causing the error.
That makes sense, this file was empty on my installation as well until I put in all the new sensors. Good catch!
That makes sense. Maybe we should log and skip instead of raising error.
I'll check it this week unless someone beats me to it
Good catch @michaelblight! I'm in the same situation, with an empty rest.yaml file, and rest sensor added in the sensor.yaml.
@epenet I think that this could be solved at platform level, not integration: if an integration has an empty file, simply do not invoke any constructor. What do you think?
I was having this ever since upgrading to 2022.11.1
In my case, I did have a rest sensor at one time, but no longer. I use the configuration.yaml approach where it pulls in folders for config. I had the following in my configuration.yaml
rest: !include_dir_merge_list rest
Since I don't have any sensors now, my rest folder is empty. I commented this line out and restarted and can confirm the error notification no longer occurs. Just thought I'd throw this here in case it helps in any way. :)
I was able to reproduce the issue, by simply setting an empty config:
rest:
During the validation of the schema, this gets loaded as an empty dict {}, which gets converted by voluptuous into a list with a minimalist schema:
[
{
'verify_ssl': True,
'timeout': 10,
'method': 'GET'
}
]
As far as I can tell, in 2022.10.5 the component loads and then logs errors:
2022-11-07 13:29:53.427 INFO SyncWorker_0 homeassistant.loader:loader.py:537 Loaded rest from homeassistant.components.rest
2022-11-07 13:29:53.428 INFO MainThread homeassistant.setup:setup.py:204 Setting up rest
2022-11-07 13:29:53.428 DEBUG MainThread homeassistant.core:core.py:907 Bus:Handling <Event service_registered[L]: domain=rest, service=reload>
2022-11-07 13:29:53.433 DEBUG MainThread homeassistant.components.rest.data:data.py:58 Updating from None
2022-11-07 13:29:53.433 ERROR MainThread homeassistant.components.rest:update_coordinator.py:263 Unexpected error fetching rest data data: Invalid type for url. Expected str or httpx.URL, got <class 'NoneType'>: None
Traceback (most recent call last):
File "/workspaces/home-assistant-core/homeassistant/helpers/update_coordinator.py", line 205, in _async_refresh
self.data = await self._async_update_data()
File "/workspaces/home-assistant-core/homeassistant/helpers/update_coordinator.py", line 164, in _async_update_data
return await self.update_method()
File "/workspaces/home-assistant-core/homeassistant/components/rest/data.py", line 60, in async_update
response = await self._async_client.request(
File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 1514, in request
request = self.build_request(
File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 344, in build_request
url = self._merge_url(url)
File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 374, in _merge_url
merge_url = URL(url)
File "/usr/local/lib/python3.9/site-packages/httpx/_urls.py", line 102, in __init__
raise TypeError(
TypeError: Invalid type for url. Expected str or httpx.URL, got <class 'NoneType'>: None
2022-11-07 13:29:53.435 DEBUG MainThread homeassistant.components.rest:update_coordinator.py:274 Finished fetching rest data data in 0.007 seconds (success: False)
2022-11-07 13:29:53.435 INFO MainThread homeassistant.setup:setup.py:252 Setup of domain rest took 0.0 seconds
2022-11-07 13:29:53.435 DEBUG MainThread homeassistant.core:core.py:907 Bus:Handling <Event component_loaded[L]: component=rest>
In 2022.11, the error is slightly earlier, preventing the setup from completing:
2022-11-07 13:37:46.710 INFO SyncWorker_0 homeassistant.loader:loader.py:543 Loaded rest from homeassistant.components.rest
2022-11-07 13:37:46.711 INFO MainThread homeassistant.setup:setup.py:204 Setting up rest
2022-11-07 13:37:46.711 DEBUG MainThread homeassistant.core:core.py:913 Bus:Handling <Event service_registered[L]: domain=rest, service=reload>
2022-11-07 13:37:46.711 ERROR MainThread homeassistant.setup:setup.py:245 Error during setup of component rest
Traceback (most recent call last):
File "/workspaces/home-assistant-core/homeassistant/setup.py", line 235, in _async_setup_component
result = await task
File "/workspaces/home-assistant-core/homeassistant/components/rest/__init__.py", line 77, in async_setup
return await _async_process_config(hass, config)
File "/workspaces/home-assistant-core/homeassistant/components/rest/__init__.py", line 97, in _async_process_config
rest = create_rest_data_from_config(hass, conf)
File "/workspaces/home-assistant-core/homeassistant/components/rest/__init__.py", line 185, in create_rest_data_from_config
raise HomeAssistantError("Resource not set for RestData")
homeassistant.exceptions.HomeAssistantError: Resource not set for RestData
2022-11-07 13:37:46.712 DEBUG MainThread homeassistant.core:core.py:913 Bus:Handling <Event state_changed[L]: entity_id=persistent_notification.invalid_config, old_state=None, new_state=<state persistent_notification.invalid_config=notifying; message=The following integrations and platforms could not be set up:
- [rest](https://www.home-assistant.io/integrations/rest) ([Show logs](/config/logs?filter=rest))
Please check your config and [logs](/config/logs)., title=Invalid config, friendly_name=Invalid config @ 2022-11-07T05:37:46.712331-08:00>>
2022-11-07 13:37:46.712 DEBUG MainThread homeassistant.core:core.py:913 Bus:Handling <Event persistent_notifications_updated[L]>
I am unsure of how this should be fixed. Ultimately the YAML config is wrong...
My current opinion is that it should be rejected by the schema validation even earlier.
Yeah I agree, or rejected by the schema validation (and that should be valid for every component, like "empty configuration is not allowed"), or managed in a different way (like "if a component has an empty configuration, skip it").
I have opened a PR #81723, but I'm very unsure about the best way to resolved this. I think that maybe users simply need to fix their configuration...