Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions homeassistant/components/hassio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@
)


DATA_INFO = "hassio_info"
DATA_HOST_INFO = "hassio_host_info"
DATA_CORE_INFO = "hassio_core_info"
DATA_HOST_INFO = "hassio_host_info"
DATA_INFO = "hassio_info"
DATA_OS_INFO = "hassio_os_info"
DATA_SUPERVISOR_INFO = "hassio_supervisor_info"
HASSIO_UPDATE_INTERVAL = timedelta(minutes=55)

SERVICE_ADDON_START = "addon_start"
Expand Down Expand Up @@ -218,6 +220,26 @@ def get_host_info(hass):
return hass.data.get(DATA_HOST_INFO)


@callback
@bind_hass
def get_supervisor_info(hass):
"""Return Supervisor information.

Async friendly.
"""
return hass.data.get(DATA_SUPERVISOR_INFO)


@callback
@bind_hass
def get_os_info(hass):
"""Return OS information.

Async friendly.
"""
return hass.data.get(DATA_OS_INFO)


@callback
@bind_hass
def get_core_info(hass):
Expand Down Expand Up @@ -358,6 +380,8 @@ async def update_info_data(now):
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()
hass.data[DATA_SUPERVISOR_INFO] = await hassio.get_supervisor_info()
hass.data[DATA_OS_INFO] = await hassio.get_os_info()
except HassioAPIError as err:
_LOGGER.warning("Can't read last version: %s", err)

Expand Down
16 changes: 16 additions & 0 deletions homeassistant/components/hassio/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ def get_host_info(self):
"""
return self.send_command("/host/info", method="get")

@api_data
def get_os_info(self):
"""Return data for the OS.

This method return a coroutine.
"""
return self.send_command("/os/info", method="get")

@api_data
def get_core_info(self):
"""Return data for Home Asssistant Core.
Expand All @@ -90,6 +98,14 @@ def get_core_info(self):
"""
return self.send_command("/core/info", method="get")

@api_data
def get_supervisor_info(self):
"""Return data for the Supervisor.

