diff --git a/homeassistant/components/hassio/__init__.py b/homeassistant/components/hassio/__init__.py index b65bea04e2a6..b38caf53c336 100644 --- a/homeassistant/components/hassio/__init__.py +++ b/homeassistant/components/hassio/__init__.py @@ -1,12 +1,10 @@ """Support for Hass.io.""" import asyncio -from dataclasses import replace from functools import partial import logging import os import struct -from typing import Any from aiohasupervisor import SupervisorBadRequestError, SupervisorError from aiohasupervisor.models import ( @@ -20,19 +18,9 @@ from homeassistant.auth.const import GROUP_ID_ADMIN from homeassistant.auth.models import RefreshToken, User from homeassistant.components import frontend from homeassistant.components.homeassistant import async_set_stop_handler -from homeassistant.components.http import ( - CONF_SERVER_HOST, - CONF_SERVER_PORT, - CONF_SSL_CERTIFICATE, -) from homeassistant.components.onboarding import async_is_onboarded from homeassistant.config_entries import SOURCE_SYSTEM, ConfigEntry -from homeassistant.const import ( - EVENT_CORE_CONFIG_UPDATE, - HASSIO_USER_NAME, - SERVER_PORT, - Platform, -) +from homeassistant.const import EVENT_CORE_CONFIG_UPDATE, HASSIO_USER_NAME, Platform from homeassistant.core import Event, HomeAssistant, callback from homeassistant.exceptions import ConfigEntryNotReady from homeassistant.helpers import ( @@ -69,7 +57,6 @@ from .const import ( DATA_COMPONENT, DATA_CONFIG_STORE, DATA_HASSIO_HOST, - DATA_HASSIO_HTTP_CONFIG, DATA_HASSIO_SUPERVISOR_USER, DATA_KEY_SUPERVISOR_ISSUES, DOMAIN, @@ -246,7 +233,6 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: websession = async_get_clientsession(hass) hass.data[DATA_COMPONENT] = HassIO(hass.loop, websession, host) hass.data[DATA_HASSIO_HOST] = host - hass.data[DATA_HASSIO_HTTP_CONFIG] = config.get("http", {}) # Load the store config_store = HassioConfig(hass) @@ -399,23 +385,17 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: entry.async_on_unload(hass.bus.async_listen(EVENT_CORE_CONFIG_UPDATE, push_config)) - http_config: dict[str, Any] = hass.data.get(DATA_HASSIO_HTTP_CONFIG, {}) - async def update_hass_api(refresh_token: RefreshToken) -> None: """Update Home Assistant API data on Hass.io.""" + # hass.config.api is always set here: hassio depends on http, and the + # http integration assigns hass.config.api during its async_setup. + assert hass.config.api is not None options = HomeAssistantOptions( - ssl=CONF_SSL_CERTIFICATE in http_config, - port=http_config.get(CONF_SERVER_PORT) or SERVER_PORT, + ssl=hass.config.api.use_ssl, + port=hass.config.api.port, refresh_token=refresh_token.token, ) - if http_config.get(CONF_SERVER_HOST) is not None: - options = replace(options, watchdog=False) - _LOGGER.warning( - "Found incompatible HTTP option 'server_host'. Watchdog feature" - " disabled" - ) - try: await supervisor_client.homeassistant.set_options(options) except SupervisorError as err: diff --git a/homeassistant/components/hassio/const.py b/homeassistant/components/hassio/const.py index c1ece85104ef..418f956c46c2 100644 --- a/homeassistant/components/hassio/const.py +++ b/homeassistant/components/hassio/const.py @@ -2,7 +2,7 @@ from datetime import timedelta from enum import StrEnum -from typing import TYPE_CHECKING, Any +from typing import TYPE_CHECKING from homeassistant.util.hass_dict import HassKey @@ -145,7 +145,6 @@ DATA_KEY_CORE = "core" DATA_KEY_HOST = "host" DATA_KEY_SUPERVISOR_ISSUES: HassKey[SupervisorIssues] = HassKey("supervisor_issues") DATA_KEY_MOUNTS = "mounts" -DATA_HASSIO_HTTP_CONFIG: HassKey[dict[str, Any]] = HassKey("hassio_http_config") DATA_HASSIO_HOST: HassKey[str] = HassKey("hassio_host") DATA_HASSIO_SUPERVISOR_USER: HassKey[User] = HassKey("hassio_supervisor_user") diff --git a/tests/components/hassio/test_init.py b/tests/components/hassio/test_init.py index 281ebd9fe8b9..1ce13995a339 100644 --- a/tests/components/hassio/test_init.py +++ b/tests/components/hassio/test_init.py @@ -308,7 +308,11 @@ async def test_setup_api_push_api_data_error( async def test_setup_api_push_api_data_server_host( hass: HomeAssistant, supervisor_client: AsyncMock ) -> None: - """Test setup with API push with active server host.""" + """Test setup with API push with active server host. + + A configured server_host no longer disables the watchdog: Supervisor + reaches Core over the Unix socket, independent of the HTTP bind address. + """ with patch.dict(os.environ, MOCK_ENVIRON): result = await async_setup_component( hass, @@ -320,7 +324,7 @@ async def test_setup_api_push_api_data_server_host( assert result assert len(supervisor_client.mock_calls) == 16 supervisor_client.homeassistant.set_options.assert_called_once_with( - HomeAssistantOptions(ssl=False, port=9999, refresh_token=ANY, watchdog=False) + HomeAssistantOptions(ssl=False, port=9999, refresh_token=ANY) )