Fix HAVCS Failing to Start on the Latest Home Assistant: AttributeError: 'ApiConfig' object has no attribute 'base_url'
Do Not Upgrade HA Too Frequently [Updated May 15, 2021]
I strongly do not recommend upgrading to core-2021.3.1 and later, including core-2021.5.3
From core-2021.3.1 onward there are some strange bugs. The version that is currently stable for the author is still core-2021.2.3
Problem Description
After the author upgraded Home Assistant to the latest version, HAVCS could no longer start normally.
Home Assistantversion that can runHAVCSnormally: core-2021.2.3Home Assistantversion that cannot runHAVCS: core-2021.5.3
Checking the Home Assistant logs showed this error:
AttributeError: 'ApiConfig' object has no attribute 'base_url'
The full error message is:
Logger: homeassistant.config_entries
Source: custom_components/havcs/__init__.py:250
Integration: Home Assistant Voice Control Skill (documentation)
First occurred: 18:05:49 (1 occurrences)
Last logged: 18:05:49
Error setting up entry 主配置[configuration.yml] for havcs
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/config_entries.py", line 269, in async_setup
result = await component.async_setup_entry(hass, self) # type: ignore
File "/config/custom_components/havcs/__init__.py", line 250, in async_setup_entry
http_manager = hass.data[DOMAIN][DATA_HAVCS_HTTP_MANAGER] = HavcsHttpManager(hass, conf.get(CONF_HTTP, {}).get(CONF_HA_URL, hass.config.api.base_url), DEVICE_CONFIG_SCHEMA)
AttributeError: 'ApiConfig' object has no attribute 'base_url'
Issue Investigation
After checking the related资料 and docs, I found that Home Assistant has already deprecated config.api.base_url. It should be replaced with the new helpers.network.get_url.
Fix
Use File Editor to open /config/custom_components/havcs/__init__.py, replace every config.api.base_url with helpers.network.get_url, then restart Home Assistant.
References
https://github.com/elupus/hass_nibe/issues/72 https://developers.home-assistant.io/blog/2020/05/08/instance-url-helper/