From bbd98e196b70a08800a23b954ed81b62a7eabf75 Mon Sep 17 00:00:00 2001 From: Ron Heft Date: Tue, 16 Mar 2021 12:15:22 -0400 Subject: [PATCH] Fix withings InvalidParamsException (#47975) * Bump withings_api to 2.3.1 (fixes #47329) * Fix NotifyAppli calls to be compatible with withings_api 2.3.1 * Fix errors with withings_api 2.2+ using pydantic * Bump withings_api to 2.3.2 --- homeassistant/components/withings/__init__.py | 8 +++----- homeassistant/components/withings/common.py | 4 ++-- homeassistant/components/withings/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- 5 files changed, 8 insertions(+), 10 deletions(-) diff --git a/homeassistant/components/withings/__init__.py b/homeassistant/components/withings/__init__.py index c6f420d172a..5efa22e6a86 100644 --- a/homeassistant/components/withings/__init__.py +++ b/homeassistant/components/withings/__init__.py @@ -4,12 +4,12 @@ Support for the Withings API. For more details about this platform, please refer to the documentation at """ import asyncio -from typing import Optional, cast +from typing import Optional from aiohttp.web import Request, Response import voluptuous as vol from withings_api import WithingsAuth -from withings_api.common import NotifyAppli, enum_or_raise +from withings_api.common import NotifyAppli from homeassistant.components import webhook from homeassistant.components.binary_sensor import DOMAIN as BINARY_SENSOR_DOMAIN @@ -195,9 +195,7 @@ async def async_webhook_handler( return json_message_response("Parameter appli not provided", message_code=20) try: - appli = cast( - NotifyAppli, enum_or_raise(int(params.getone("appli")), NotifyAppli) - ) + appli = NotifyAppli(int(params.getone("appli"))) except ValueError: return json_message_response("Invalid appli provided", message_code=21) diff --git a/homeassistant/components/withings/common.py b/homeassistant/components/withings/common.py index e2e0b06e342..54a0a3c94ee 100644 --- a/homeassistant/components/withings/common.py +++ b/homeassistant/components/withings/common.py @@ -681,7 +681,7 @@ class DataManager: ) # Determine what subscriptions need to be created. - ignored_applis = frozenset({NotifyAppli.USER}) + ignored_applis = frozenset({NotifyAppli.USER, NotifyAppli.UNKNOWN}) to_add_applis = frozenset( [ appli @@ -846,7 +846,7 @@ class DataManager: data = serie.data for field in GetSleepSummaryField: - raw_values[field].append(data._asdict()[field.value]) + raw_values[field].append(dict(data)[field.value]) values: Dict[GetSleepSummaryField, float] = {} diff --git a/homeassistant/components/withings/manifest.json b/homeassistant/components/withings/manifest.json index ec981ff691c..6b2918722ba 100644 --- a/homeassistant/components/withings/manifest.json +++ b/homeassistant/components/withings/manifest.json @@ -3,7 +3,7 @@ "name": "Withings", "config_flow": true, "documentation": "https://www.home-assistant.io/integrations/withings", - "requirements": ["withings-api==2.1.6"], + "requirements": ["withings-api==2.3.2"], "dependencies": ["http", "webhook"], "codeowners": ["@vangorra"] } diff --git a/requirements_all.txt b/requirements_all.txt index c07215ade32..ca653fb6e1b 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -2311,7 +2311,7 @@ wiffi==1.0.1 wirelesstagpy==0.4.1 # homeassistant.components.withings -withings-api==2.1.6 +withings-api==2.3.2 # homeassistant.components.wled wled==0.4.4 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index ed005d34d03..7210c651177 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -1187,7 +1187,7 @@ watchdog==1.0.2 wiffi==1.0.1 # homeassistant.components.withings -withings-api==2.1.6 +withings-api==2.3.2 # homeassistant.components.wled wled==0.4.4