Skip to content

Commit

Permalink
Add method for getting status from either status or stop endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
frwickst committed Jan 29, 2022
1 parent 79f3623 commit 06fb1e8
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions huum/huum.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit 06fb1e8

Please sign in to comment.