core: 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

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 2
  • Comments: 17 (12 by maintainers)

Most upvoted comments

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.

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]>