From 2c8b704a6d49f67c2bdd4538365e4fa2eba028e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20S=C3=B8rensen?= Date: Thu, 13 Apr 2023 00:38:32 +0200 Subject: [PATCH] Add certificate status for cloud remote (#91277) --- homeassistant/components/cloud/http_api.py | 1 + homeassistant/components/cloud/strings.json | 1 + homeassistant/components/cloud/system_health.py | 1 + tests/components/cloud/test_http_api.py | 1 + tests/components/cloud/test_system_health.py | 8 +++++++- 5 files changed, 11 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/cloud/http_api.py b/homeassistant/components/cloud/http_api.py index c25de5463b5d9..aef4efdb7a467 100644 --- a/homeassistant/components/cloud/http_api.py +++ b/homeassistant/components/cloud/http_api.py @@ -485,6 +485,7 @@ async def _account_data(hass: HomeAssistant, cloud: Cloud): "logged_in": True, "prefs": client.prefs.as_dict(), "remote_certificate": certificate, + "remote_certificate_status": remote.certificate_status, "remote_connected": remote.is_connected, "remote_domain": remote.instance_domain, "http_use_ssl": hass.config.api.use_ssl, diff --git a/homeassistant/components/cloud/strings.json b/homeassistant/components/cloud/strings.json index 432a4db0f7725..a3cf7fe04576c 100644 --- a/homeassistant/components/cloud/strings.json +++ b/homeassistant/components/cloud/strings.json @@ -4,6 +4,7 @@ "can_reach_cert_server": "Reach Certificate Server", "can_reach_cloud": "Reach Home Assistant Cloud", "can_reach_cloud_auth": "Reach Authentication Server", + "certificate_status": "Certificate Status", "relayer_connected": "Relayer Connected", "relayer_region": "Relayer Region", "remote_connected": "Remote Connected", diff --git a/homeassistant/components/cloud/system_health.py b/homeassistant/components/cloud/system_health.py index b1f1774aa479b..592338144f362 100644 --- a/homeassistant/components/cloud/system_health.py +++ b/homeassistant/components/cloud/system_health.py @@ -34,6 +34,7 @@ async def system_health_info(hass): data["alexa_enabled"] = client.prefs.alexa_enabled data["google_enabled"] = client.prefs.google_enabled data["remote_server"] = cloud.remote.snitun_server + data["certificate_status"] = cloud.remote.certificate_status data["can_reach_cert_server"] = system_health.async_check_can_reach_url( hass, f"https://{cloud.acme_server}/directory" diff --git a/tests/components/cloud/test_http_api.py b/tests/components/cloud/test_http_api.py index 115e77f118e20..f748a6981ad0d 100644 --- a/tests/components/cloud/test_http_api.py +++ b/tests/components/cloud/test_http_api.py @@ -429,6 +429,7 @@ async def test_websocket_status( "google_local_connected": False, "remote_domain": None, "remote_connected": False, + "remote_certificate_status": None, "remote_certificate": None, "http_use_ssl": False, "active_subscription": False, diff --git a/tests/components/cloud/test_system_health.py b/tests/components/cloud/test_system_health.py index 96b87936da4b0..79e45e9ba26d8 100644 --- a/tests/components/cloud/test_system_health.py +++ b/tests/components/cloud/test_system_health.py @@ -3,6 +3,7 @@ from unittest.mock import Mock from aiohttp import ClientError +from hass_nabucasa.remote import CertificateStatus from homeassistant.core import HomeAssistant from homeassistant.setup import async_setup_component @@ -32,7 +33,11 @@ async def test_cloud_system_health( relayer_server="cloud.bla.com", acme_server="cert-server", is_logged_in=True, - remote=Mock(is_connected=False, snitun_server="us-west-1"), + remote=Mock( + is_connected=False, + snitun_server="us-west-1", + certificate_status=CertificateStatus.READY, + ), expiration_date=now, is_connected=True, client=Mock( @@ -54,6 +59,7 @@ async def test_cloud_system_health( assert info == { "logged_in": True, "subscription_expiration": now, + "certificate_status": "ready", "relayer_connected": True, "relayer_region": "xx-earth-616", "remote_enabled": True,