From 06fb1e8882ca40ec1b67ef815710f2faae401a2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frank=20Wickstr=C3=B6m?= Date: Sat, 29 Jan 2022 20:35:40 +0200 Subject: [PATCH] Add method for getting status from either status or stop endpoint --- huum/huum.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/huum/huum.py b/huum/huum.py index 195dc9b..621d1da 100644 --- a/huum/huum.py +++ b/huum/huum.py @@ -3,6 +3,7 @@ import aiohttp +from huum.const import SaunaStatus from huum.exceptions import SafetyException from huum.schemas import HuumStatusResponse from huum.settings import settings @@ -149,6 +150,29 @@ async def status(self) -> HuumStatusResponse: return HuumStatusResponse(**json_data) + async def status_from_status_or_stop(self) -> HuumStatusResponse: + """ + Get status from the status endpoint or from stop event if that is in option + + The Huum API does not return the target temperature if the sauna + is not heating. Turning off the sauna will give the temperature, + however. So if the sauna is not on, we can get the temperature + set on the thermostat by telling it to turn off. If the sauna is on + we get the target temperature from the status endpoint. + + Why this is not done in the status method is because there is an + additional API call in the case that the status endpoint does not + return target temperature. For this reason the status method is kept + as a pure status request. + + Returns: + A `HuumStatusResponse` from the Huum API + """ + status_response = await self.status() + if status_response.status == SaunaStatus.ONLINE_NOT_HEATING: + status_response = await self.turn_off() + return status_response + async def open_session(self) -> None: self.session = aiohttp.ClientSession()