diff --git a/README.md b/README.md index 52c7ac3..1b2b662 100755 --- a/README.md +++ b/README.md @@ -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/) diff --git a/custom_components/eight_sleep_climate/climate.py b/custom_components/eight_sleep_climate/climate.py index 041627f..5922378 100755 --- a/custom_components/eight_sleep_climate/climate.py +++ b/custom_components/eight_sleep_climate/climate.py @@ -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, ) @@ -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 @@ -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__) @@ -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: @@ -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.""" diff --git a/custom_components/eight_sleep_climate/config_flow.py b/custom_components/eight_sleep_climate/config_flow.py index a9a4395..67df6fe 100755 --- a/custom_components/eight_sleep_climate/config_flow.py +++ b/custom_components/eight_sleep_climate/config_flow.py @@ -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 diff --git a/custom_components/eight_sleep_climate/manifest.json b/custom_components/eight_sleep_climate/manifest.json index 8259032..50bf563 100755 --- a/custom_components/eight_sleep_climate/manifest.json +++ b/custom_components/eight_sleep_climate/manifest.json @@ -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" } diff --git a/hacs.json b/hacs.json index 29fbc65..1bbb566 100755 --- a/hacs.json +++ b/hacs.json @@ -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 }