This method returns a coroutine.
"""
return self.send_command("/supervisor/info", method="get")

@api_data
def get_addon_info(self, addon):
"""Return data for a Add-on.
Expand Down
19 changes: 19 additions & 0 deletions homeassistant/components/hassio/strings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"title": "Home Assistant Supervisor",
"system_health": {
"info": {
"board": "Board",
"chassis": "Chassis",
"disk_free": "Disk free (GB)",
"disk_total": "Disk Total (GB)",
"disk_used": "Disk Used (GB)",
Comment thread
ludeeus marked this conversation as resolved.
Outdated
"docker_version": "Docker Version",
"healthy": "Healthy",
"host_os": "Host Operating System",
"installed_addons": "Installed Add-ons",
"supervisor_version": "Supervisor Version",
"supported": "Supported",
"update_channel": "Update Channel"
}
}
}
42 changes: 42 additions & 0 deletions homeassistant/components/hassio/system_health.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""Provide info to system health."""
Comment thread
ludeeus marked this conversation as resolved.
from homeassistant.components import system_health
from homeassistant.core import HomeAssistant, callback


@callback
def async_register(
hass: HomeAssistant, register: system_health.SystemHealthRegistration
) -> None:
"""Register system health callbacks."""
register.async_register_info(system_health_info, "/hassio")


async def system_health_info(hass: HomeAssistant):
"""Get info for the info page."""
info = hass.components.hassio.get_info()
host = hass.components.hassio.get_host_info()
os = hass.components.hassio.get_os_info()
supervisor = hass.components.hassio.get_supervisor_info()

information = {
"host_os": host.get("operating_system"),
"update_channel": info.get("channel"),
"supervisor_version": info.get("supervisor"),
"docker_version": info.get("docker"),
"chassis": host.get("chassis"),
"disk_free": host.get("disk_free"),
"disk_total": host.get("disk_total"),
"disk_used": host.get("disk_used"),
"healthy": supervisor.get("healthy"),
"supported": supervisor.get("supported"),
}

if info.get("hassos") is not None:
information["board"] = os.get("board")

information["installed_addons"] = ", ".join(
f"{addon['name']} ({addon['version']})"
for addon in supervisor.get("addons", [])
)

return information
20 changes: 18 additions & 2 deletions homeassistant/components/hassio/translations/en.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
{
"title": "Hass.io"
}
"title": "Home Assistant Supervisor",
"system_health": {
"info": {
"board": "Board",
"chassis": "Chassis",
"disk_free": "Disk free (GB)",
"disk_total": "Disk Total (GB)",
"disk_used": "Disk Used (GB)",
"docker_version": "Docker Version",
"healthy": "Healthy",
"host_os": "Host Operating System",
"installed_addons": "Installed Add-ons",
"supervisor_version": "Supervisor Version",
"supported": "Supported",
"update_channel": "Update Channel"
}
}
}
18 changes: 7 additions & 11 deletions homeassistant/components/homeassistant/strings.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
{
"system_health": {
"info": {
"installation_type": "Installation Type",
"version": "Version",
"arch": "CPU Architecture",
"dev": "Development",
"virtualenv": "Virtual Environment",
"python_version": "Python Version",
"docker": "Docker",
"arch": "CPU Architecture",
"timezone": "Timezone",
"os_name": "Operating System Name",
"installation_type": "Installation Type",
Comment thread
ludeeus marked this conversation as resolved.
"os_name": "Operating System Family",
"os_version": "Operating System Version",
"supervisor": "Supervisor",
"host_os": "Home Assistant OS",
"chassis": "Chassis",
"docker_version": "Docker"
"python_version": "Python Version",
"timezone": "Timezone",
"version": "Version",
"virtualenv": "Virtual Environment"
}
}
}
7 changes: 6 additions & 1 deletion homeassistant/components/homeassistant/system_health.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,10 @@ def async_register(
async def system_health_info(hass):
"""Get info for the info page."""
info = await system_info.async_get_system_info(hass)
info.pop("hassio")

# Moved to homeassistant/components/hassio/system_health.py
for key in ["hassio", "supervisor", "host_os", "chassis", "docker_version"]:
Comment thread
ludeeus marked this conversation as resolved.
Outdated
if key in info:
info.pop(key)
Comment thread
ludeeus marked this conversation as resolved.
Outdated

return info
36 changes: 16 additions & 20 deletions homeassistant/components/homeassistant/translations/en.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
{
"system_health": {
"info": {
"arch": "CPU Architecture",
"chassis": "Chassis",
"dev": "Development",
"docker": "Docker",
"docker_version": "Docker",
"host_os": "Home Assistant OS",
"installation_type": "Installation Type",
"os_name": "Operating System Name",
"os_version": "Operating System Version",
"python_version": "Python Version",
"supervisor": "Supervisor",
"timezone": "Timezone",
"version": "Version",
"virtualenv": "Virtual Environment"
}
},
"title": "Home Assistant"
}
"system_health": {
"info": {
"arch": "CPU Architecture",
"dev": "Development",
"docker": "Docker",
"installation_type": "Installation Type",
"os_name": "Operating System Family",
"os_version": "Operating System Version",
"python_version": "Python Version",
"timezone": "Timezone",
"version": "Version",
"virtualenv": "Virtual Environment"
}
},
"title": "Home Assistant"
}
33 changes: 33 additions & 0 deletions tests/components/hassio/test_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,39 @@ async def test_api_host_info(hassio_handler, aioclient_mock):
assert data["operating_system"] == "Debian GNU/Linux 10 (buster)"


async def test_api_supervisor_info(hassio_handler, aioclient_mock):
"""Test setup with API Supervisor info."""
aioclient_mock.get(
"http://127.0.0.1/supervisor/info",
json={
"result": "ok",
"data": {"supported": True, "version": "2020.11.1", "channel": "stable"},
},
)

data = await hassio_handler.get_supervisor_info()
assert aioclient_mock.call_count == 1
assert data["supported"]
assert data["version"] == "2020.11.1"
assert data["channel"] == "stable"


async def test_api_os_info(hassio_handler, aioclient_mock):
"""Test setup with API OS info."""
aioclient_mock.get(
"http://127.0.0.1/os/info",
json={
"result": "ok",
"data": {"board": "odroid-n2", "version": "2020.11.1"},
},
)

data = await hassio_handler.get_os_info()
assert aioclient_mock.call_count == 1
assert data["board"] == "odroid-n2"
assert data["version"] == "2020.11.1"


async def test_api_host_info_error(hassio_handler, aioclient_mock):
"""Test setup with API Home Assistant info error."""
aioclient_mock.get(
Expand Down
22 changes: 15 additions & 7 deletions tests/components/hassio/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ def mock_all(aioclient_mock):
"http://127.0.0.1/core/info",
json={"result": "ok", "data": {"version_latest": "1.0.0"}},
)
aioclient_mock.get(
"http://127.0.0.1/os/info",
json={"result": "ok", "data": {"version_latest": "1.0.0"}},
)
aioclient_mock.get(
"http://127.0.0.1/supervisor/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": {}}}
)
Expand All @@ -55,7 +63,7 @@ async def test_setup_api_ping(hass, aioclient_mock):
result = await async_setup_component(hass, "hassio", {})
assert result

assert aioclient_mock.call_count == 7
assert aioclient_mock.call_count == 9
assert hass.components.hassio.get_core_info()["version_latest"] == "1.0.0"
assert hass.components.hassio.is_hassio()

Expand Down Expand Up @@ -94,7 +102,7 @@ async def test_setup_api_push_api_data(hass, aioclient_mock):
)
assert result

assert aioclient_mock.call_count == 7
assert aioclient_mock.call_count == 9
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"]
Expand All @@ -110,7 +118,7 @@ async def test_setup_api_push_api_data_server_host(hass, aioclient_mock):
)
assert result

assert aioclient_mock.call_count == 7
assert aioclient_mock.call_count == 9
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"]
Expand All @@ -122,7 +130,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 == 7
assert aioclient_mock.call_count == 9
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"]
Expand Down Expand Up @@ -169,7 +177,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 == 7
assert aioclient_mock.call_count == 9
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
Expand All @@ -183,7 +191,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 == 7
assert aioclient_mock.call_count == 9
assert aioclient_mock.mock_calls[2][2]["timezone"] == "testzone"

with patch("homeassistant.util.dt.set_default_time_zone"):
Expand All @@ -200,7 +208,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 == 7
assert aioclient_mock.call_count == 9
assert aioclient_mock.mock_calls[-1][3]["X-Hassio-Key"] == "123456"


Expand Down