Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SleepIQ add core climate for SleepNumber Climate 360 beds #134718

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions homeassistant/components/sleepiq/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
DOMAIN = "sleepiq"

ACTUATOR = "actuator"
CORE_CLIMATE_TIMER = "core_climate_timer"
CORE_CLIMATE = "core_climate"
BED = "bed"
FIRMNESS = "firmness"
ICON_EMPTY = "mdi:bed-empty"
Expand All @@ -15,6 +17,8 @@
FOOT_WARMER = "foot_warmer"
ENTITY_TYPES = {
ACTUATOR: "Position",
CORE_CLIMATE_TIMER: "Core Climate Timer",
CORE_CLIMATE: "Core Climate",
FIRMNESS: "Firmness",
PRESSURE: "Pressure",
IS_IN_BED: "Is In Bed",
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/sleepiq/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
"documentation": "https://www.home-assistant.io/integrations/sleepiq",
"iot_class": "cloud_polling",
"loggers": ["asyncsleepiq"],
"requirements": ["asyncsleepiq==1.5.2"]
"requirements": ["asyncsleepiq==1.5.3"]
}
45 changes: 45 additions & 0 deletions homeassistant/components/sleepiq/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
from typing import Any, cast

from asyncsleepiq import (
CoreTemps,
FootWarmingTemps,
SleepIQActuator,
SleepIQBed,
SleepIQCoreClimate,
SleepIQFootWarmer,
SleepIQSleeper,
)
Expand All @@ -21,6 +23,7 @@

from .const import (
ACTUATOR,
CORE_CLIMATE_TIMER,
DOMAIN,
ENTITY_TYPES,
FIRMNESS,
Expand Down Expand Up @@ -95,6 +98,27 @@ def _get_foot_warming_unique_id(bed: SleepIQBed, foot_warmer: SleepIQFootWarmer)
return f"{bed.id}_{foot_warmer.side.value}_{FOOT_WARMING_TIMER}"


async def _async_set_core_climate_time(
core_climate: SleepIQCoreClimate, time: int
) -> None:
temperature = CoreTemps(core_climate.temperature)
if temperature != CoreTemps.OFF:
await core_climate.turn_on(temperature, time)

core_climate.timer = time


def _get_core_climate_name(bed: SleepIQBed, core_climate: SleepIQCoreClimate) -> str:
sleeper = sleeper_for_side(bed, core_climate.side)
return f"SleepNumber {bed.name} {sleeper.name} {ENTITY_TYPES[CORE_CLIMATE_TIMER]}"


def _get_core_climate_unique_id(
bed: SleepIQBed, core_climate: SleepIQCoreClimate
) -> str:
return f"{bed.id}_{core_climate.side.value}_{CORE_CLIMATE_TIMER}"


NUMBER_DESCRIPTIONS: dict[str, SleepIQNumberEntityDescription] = {
FIRMNESS: SleepIQNumberEntityDescription(
key=FIRMNESS,
Expand Down Expand Up @@ -132,6 +156,18 @@ def _get_foot_warming_unique_id(bed: SleepIQBed, foot_warmer: SleepIQFootWarmer)
get_name_fn=_get_foot_warming_name,
get_unique_id_fn=_get_foot_warming_unique_id,
),
CORE_CLIMATE_TIMER: SleepIQNumberEntityDescription(
key=CORE_CLIMATE_TIMER,
native_min_value=0,
native_max_value=SleepIQCoreClimate.max_core_climate_time,
native_step=30,
name=ENTITY_TYPES[CORE_CLIMATE_TIMER],
icon="mdi:timer",
value_fn=lambda core_climate: core_climate.timer,
set_value_fn=_async_set_core_climate_time,
get_name_fn=_get_core_climate_name,
get_unique_id_fn=_get_core_climate_unique_id,
),
}


Expand Down Expand Up @@ -172,6 +208,15 @@ async def async_setup_entry(
)
for foot_warmer in bed.foundation.foot_warmers
)
entities.extend(
SleepIQNumberEntity(
data.data_coordinator,
bed,
core_climate,
NUMBER_DESCRIPTIONS[CORE_CLIMATE_TIMER],
)
for core_climate in bed.foundation.core_climates
)

