Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion homeassistant/components/hassio/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"domain": "hassio",
"name": "Hass.io",
"name": "Home Assistant Supervisor",
"documentation": "https://www.home-assistant.io/hassio",
"dependencies": ["http"],
"after_dependencies": ["panel_custom"],
Expand Down
18 changes: 18 additions & 0 deletions homeassistant/components/hassio/strings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"system_health": {
"info": {
"board": "Board",
"disk_total": "Disk Total",
"disk_used": "Disk Used",
"docker_version": "Docker Version",
"healthy": "Healthy",
"host_os": "Host Operating System",
"installed_addons": "Installed Add-ons",
"supervisor_api": "Supervisor API",
"supervisor_version": "Supervisor Version",
"supported": "Supported",
"update_channel": "Update Channel",
"version_api": "Version API"
}
}
}
72 changes: 72 additions & 0 deletions homeassistant/components/hassio/system_health.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
"""Provide info to system health."""
Comment thread
ludeeus marked this conversation as resolved.
import os

from homeassistant.components import system_health
from homeassistant.core import HomeAssistant, callback

SUPERVISOR_PING = f"http://{os.environ['HASSIO']}/supervisor/ping"
OBSERVER_URL = f"http://{os.environ['HASSIO']}:4357"


@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_info = hass.components.hassio.get_host_info()
supervisor_info = hass.components.hassio.get_supervisor_info()

if supervisor_info.get("healthy"):
healthy = True
else:
healthy = {
"type": "failed",
"error": "Unhealthy",
"more_info": "/hassio/system",
}

if supervisor_info.get("supported"):
supported = True
else:
supported = {
"type": "failed",
"error": "Unsupported",
"more_info": "/hassio/system",
}

information = {
"host_os": host_info.get("operating_system"),
"update_channel": info.get("channel"),
"supervisor_version": info.get("supervisor"),
"docker_version": info.get("docker"),
"disk_total": f"{host_info.get('disk_total')} GB",
"disk_used": f"{host_info.get('disk_used')} GB",
"healthy": healthy,
"supported": supported,
}

if info.get("hassos") is not None:
os_info = hass.components.hassio.get_os_info()
information["board"] = os_info.get("board")

information["supervisor_api"] = system_health.async_check_can_reach_url(
hass, SUPERVISOR_PING, OBSERVER_URL
)
information["version_api"] = system_health.async_check_can_reach_url(
hass,
f"https://version.home-assistant.io/{info.get('channel')}.json",
"/hassio/system",
)

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

return information
19 changes: 17 additions & 2 deletions homeassistant/components/hassio/translations/en.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
{
"title": "Hass.io"
}
"system_health": {
"info": {
"board": "Board",
"disk_total": "Disk Total",
"disk_used": "Disk Used",
"docker_version": "Docker Version",
"healthy": "Healthy",
"host_os": "Host Operating System",
"installed_addons": "Installed Add-ons",
"supervisor_api": "Supervisor API",
"supervisor_version": "Supervisor Version",
"supported": "Supported",
"update_channel": "Update Channel",
"version_api": "Version API"
}
}
}
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"
}
}
}
16 changes: 14 additions & 2 deletions homeassistant/components/homeassistant/system_health.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,17 @@ 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")
return info

return {
"version": info.get("version"),
"installation_type": info.get("installation_type"),
"dev": info.get("dev"),
"hassio": info.get("hassio"),
"docker": info.get("docker"),
"virtualenv": info.get("virtualenv"),
"python_version": info.get("python_version"),
"os_name": info.get("os_name"),
"os_version": info.get("os_version"),
"arch": info.get("arch"),
"timezone": info.get("timezone"),
}
33 changes: 15 additions & 18 deletions homeassistant/components/homeassistant/translations/en.json
Original file line number Diff line number Diff line change
@@ -1,20 +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"
}
"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
Loading