Add more system information from Supervisor (#35560)

This commit is contained in:
Franck Nijhof authored and GitHub committed 2020-05-12 15:27:34 -07:00
1 parent 306f15723d
commit eddb5c6c3f
8 files changed
+148 -35

No files matched your search

+31 -8
View File
@@ -41,7 +41,8 @@ CONFIG_SCHEMA = vol.Schema(
)
DATA_HOMEASSISTANT_VERSION = "hassio_hass_version"
DATA_INFO = "hassio_info"
DATA_HOST_INFO = "hassio_host_info"
HASSIO_UPDATE_INTERVAL = timedelta(minutes=55)
SERVICE_ADDON_START = "addon_start"
@@ -130,7 +131,29 @@ def get_homeassistant_version(hass):
Async friendly.
"""
return hass.data.get(DATA_HOMEASSISTANT_VERSION)
if DATA_INFO not in hass.data:
return None
return hass.data[DATA_INFO].get("homeassistant")
@callback
@bind_hass
def get_info(hass):
"""Return generic information from Supervisor.
Async friendly.
"""
return hass.data.get(DATA_INFO)
@callback
@bind_hass
def get_host_info(hass):
"""Return generic host information.
Async friendly.
"""
return hass.data.get(DATA_HOST_INFO)
@callback
@@ -247,20 +270,20 @@ async def async_setup(hass, config):
DOMAIN, service, async_service_handler, schema=settings[1]
)
async def update_homeassistant_version(now):
"""Update last available Home Assistant version."""
async def update_info_data(now):
"""Update last available supervisor information."""
try:
data = await hassio.get_homeassistant_info()
hass.data[DATA_HOMEASSISTANT_VERSION] = data["last_version"]
hass.data[DATA_INFO] = await hassio.get_info()
hass.data[DATA_HOST_INFO] = await hassio.get_host_info()
except HassioAPIError as err:
_LOGGER.warning("Can't read last version: %s", err)
hass.helpers.event.async_track_point_in_utc_time(
update_homeassistant_version, utcnow() + HASSIO_UPDATE_INTERVAL
update_info_data, utcnow() + HASSIO_UPDATE_INTERVAL
)
# Fetch last version
await update_homeassistant_version(None)
await update_info_data(None)
async def async_handle_core_service(call):
"""Service handler for handling core services."""
+11 -3
View File
@@ -68,12 +68,20 @@ class HassIO:
return self.send_command("/supervisor/ping", method="get", timeout=15)
@_api_data
def get_homeassistant_info(self):
"""Return data for Home Assistant.
def get_info(self):
"""Return generic Supervisor information.
This method return a coroutine.
"""
return self.send_command("/homeassistant/info", method="get")
return self.send_command("/info", method="get")
@_api_data
def get_host_info(self):
"""Return data for Host.
This method return a coroutine.
"""
return self.send_command("/host/info", method="get")
@_api_data
def get_addon_info(self, addon):
+23
View File
@@ -14,6 +14,7 @@ from .typing import HomeAssistantType
async def async_get_system_info(hass: HomeAssistantType) -> Dict:
"""Return info about the system."""
info_object = {
"installation_type": "Unknown",
"version": current_version,
"dev": "dev" in current_version,
"hassio": hass.components.hassio.is_hassio(),
@@ -33,4 +34,26 @@ async def async_get_system_info(hass: HomeAssistantType) -> Dict:
elif platform.system() == "Linux":
info_object["docker"] = os.path.isfile("/.dockerenv")
# Determine installation type on current data
if info_object["docker"]:
info_object["installation_type"] = "Home Assistant Core on Docker"
elif is_virtual_env():
info_object[
"installation_type"
] = "Home Assistant Core in a Python Virtual Environment"
# Enrich with Supervisor information
if hass.components.hassio.is_hassio():
info = hass.components.hassio.get_info()
host = hass.components.hassio.get_host_info()
info_object["supervisor"] = info.get("supervisor")
info_object["host_os"] = host.get("operating_system")
info_object["chassis"] = host.get("chassis")
if info.get("hassos") is not None:
info_object["installation_type"] = "Home Assistant"
else:
info_object["installation_type"] = "Home Assistant Supervised"
return info_object