async_add_entities(entities)

Expand Down
51 changes: 50 additions & 1 deletion homeassistant/components/sleepiq/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
from __future__ import annotations

from asyncsleepiq import (
CoreTemps,
FootWarmingTemps,
Side,
SleepIQBed,
SleepIQCoreClimate,
SleepIQFootWarmer,
SleepIQPreset,
)
Expand All @@ -15,7 +17,7 @@
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity_platform import AddEntitiesCallback

from .const import DOMAIN, FOOT_WARMER
from .const import CORE_CLIMATE, DOMAIN, FOOT_WARMER
from .coordinator import SleepIQData, SleepIQDataUpdateCoordinator
from .entity import SleepIQBedEntity, SleepIQSleeperEntity, sleeper_for_side

Expand All @@ -37,6 +39,10 @@ async def async_setup_entry(
SleepIQFootWarmingTempSelectEntity(data.data_coordinator, bed, foot_warmer)
for foot_warmer in bed.foundation.foot_warmers
)
entities.extend(
SleepIQCoreTempSelectEntity(data.data_coordinator, bed, core_climate)
for core_climate in bed.foundation.core_climates
)
async_add_entities(entities)


Expand Down Expand Up @@ -115,3 +121,46 @@ async def async_select_option(self, option: str) -> None:
self._attr_current_option = option
await self.coordinator.async_request_refresh()
self.async_write_ha_state()


class SleepIQCoreTempSelectEntity(
SleepIQSleeperEntity[SleepIQDataUpdateCoordinator], SelectEntity
):
"""Representation of a SleepIQ core climate temperature select entity."""

_attr_icon = "mdi:heat-wave"
_attr_options = [e.name.lower() for e in CoreTemps]
_attr_translation_key = "core_temps"

def __init__(
self,
coordinator: SleepIQDataUpdateCoordinator,
bed: SleepIQBed,
core_climate: SleepIQCoreClimate,
) -> None:
"""Initialize the select entity."""
self.core_climate = core_climate
sleeper = sleeper_for_side(bed, core_climate.side)
super().__init__(coordinator, bed, sleeper, CORE_CLIMATE)
self._async_update_attrs()

@callback
def _async_update_attrs(self) -> None:
"""Update entity attributes."""
self._attr_current_option = CoreTemps(
self.core_climate.temperature
).name.lower()

async def async_select_option(self, option: str) -> None:
"""Change the current preset."""
temperature = CoreTemps[option.upper()]
timer = self.core_climate.timer or 240

if temperature == 0:
await self.core_climate.turn_off()
else:
await self.core_climate.turn_on(temperature, timer)

self._attr_current_option = option
await self.coordinator.async_request_refresh()
self.async_write_ha_state()
11 changes: 11 additions & 0 deletions homeassistant/components/sleepiq/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@
"medium": "Medium",
"high": "High"
}
},
"core_temps": {
"state": {
"off": "Off",
"heating_push_low": "Heating Low",
"heating_push_med": "Heating Medium",
"heating_push_high": "Heating High",
"cooling_pull_low": "Cooling Low",
"cooling_pull_med": "Cooling Medium",
"cooling_pull_high": "Cooling High"
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ asyncinotify==4.0.2
asyncpysupla==0.0.5

# homeassistant.components.sleepiq
asyncsleepiq==1.5.2
asyncsleepiq==1.5.3

# homeassistant.components.aten_pe
# atenpdu==0.3.2
Expand Down
2 changes: 1 addition & 1 deletion requirements_test_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ async-upnp-client==0.42.0
asyncarve==0.1.1

# homeassistant.components.sleepiq
asyncsleepiq==1.5.2
asyncsleepiq==1.5.3

# homeassistant.components.aurora
auroranoaa==0.0.5
Expand Down