From f4a58c7dc7e846cdf492b96a5c4ef0216a76dfbb Mon Sep 17 00:00:00 2001 From: Keilin Bickar Date: Thu, 1 Dec 2022 04:53:48 -0500 Subject: [PATCH] Bump sense_api to 0.11.0 and add refresh token support (#83030) fixes undefined --- homeassistant/components/emulated_kasa/manifest.json | 2 +- homeassistant/components/sense/__init__.py | 5 ++++- homeassistant/components/sense/config_flow.py | 2 ++ homeassistant/components/sense/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- tests/components/sense/test_config_flow.py | 4 ++++ 7 files changed, 14 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/emulated_kasa/manifest.json b/homeassistant/components/emulated_kasa/manifest.json index 31319a656cd..86e8f2fc2ca 100644 --- a/homeassistant/components/emulated_kasa/manifest.json +++ b/homeassistant/components/emulated_kasa/manifest.json @@ -2,7 +2,7 @@ "domain": "emulated_kasa", "name": "Emulated Kasa", "documentation": "https://www.home-assistant.io/integrations/emulated_kasa", - "requirements": ["sense_energy==0.10.4"], + "requirements": ["sense_energy==0.11.0"], "codeowners": ["@kbickar"], "quality_scale": "internal", "iot_class": "local_push", diff --git a/homeassistant/components/sense/__init__.py b/homeassistant/components/sense/__init__.py index 82b25802b02..316cbb841ed 100644 --- a/homeassistant/components/sense/__init__.py +++ b/homeassistant/components/sense/__init__.py @@ -66,6 +66,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: access_token = entry_data.get("access_token", "") user_id = entry_data.get("user_id", "") + device_id = entry_data.get("device_id", "") + refresh_token = entry_data.get("refresh_token", "") monitor_id = entry_data.get("monitor_id", "") client_session = async_get_clientsession(hass) @@ -76,7 +78,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: gateway.rate_limit = ACTIVE_UPDATE_RATE try: - gateway.load_auth(access_token, user_id, monitor_id) + gateway.load_auth(access_token, user_id, device_id, refresh_token) + gateway.set_monitor_id(monitor_id) await gateway.get_monitor_data() except (SenseAuthenticationException, SenseMFARequiredException) as err: _LOGGER.warning("Sense authentication expired") diff --git a/homeassistant/components/sense/config_flow.py b/homeassistant/components/sense/config_flow.py index 0690344ccf1..d7f7588beb2 100644 --- a/homeassistant/components/sense/config_flow.py +++ b/homeassistant/components/sense/config_flow.py @@ -60,6 +60,8 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): """Create the entry from the config data.""" self._auth_data["access_token"] = self._gateway.sense_access_token self._auth_data["user_id"] = self._gateway.sense_user_id + self._auth_data["device_id"] = self._gateway.device_id + self._auth_data["refresh_token"] = self._gateway.refresh_token self._auth_data["monitor_id"] = self._gateway.sense_monitor_id existing_entry = await self.async_set_unique_id(self._auth_data[CONF_EMAIL]) if not existing_entry: diff --git a/homeassistant/components/sense/manifest.json b/homeassistant/components/sense/manifest.json index 192a0f6defe..158ef7cae61 100644 --- a/homeassistant/components/sense/manifest.json +++ b/homeassistant/components/sense/manifest.json @@ -2,7 +2,7 @@ "domain": "sense", "name": "Sense", "documentation": "https://www.home-assistant.io/integrations/sense", - "requirements": ["sense_energy==0.10.4"], + "requirements": ["sense_energy==0.11.0"], "codeowners": ["@kbickar"], "config_flow": true, "dhcp": [ diff --git a/requirements_all.txt b/requirements_all.txt index c9e53c4824f..4c5e81ae1b2 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -2258,7 +2258,7 @@ sendgrid==6.8.2 # homeassistant.components.emulated_kasa # homeassistant.components.sense -sense_energy==0.10.4 +sense_energy==0.11.0 # homeassistant.components.sensirion_ble sensirion-ble==0.0.1 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index cca1eecda0a..0be440adfd6 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -1561,7 +1561,7 @@ securetar==2022.2.0 # homeassistant.components.emulated_kasa # homeassistant.components.sense -sense_energy==0.10.4 +sense_energy==0.11.0 # homeassistant.components.sensirion_ble sensirion-ble==0.0.1 diff --git a/tests/components/sense/test_config_flow.py b/tests/components/sense/test_config_flow.py index 690e5d2e530..7dc2b2469ec 100644 --- a/tests/components/sense/test_config_flow.py +++ b/tests/components/sense/test_config_flow.py @@ -22,6 +22,8 @@ MOCK_CONFIG = { "access_token": "ABC", "user_id": "123", "monitor_id": "456", + "device_id": "789", + "refresh_token": "XYZ", } @@ -36,6 +38,8 @@ def mock_sense(): mock_sense.return_value.sense_access_token = "ABC" mock_sense.return_value.sense_user_id = "123" mock_sense.return_value.sense_monitor_id = "456" + mock_sense.return_value.device_id = "789" + mock_sense.return_value.refresh_token = "XYZ" yield mock_sense