mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Pass function correctly to Withings API (#100391)
* Pass function correctly to Withings API * Add more typing
This commit is contained in:
parent
f99dedfb42
commit
7b71d27637
@ -2,7 +2,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
from collections.abc import Iterable
|
from collections.abc import Awaitable, Callable, Iterable
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
import arrow
|
import arrow
|
||||||
@ -63,7 +63,7 @@ class ConfigEntryWithingsApi(AbstractWithingsApi):
|
|||||||
)
|
)
|
||||||
return response.json()
|
return response.json()
|
||||||
|
|
||||||
async def _do_retry(self, func, attempts=3) -> Any:
|
async def _do_retry(self, func: Callable[[], Awaitable[Any]], attempts=3) -> Any:
|
||||||
"""Retry a function call.
|
"""Retry a function call.
|
||||||
|
|
||||||
Withings' API occasionally and incorrectly throws errors.
|
Withings' API occasionally and incorrectly throws errors.
|
||||||
@ -97,8 +97,8 @@ class ConfigEntryWithingsApi(AbstractWithingsApi):
|
|||||||
) -> MeasureGetMeasResponse:
|
) -> MeasureGetMeasResponse:
|
||||||
"""Get measurements."""
|
"""Get measurements."""
|
||||||
|
|
||||||
return await self._do_retry(
|
async def call_super() -> MeasureGetMeasResponse:
|
||||||
await self._hass.async_add_executor_job(
|
return await self._hass.async_add_executor_job(
|
||||||
self.measure_get_meas,
|
self.measure_get_meas,
|
||||||
meastype,
|
meastype,
|
||||||
category,
|
category,
|
||||||
@ -107,7 +107,8 @@ class ConfigEntryWithingsApi(AbstractWithingsApi):
|
|||||||
offset,
|
offset,
|
||||||
lastupdate,
|
lastupdate,
|
||||||
)
|
)
|
||||||
)
|
|
||||||
|
return await self._do_retry(call_super)
|
||||||
|
|
||||||
async def async_sleep_get_summary(
|
async def async_sleep_get_summary(
|
||||||
self,
|
self,
|
||||||
@ -119,8 +120,8 @@ class ConfigEntryWithingsApi(AbstractWithingsApi):
|
|||||||
) -> SleepGetSummaryResponse:
|
) -> SleepGetSummaryResponse:
|
||||||
"""Get sleep data."""
|
"""Get sleep data."""
|
||||||
|
|
||||||
return await self._do_retry(
|
async def call_super() -> SleepGetSummaryResponse:
|
||||||
await self._hass.async_add_executor_job(
|
return await self._hass.async_add_executor_job(
|
||||||
self.sleep_get_summary,
|
self.sleep_get_summary,
|
||||||
data_fields,
|
data_fields,
|
||||||
startdateymd,
|
startdateymd,
|
||||||
@ -128,16 +129,18 @@ class ConfigEntryWithingsApi(AbstractWithingsApi):
|
|||||||
offset,
|
offset,
|
||||||
lastupdate,
|
lastupdate,
|
||||||
)
|
)
|
||||||
)
|
|
||||||
|
return await self._do_retry(call_super)
|
||||||
|
|
||||||
async def async_notify_list(
|
async def async_notify_list(
|
||||||
self, appli: NotifyAppli | None = None
|
self, appli: NotifyAppli | None = None
|
||||||
) -> NotifyListResponse:
|
) -> NotifyListResponse:
|
||||||
"""List webhooks."""
|
"""List webhooks."""
|
||||||
|
|
||||||
return await self._do_retry(
|
async def call_super() -> NotifyListResponse:
|
||||||
await self._hass.async_add_executor_job(self.notify_list, appli)
|
return await self._hass.async_add_executor_job(self.notify_list, appli)
|
||||||
)
|
|
||||||
|
return await self._do_retry(call_super)
|
||||||
|
|
||||||
async def async_notify_subscribe(
|
async def async_notify_subscribe(
|
||||||
self,
|
self,
|
||||||
@ -147,19 +150,21 @@ class ConfigEntryWithingsApi(AbstractWithingsApi):
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Subscribe to webhook."""
|
"""Subscribe to webhook."""
|
||||||
|
|
||||||
return await self._do_retry(
|
async def call_super() -> None:
|
||||||
await self._hass.async_add_executor_job(
|
await self._hass.async_add_executor_job(
|
||||||
self.notify_subscribe, callbackurl, appli, comment
|
self.notify_subscribe, callbackurl, appli, comment
|
||||||
)
|
)
|
||||||
)
|
|
||||||
|
await self._do_retry(call_super)
|
||||||
|
|
||||||
async def async_notify_revoke(
|
async def async_notify_revoke(
|
||||||
self, callbackurl: str | None = None, appli: NotifyAppli | None = None
|
self, callbackurl: str | None = None, appli: NotifyAppli | None = None
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Revoke webhook."""
|
"""Revoke webhook."""
|
||||||
|
|
||||||
return await self._do_retry(
|
async def call_super() -> None:
|
||||||
await self._hass.async_add_executor_job(
|
await self._hass.async_add_executor_job(
|
||||||
self.notify_revoke, callbackurl, appli
|
self.notify_revoke, callbackurl, appli
|
||||||
)
|
)
|
||||||
)
|
|
||||||
|
await self._do_retry(call_super)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user