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:
Franck Nijhof 2020-08-12 08:00:38 +02:00 committed by GitHub
parent 540d0e5428
commit 5f95b5caaf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 60 additions and 28 deletions

View File

@ -44,6 +44,7 @@ CONFIG_SCHEMA = vol.Schema(
DATA_INFO = "hassio_info"
DATA_HOST_INFO = "hassio_host_info"
DATA_CORE_INFO = "hassio_core_info"
HASSIO_UPDATE_INTERVAL = timedelta(minutes=55)
SERVICE_ADDON_START = "addon_start"
@ -140,18 +141,6 @@ async def async_get_addon_info(hass: HomeAssistantType, addon_id: str) -> dict:
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
@bind_hass
def get_info(hass):
@ -172,6 +161,16 @@ def get_host_info(hass):
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
@bind_hass
def is_hassio(hass):
@ -301,6 +300,7 @@ async def async_setup(hass, config):
try:
hass.data[DATA_INFO] = await hassio.get_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:
_LOGGER.warning("Can't read last version: %s", err)

View File

@ -82,6 +82,14 @@ class HassIO:
"""
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
def get_addon_info(self, addon):
"""Return data for a Add-on.

View File

@ -76,9 +76,10 @@ async def async_setup(hass, config):
if "dev" in current_version:
return Updater(False, "", "")
# Load data from supervisor on Hass.io
# Load data from Supervisor
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
update_available = False

View File

@ -92,6 +92,30 @@ async def test_api_host_info_error(hassio_handler, aioclient_mock):
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):
"""Test setup with API Home Assistant stop."""
aioclient_mock.post("http://127.0.0.1/homeassistant/stop", json={"result": "ok"})

View File

@ -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(
"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", {})
assert result
assert aioclient_mock.call_count == 6
assert hass.components.hassio.get_homeassistant_version() == "0.110.0"
assert aioclient_mock.call_count == 7
assert hass.components.hassio.get_core_info()["version_latest"] == "1.0.0"
assert hass.components.hassio.is_hassio()
@ -90,7 +94,7 @@ async def test_setup_api_push_api_data(hass, aioclient_mock):
)
assert result
assert aioclient_mock.call_count == 6
assert aioclient_mock.call_count == 7
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]["watchdog"]
@ -106,7 +110,7 @@ async def test_setup_api_push_api_data_server_host(hass, aioclient_mock):
)
assert result
assert aioclient_mock.call_count == 6
assert aioclient_mock.call_count == 7
assert not aioclient_mock.mock_calls[1][2]["ssl"]
assert aioclient_mock.mock_calls[1][2]["port"] == 9999
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": {}})
assert result
assert aioclient_mock.call_count == 6
assert aioclient_mock.call_count == 7
assert not aioclient_mock.mock_calls[1][2]["ssl"]
assert aioclient_mock.mock_calls[1][2]["port"] == 8123
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": {}})
assert result
assert aioclient_mock.call_count == 6
assert aioclient_mock.call_count == 7
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]["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": {}})
assert result
assert aioclient_mock.call_count == 6
assert aioclient_mock.call_count == 7
assert aioclient_mock.mock_calls[2][2]["timezone"] == "testzone"
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": {}})
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"

View File

@ -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."""
mock_get_uuid.return_value = MOCK_HUUID
mock_component(hass, "hassio")
hass.data["hassio_info"] = {"hassos": None, "homeassistant": "999.0"}
hass.data["hassio_host"] = {
"supervisor": "222",
"chassis": "vm",
"operating_system": "HassOS 4.6",
}
hass.data["hassio_core_info"] = {"version_latest": "999.0"}
assert await async_setup_component(hass, updater.DOMAIN, {updater.DOMAIN: {}})