mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 01:37:08 +00:00
Fix lastest version in updater for Supervisor enabled installs (#38773)
* Fix lastest version in update for Supervisor enabled installs * Fix updater tests
This commit is contained in:
parent
540d0e5428
commit
5f95b5caaf
@ -44,6 +44,7 @@ CONFIG_SCHEMA = vol.Schema(
|
|||||||
|
|
||||||
DATA_INFO = "hassio_info"
|
DATA_INFO = "hassio_info"
|
||||||
DATA_HOST_INFO = "hassio_host_info"
|
DATA_HOST_INFO = "hassio_host_info"
|
||||||
|
DATA_CORE_INFO = "hassio_core_info"
|
||||||
HASSIO_UPDATE_INTERVAL = timedelta(minutes=55)
|
HASSIO_UPDATE_INTERVAL = timedelta(minutes=55)
|
||||||
|
|
||||||
SERVICE_ADDON_START = "addon_start"
|
SERVICE_ADDON_START = "addon_start"
|
||||||
@ -140,18 +141,6 @@ async def async_get_addon_info(hass: HomeAssistantType, addon_id: str) -> dict:
|
|||||||
return result["data"]
|
return result["data"]
|
||||||
|
|
||||||
|
|
||||||
@callback
|
|
||||||
@bind_hass
|
|
||||||
def get_homeassistant_version(hass):
|
|
||||||
"""Return latest available Home Assistant version.
|
|
||||||
|
|
||||||
Async friendly.
|
|
||||||
"""
|
|
||||||
if DATA_INFO not in hass.data:
|
|
||||||
return None
|
|
||||||
return hass.data[DATA_INFO].get("homeassistant")
|
|
||||||
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
@bind_hass
|
@bind_hass
|
||||||
def get_info(hass):
|
def get_info(hass):
|
||||||
@ -172,6 +161,16 @@ def get_host_info(hass):
|
|||||||
return hass.data.get(DATA_HOST_INFO)
|
return hass.data.get(DATA_HOST_INFO)
|
||||||
|
|
||||||
|
|
||||||
|
@callback
|
||||||
|
@bind_hass
|
||||||
|
def get_core_info(hass):
|
||||||
|
"""Return Home Assistant Core information from Supervisor.
|
||||||
|
|
||||||
|
Async friendly.
|
||||||
|
"""
|
||||||
|
return hass.data.get(DATA_CORE_INFO)
|
||||||
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
@bind_hass
|
@bind_hass
|
||||||
def is_hassio(hass):
|
def is_hassio(hass):
|
||||||
@ -301,6 +300,7 @@ async def async_setup(hass, config):
|
|||||||
try:
|
try:
|
||||||
hass.data[DATA_INFO] = await hassio.get_info()
|
hass.data[DATA_INFO] = await hassio.get_info()
|
||||||
hass.data[DATA_HOST_INFO] = await hassio.get_host_info()
|
hass.data[DATA_HOST_INFO] = await hassio.get_host_info()
|
||||||
|
hass.data[DATA_CORE_INFO] = await hassio.get_core_info()
|
||||||
except HassioAPIError as err:
|
except HassioAPIError as err:
|
||||||
_LOGGER.warning("Can't read last version: %s", err)
|
_LOGGER.warning("Can't read last version: %s", err)
|
||||||
|
|
||||||
|
@ -82,6 +82,14 @@ class HassIO:
|
|||||||
"""
|
"""
|
||||||
return self.send_command("/host/info", method="get")
|
return self.send_command("/host/info", method="get")
|
||||||
|
|
||||||
|
@_api_data
|
||||||
|
def get_core_info(self):
|
||||||
|
"""Return data for Home Asssistant Core.
|
||||||
|
|
||||||
|
This method returns a coroutine.
|
||||||
|
"""
|
||||||
|
return self.send_command("/core/info", method="get")
|
||||||
|
|
||||||
@_api_data
|
@_api_data
|
||||||
def get_addon_info(self, addon):
|
def get_addon_info(self, addon):
|
||||||
"""Return data for a Add-on.
|
"""Return data for a Add-on.
|
||||||
|
@ -76,9 +76,10 @@ async def async_setup(hass, config):
|
|||||||
if "dev" in current_version:
|
if "dev" in current_version:
|
||||||
return Updater(False, "", "")
|
return Updater(False, "", "")
|
||||||
|
|
||||||
# Load data from supervisor on Hass.io
|
# Load data from Supervisor
|
||||||
if hass.components.hassio.is_hassio():
|
if hass.components.hassio.is_hassio():
|
||||||
newest = hass.components.hassio.get_homeassistant_version()
|
core_info = hass.components.hassio.get_core_info()
|
||||||
|
newest = core_info["version_latest"]
|
||||||
|
|
||||||
# Validate version
|
# Validate version
|
||||||
update_available = False
|
update_available = False
|
||||||
|
@ -92,6 +92,30 @@ async def test_api_host_info_error(hassio_handler, aioclient_mock):
|
|||||||
assert aioclient_mock.call_count == 1
|
assert aioclient_mock.call_count == 1
|
||||||
|
|
||||||
|
|
||||||
|
async def test_api_core_info(hassio_handler, aioclient_mock):
|
||||||
|
"""Test setup with API Home Assistant Core info."""
|
||||||
|
aioclient_mock.get(
|
||||||
|
"http://127.0.0.1/core/info",
|
||||||
|
json={"result": "ok", "data": {"version_latest": "1.0.0"}},
|
||||||
|
)
|
||||||
|
|
||||||
|
data = await hassio_handler.get_core_info()
|
||||||
|
assert aioclient_mock.call_count == 1
|
||||||
|
assert data["version_latest"] == "1.0.0"
|
||||||
|
|
||||||
|
|
||||||
|
async def test_api_core_info_error(hassio_handler, aioclient_mock):
|
||||||
|
"""Test setup with API Home Assistant Core info error."""
|
||||||
|
aioclient_mock.get(
|
||||||
|
"http://127.0.0.1/core/info", json={"result": "error", "message": None}
|
||||||
|
)
|
||||||
|
|
||||||
|
with pytest.raises(HassioAPIError):
|
||||||
|
await hassio_handler.get_core_info()
|
||||||
|
|
||||||
|
assert aioclient_mock.call_count == 1
|
||||||
|
|
||||||
|
|
||||||
async def test_api_homeassistant_stop(hassio_handler, aioclient_mock):
|
async def test_api_homeassistant_stop(hassio_handler, aioclient_mock):
|
||||||
"""Test setup with API Home Assistant stop."""
|
"""Test setup with API Home Assistant stop."""
|
||||||
aioclient_mock.post("http://127.0.0.1/homeassistant/stop", json={"result": "ok"})
|
aioclient_mock.post("http://127.0.0.1/homeassistant/stop", json={"result": "ok"})
|
||||||
|
@ -40,6 +40,10 @@ def mock_all(aioclient_mock):
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
aioclient_mock.get(
|
||||||
|
"http://127.0.0.1/core/info",
|
||||||
|
json={"result": "ok", "data": {"version_latest": "1.0.0"}},
|
||||||
|
)
|
||||||
aioclient_mock.get(
|
aioclient_mock.get(
|
||||||
"http://127.0.0.1/ingress/panels", json={"result": "ok", "data": {"panels": {}}}
|
"http://127.0.0.1/ingress/panels", json={"result": "ok", "data": {"panels": {}}}
|
||||||
)
|
)
|
||||||
@ -51,8 +55,8 @@ async def test_setup_api_ping(hass, aioclient_mock):
|
|||||||
result = await async_setup_component(hass, "hassio", {})
|
result = await async_setup_component(hass, "hassio", {})
|
||||||
assert result
|
assert result
|
||||||
|
|
||||||
assert aioclient_mock.call_count == 6
|
assert aioclient_mock.call_count == 7
|
||||||
assert hass.components.hassio.get_homeassistant_version() == "0.110.0"
|
assert hass.components.hassio.get_core_info()["version_latest"] == "1.0.0"
|
||||||
assert hass.components.hassio.is_hassio()
|
assert hass.components.hassio.is_hassio()
|
||||||
|
|
||||||
|
|
||||||
@ -90,7 +94,7 @@ async def test_setup_api_push_api_data(hass, aioclient_mock):
|
|||||||
)
|
)
|
||||||
assert result
|
assert result
|
||||||
|
|
||||||
assert aioclient_mock.call_count == 6
|
assert aioclient_mock.call_count == 7
|
||||||
assert not aioclient_mock.mock_calls[1][2]["ssl"]
|
assert not aioclient_mock.mock_calls[1][2]["ssl"]
|
||||||
assert aioclient_mock.mock_calls[1][2]["port"] == 9999
|
assert aioclient_mock.mock_calls[1][2]["port"] == 9999
|
||||||
assert aioclient_mock.mock_calls[1][2]["watchdog"]
|
assert aioclient_mock.mock_calls[1][2]["watchdog"]
|
||||||
@ -106,7 +110,7 @@ async def test_setup_api_push_api_data_server_host(hass, aioclient_mock):
|
|||||||
)
|
)
|
||||||
assert result
|
assert result
|
||||||
|
|
||||||
assert aioclient_mock.call_count == 6
|
assert aioclient_mock.call_count == 7
|
||||||
assert not aioclient_mock.mock_calls[1][2]["ssl"]
|
assert not aioclient_mock.mock_calls[1][2]["ssl"]
|
||||||
assert aioclient_mock.mock_calls[1][2]["port"] == 9999
|
assert aioclient_mock.mock_calls[1][2]["port"] == 9999
|
||||||
assert not aioclient_mock.mock_calls[1][2]["watchdog"]
|
assert not aioclient_mock.mock_calls[1][2]["watchdog"]
|
||||||
@ -118,7 +122,7 @@ async def test_setup_api_push_api_data_default(hass, aioclient_mock, hass_storag
|
|||||||
result = await async_setup_component(hass, "hassio", {"http": {}, "hassio": {}})
|
result = await async_setup_component(hass, "hassio", {"http": {}, "hassio": {}})
|
||||||
assert result
|
assert result
|
||||||
|
|
||||||
assert aioclient_mock.call_count == 6
|
assert aioclient_mock.call_count == 7
|
||||||
assert not aioclient_mock.mock_calls[1][2]["ssl"]
|
assert not aioclient_mock.mock_calls[1][2]["ssl"]
|
||||||
assert aioclient_mock.mock_calls[1][2]["port"] == 8123
|
assert aioclient_mock.mock_calls[1][2]["port"] == 8123
|
||||||
refresh_token = aioclient_mock.mock_calls[1][2]["refresh_token"]
|
refresh_token = aioclient_mock.mock_calls[1][2]["refresh_token"]
|
||||||
@ -165,7 +169,7 @@ async def test_setup_api_existing_hassio_user(hass, aioclient_mock, hass_storage
|
|||||||
result = await async_setup_component(hass, "hassio", {"http": {}, "hassio": {}})
|
result = await async_setup_component(hass, "hassio", {"http": {}, "hassio": {}})
|
||||||
assert result
|
assert result
|
||||||
|
|
||||||
assert aioclient_mock.call_count == 6
|
assert aioclient_mock.call_count == 7
|
||||||
assert not aioclient_mock.mock_calls[1][2]["ssl"]
|
assert not aioclient_mock.mock_calls[1][2]["ssl"]
|
||||||
assert aioclient_mock.mock_calls[1][2]["port"] == 8123
|
assert aioclient_mock.mock_calls[1][2]["port"] == 8123
|
||||||
assert aioclient_mock.mock_calls[1][2]["refresh_token"] == token.token
|
assert aioclient_mock.mock_calls[1][2]["refresh_token"] == token.token
|
||||||
@ -179,7 +183,7 @@ async def test_setup_core_push_timezone(hass, aioclient_mock):
|
|||||||
result = await async_setup_component(hass, "hassio", {"hassio": {}})
|
result = await async_setup_component(hass, "hassio", {"hassio": {}})
|
||||||
assert result
|
assert result
|
||||||
|
|
||||||
assert aioclient_mock.call_count == 6
|
assert aioclient_mock.call_count == 7
|
||||||
assert aioclient_mock.mock_calls[2][2]["timezone"] == "testzone"
|
assert aioclient_mock.mock_calls[2][2]["timezone"] == "testzone"
|
||||||
|
|
||||||
await hass.config.async_update(time_zone="America/New_York")
|
await hass.config.async_update(time_zone="America/New_York")
|
||||||
@ -195,7 +199,7 @@ async def test_setup_hassio_no_additional_data(hass, aioclient_mock):
|
|||||||
result = await async_setup_component(hass, "hassio", {"hassio": {}})
|
result = await async_setup_component(hass, "hassio", {"hassio": {}})
|
||||||
assert result
|
assert result
|
||||||
|
|
||||||
assert aioclient_mock.call_count == 6
|
assert aioclient_mock.call_count == 7
|
||||||
assert aioclient_mock.mock_calls[-1][3]["X-Hassio-Key"] == "123456"
|
assert aioclient_mock.mock_calls[-1][3]["X-Hassio-Key"] == "123456"
|
||||||
|
|
||||||
|
|
||||||
|
@ -154,12 +154,7 @@ async def test_new_version_shows_entity_after_hour_hassio(
|
|||||||
"""Test if binary sensor gets updated if new version is available / Hass.io."""
|
"""Test if binary sensor gets updated if new version is available / Hass.io."""
|
||||||
mock_get_uuid.return_value = MOCK_HUUID
|
mock_get_uuid.return_value = MOCK_HUUID
|
||||||
mock_component(hass, "hassio")
|
mock_component(hass, "hassio")
|
||||||
hass.data["hassio_info"] = {"hassos": None, "homeassistant": "999.0"}
|
hass.data["hassio_core_info"] = {"version_latest": "999.0"}
|
||||||
hass.data["hassio_host"] = {
|
|
||||||
"supervisor": "222",
|
|
||||||
"chassis": "vm",
|
|
||||||
"operating_system": "HassOS 4.6",
|
|
||||||
}
|
|
||||||
|
|
||||||
assert await async_setup_component(hass, updater.DOMAIN, {updater.DOMAIN: {}})
|
assert await async_setup_component(hass, updater.DOMAIN, {updater.DOMAIN: {}})
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user