Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
sleep is removed from core in 2023.11.
  • Loading branch information
amosyuen committed Mar 3, 2024
1 parent c3cc64a commit d32c57c
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 19 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ The Google Assistant UI is limited to setting temperature between 50 to 90 degre

## Installation

Requries https://github.com/lukas-clarke/eight_sleep to be installed.

### HACS

1. Install [HACS](https://hacs.xyz/)
Expand Down
51 changes: 36 additions & 15 deletions custom_components/eight_sleep_climate/climate.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
"""Adds support for Eight Sleep thermostat units."""
import logging

from custom_components.eight_sleep.const import ATTR_DURATION
from custom_components.eight_sleep.const import ATTR_SERVICE_SLEEP_STAGE
from custom_components.eight_sleep.const import ATTR_TARGET
from custom_components.eight_sleep.const import (
DOMAIN as EIGHT_SLEEP_DOMAIN,
)
from custom_components.eight_sleep.const import SERVICE_HEAT_SET
from custom_components.eight_sleep.const import SERVICE_SIDE_OFF
from custom_components.eight_sleep.const import SERVICE_SIDE_ON
from custom_components.eight_sleep.sensor import ATTR_DURATION_HEAT
from custom_components.eight_sleep.sensor import ATTR_TARGET_HEAT
from homeassistant.components.climate import (
ClimateEntity,
)
Expand All @@ -12,12 +23,6 @@
from homeassistant.components.climate.const import CURRENT_HVAC_OFF
from homeassistant.components.climate.const import HVAC_MODE_HEAT_COOL
from homeassistant.components.climate.const import HVAC_MODE_OFF
from homeassistant.components.eight_sleep.const import ATTR_DURATION
from homeassistant.components.eight_sleep.const import ATTR_TARGET
from homeassistant.components.eight_sleep.const import DOMAIN as EIGHT_SLEEP_DOMAIN
from homeassistant.components.eight_sleep.const import SERVICE_HEAT_SET
from homeassistant.components.eight_sleep.sensor import ATTR_DURATION_HEAT
from homeassistant.components.eight_sleep.sensor import ATTR_TARGET_HEAT
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ATTR_ENTITY_ID
Expand All @@ -35,6 +40,7 @@
from .util import remove_unique_id_postfix

ATTR_TARGET_TEMP = "target_temperature"
STAGE_CURRENT = "current"
EIGHT_HEAT_SENSOR = "bed_state"

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -176,6 +182,7 @@ async def async_set_temperature(self, **kwargs):
kwargs,
)
hvac_mode = self.hvac_mode
target_temp = None
if ATTR_TEMPERATURE in kwargs:
target_temp = int(kwargs[ATTR_TEMPERATURE])
if target_temp < self._attr_min_temp or target_temp > self._attr_max_temp:
Expand All @@ -196,15 +203,29 @@ async def async_set_temperature(self, **kwargs):
_LOGGER.error("Unrecognized hvac mode: %s", hvac_mode)
return False

data = {
ATTR_ENTITY_ID: self._eight_sleep_state_entity_id,
ATTR_DURATION: 7200 if hvac_mode == HVAC_MODE_HEAT_COOL else 0,
ATTR_TARGET: self._attr_target_temperature,
}
_LOGGER.debug("_async_update_climate: Set heat data=%s", data)
await self.hass.services.async_call(
EIGHT_SLEEP_DOMAIN, SERVICE_HEAT_SET, data, False
)
if hvac_mode != HVAC_MODE_HEAT_COOL:
data = {ATTR_ENTITY_ID: self._eight_sleep_state_entity_id}
_LOGGER.debug("_async_update_climate: Turn off side data=%s", data)
await self.hass.services.async_call(
EIGHT_SLEEP_DOMAIN, SERVICE_SIDE_OFF, data, False
)
elif target_temp is None:
data = {ATTR_ENTITY_ID: self._eight_sleep_state_entity_id}
_LOGGER.debug("_async_update_climate: Turn on side data=%s", data)
await self.hass.services.async_call(
EIGHT_SLEEP_DOMAIN, SERVICE_SIDE_ON, data, False
)
else:
data = {
ATTR_SERVICE_SLEEP_STAGE: STAGE_CURRENT,
ATTR_ENTITY_ID: self._eight_sleep_state_entity_id,
ATTR_DURATION: 7200 if hvac_mode == HVAC_MODE_HEAT_COOL else 0,
ATTR_TARGET: self._attr_target_temperature,
}
_LOGGER.debug("_async_update_climate: Set heat data=%s", data)
await self.hass.services.async_call(
EIGHT_SLEEP_DOMAIN, SERVICE_HEAT_SET, data, False
)

async def async_turn_off(self):
"""Turn thermostat on."""
Expand Down
4 changes: 3 additions & 1 deletion custom_components/eight_sleep_climate/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
from typing import Set

import voluptuous as vol
from custom_components.eight_sleep.const import (
DOMAIN as EIGHT_SLEEP_DOMAIN,
)
from homeassistant import config_entries
from homeassistant.components.climate import DOMAIN as CLIMATE_PLATFORM
from homeassistant.components.eight_sleep.const import DOMAIN as EIGHT_SLEEP_DOMAIN
from homeassistant.config_entries import ConfigEntryState
from homeassistant.const import CONF_NAME
from homeassistant.core import HomeAssistant
Expand Down
2 changes: 1 addition & 1 deletion custom_components/eight_sleep_climate/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
"documentation": "https://github.com/amosyuen/ha-eight-sleep-climate",
"iot_class": "cloud_polling",
"issue_tracker": "https://github.com/amosyuen/ha-eight-sleep-climate/issues",
"version": "2.0.0"
"version": "3.0.0"
}
4 changes: 2 additions & 2 deletions hacs.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Eight Sleep Climate",
"hacs": "1.0.0",
"homeassistant": "0.118.0",
"hacs": "1.6.0",
"homeassistant": "2023.11.0",
"render_readme": true
}

0 comments on commit d32c57c

Please sign in to comment.