-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from jmwaldrip/main
Adding support for Heidi Climate System
- Loading branch information
Showing
6 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
"""Foundation for Core Climate for SleepIQ API.""" | ||
from __future__ import annotations | ||
|
||
from typing import Any | ||
|
||
from .api import SleepIQAPI | ||
|
||
from .consts import SIDES_FULL, CoreTemps, Side | ||
|
||
|
||
class SleepIQCoreClimate: | ||
""" | ||
CoreClimate representation for SleepIQ API. | ||
Controls heating and cooling. | ||
""" | ||
|
||
def __init__(self, api: SleepIQAPI, bed_id: str, side: Side, timer: int, temperature: int) -> None: | ||
"""Initialize CoreClimate object.""" | ||
self._api = api | ||
self.bed_id = bed_id | ||
self.side = side | ||
self.is_on = (temperature > 0) | ||
self.timer = timer | ||
self.temperature = temperature | ||
|
||
def __str__(self) -> str: | ||
"""Return string representation.""" | ||
return f"SleepIQCoreClimate[{self.side}]: {'On' if self.is_on else 'Off'}, {self.timer}, {CoreTemps(self.temperature).name}" | ||
__repr__ = __str__ | ||
|
||
async def turn_on(self, temperature: CoreTemps, time: int) -> None: | ||
"""Turn on core climate mode through API.""" | ||
await self.set_mode(temperature, time) | ||
|
||
async def turn_off(self) -> None: | ||
"""Turn off core climate mode through API.""" | ||
# The API requires a valid time value even if we're turning the climate off | ||
await self.set_mode(CoreTemps.OFF, 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
"""Foundation for Core Climate for Fuzion SleepIQ API.""" | ||
from __future__ import annotations | ||
|
||
from typing import Any | ||
|
||
from ..api import SleepIQAPI | ||
|
||
from ..core_climate import SleepIQCoreClimate | ||
|
||
from ..consts import SIDES_FULL, CoreTemps, Side | ||
|
||
|
||
class SleepIQFuzionCoreClimate(SleepIQCoreClimate): | ||
""" | ||
CoreClimate (Also known as Heidi) representation for SleepIQ Fuzion API. | ||
Heidi is the name of the climate calls in the SleepIQ API. | ||
Controls heating and cooling. | ||
""" | ||
max_core_climate_time = 600 | ||
|
||
async def set_mode(self, temperature: CoreTemps, time: int) -> None: | ||
"""Set core climate state through API.""" | ||
if time <= 0 or time > self.max_core_climate_time: | ||
raise ValueError(f"Invalid Time, must be between 0 and {self.max_core_climate_time}") | ||
|
||
args = [SIDES_FULL[self.side].lower(), temperature.name.lower(), str(time)] | ||
await self._api.bamkey(self.bed_id, "SetHeidiMode", args) | ||
await self.update({}) | ||
|
||
async def update(self, data: dict[str, Any]) -> None: | ||
"""Update the core climate data through the API.""" | ||
args = [SIDES_FULL[self.side].lower()] | ||
self.preset = await self._api.bamkey(self.bed_id, "GetHeidiMode", args) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters