mirror of
https://github.com/USA-RedDragon/badnest.git
synced 2025-01-18 22:50:44 +00:00
Thermostat eco preset support
This commit is contained in:
parent
de8312b722
commit
b4debfcf9c
@ -92,7 +92,6 @@ class NestThermostatAPI(NestAPI):
|
|||||||
self.can_cool = None
|
self.can_cool = None
|
||||||
self.has_fan = None
|
self.has_fan = None
|
||||||
self.fan = None
|
self.fan = None
|
||||||
self.away = None
|
|
||||||
self.current_temperature = None
|
self.current_temperature = None
|
||||||
self.target_temperature = None
|
self.target_temperature = None
|
||||||
self.target_temperature_high = None
|
self.target_temperature_high = None
|
||||||
@ -151,6 +150,7 @@ class NestThermostatAPI(NestAPI):
|
|||||||
]
|
]
|
||||||
self._hvac_ac_state = thermostat_data["hvac_ac_state"]
|
self._hvac_ac_state = thermostat_data["hvac_ac_state"]
|
||||||
self._hvac_heater_state = thermostat_data["hvac_heater_state"]
|
self._hvac_heater_state = thermostat_data["hvac_heater_state"]
|
||||||
|
if self.mode != 'eco':
|
||||||
self.mode = thermostat_data["target_temperature_type"]
|
self.mode = thermostat_data["target_temperature_type"]
|
||||||
self.target_temperature_high = thermostat_data[
|
self.target_temperature_high = thermostat_data[
|
||||||
"target_temperature_high"
|
"target_temperature_high"
|
||||||
@ -166,7 +166,10 @@ class NestThermostatAPI(NestAPI):
|
|||||||
self.has_fan = thermostat_data["has_fan"]
|
self.has_fan = thermostat_data["has_fan"]
|
||||||
self.fan = thermostat_data["fan_timer_timeout"] > 0
|
self.fan = thermostat_data["fan_timer_timeout"] > 0
|
||||||
self.current_humidity = thermostat_data["current_humidity"]
|
self.current_humidity = thermostat_data["current_humidity"]
|
||||||
self.away = thermostat_data["home_away_input"]
|
if thermostat_data["eco"]["mode"] == 'manual-eco':
|
||||||
|
self.mode = 'eco'
|
||||||
|
else:
|
||||||
|
self.mode = 'unknown'
|
||||||
|
|
||||||
def set_temp(self, temp, temp_high=None):
|
def set_temp(self, temp, temp_high=None):
|
||||||
if temp_high is None:
|
if temp_high is None:
|
||||||
@ -231,7 +234,8 @@ class NestThermostatAPI(NestAPI):
|
|||||||
headers={"Authorization": f"Basic {self._access_token}"},
|
headers={"Authorization": f"Basic {self._access_token}"},
|
||||||
)
|
)
|
||||||
|
|
||||||
def set_eco_mode(self):
|
def set_eco_mode(self, state):
|
||||||
|
mode = 'manual-eco' if state else 'schedule'
|
||||||
self._session.post(
|
self._session.post(
|
||||||
f"{self._czfe_url}/v5/put",
|
f"{self._czfe_url}/v5/put",
|
||||||
json={
|
json={
|
||||||
@ -239,7 +243,7 @@ class NestThermostatAPI(NestAPI):
|
|||||||
{
|
{
|
||||||
"object_key": f'device.{self._device_id}',
|
"object_key": f'device.{self._device_id}',
|
||||||
"op": "MERGE",
|
"op": "MERGE",
|
||||||
"value": {"eco": {"mode": "manual-eco"}},
|
"value": {"eco": {"mode": mode}},
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -13,9 +13,9 @@ from homeassistant.components.climate.const import (
|
|||||||
HVAC_MODE_HEAT,
|
HVAC_MODE_HEAT,
|
||||||
HVAC_MODE_OFF,
|
HVAC_MODE_OFF,
|
||||||
SUPPORT_FAN_MODE,
|
SUPPORT_FAN_MODE,
|
||||||
|
SUPPORT_PRESET_MODE,
|
||||||
SUPPORT_TARGET_TEMPERATURE,
|
SUPPORT_TARGET_TEMPERATURE,
|
||||||
SUPPORT_TARGET_TEMPERATURE_RANGE,
|
SUPPORT_TARGET_TEMPERATURE_RANGE,
|
||||||
PRESET_AWAY,
|
|
||||||
PRESET_ECO,
|
PRESET_ECO,
|
||||||
PRESET_NONE,
|
PRESET_NONE,
|
||||||
CURRENT_HVAC_HEAT,
|
CURRENT_HVAC_HEAT,
|
||||||
@ -53,9 +53,7 @@ ACTION_NEST_TO_HASS = {
|
|||||||
|
|
||||||
MODE_NEST_TO_HASS = {v: k for k, v in MODE_HASS_TO_NEST.items()}
|
MODE_NEST_TO_HASS = {v: k for k, v in MODE_HASS_TO_NEST.items()}
|
||||||
|
|
||||||
PRESET_AWAY_AND_ECO = "Away and Eco"
|
PRESET_MODES = [PRESET_NONE, PRESET_ECO]
|
||||||
|
|
||||||
PRESET_MODES = [PRESET_NONE, PRESET_AWAY, PRESET_ECO, PRESET_AWAY_AND_ECO]
|
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -100,8 +98,7 @@ class NestClimate(ClimateDevice):
|
|||||||
self.device_id = device_id
|
self.device_id = device_id
|
||||||
|
|
||||||
# Set the default supported features
|
# Set the default supported features
|
||||||
self._support_flags = SUPPORT_TARGET_TEMPERATURE
|
self._support_flags = SUPPORT_TARGET_TEMPERATURE | SUPPORT_PRESET_MODE
|
||||||
# | SUPPORT_PRESET_MODE
|
|
||||||
|
|
||||||
# Not all nest devices support cooling and heating remove unused
|
# Not all nest devices support cooling and heating remove unused
|
||||||
self._operation_list = []
|
self._operation_list = []
|
||||||
@ -195,7 +192,9 @@ class NestClimate(ClimateDevice):
|
|||||||
@property
|
@property
|
||||||
def hvac_mode(self):
|
def hvac_mode(self):
|
||||||
"""Return hvac target hvac state."""
|
"""Return hvac target hvac state."""
|
||||||
if self.device.mode is None or self.device.mode == NEST_MODE_ECO:
|
if self.device.mode == 'unknown' \
|
||||||
|
or self.device.mode == NEST_MODE_ECO \
|
||||||
|
or self.device.mode is None:
|
||||||
# We assume the first operation in operation list is the main one
|
# We assume the first operation in operation list is the main one
|
||||||
return self._operation_list[0]
|
return self._operation_list[0]
|
||||||
|
|
||||||
@ -209,16 +208,10 @@ class NestClimate(ClimateDevice):
|
|||||||
@property
|
@property
|
||||||
def preset_mode(self):
|
def preset_mode(self):
|
||||||
"""Return current preset mode."""
|
"""Return current preset mode."""
|
||||||
if self.device.away and self.device.mode == NEST_MODE_ECO:
|
|
||||||
return PRESET_AWAY_AND_ECO
|
|
||||||
|
|
||||||
if self.device.away:
|
|
||||||
return PRESET_AWAY
|
|
||||||
|
|
||||||
if self.device.mode == NEST_MODE_ECO:
|
if self.device.mode == NEST_MODE_ECO:
|
||||||
return PRESET_ECO
|
return PRESET_ECO
|
||||||
|
|
||||||
return None
|
return PRESET_NONE
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def preset_modes(self):
|
def preset_modes(self):
|
||||||
@ -268,20 +261,11 @@ class NestClimate(ClimateDevice):
|
|||||||
|
|
||||||
def set_preset_mode(self, preset_mode):
|
def set_preset_mode(self, preset_mode):
|
||||||
"""Set preset mode."""
|
"""Set preset mode."""
|
||||||
need_away = preset_mode in (PRESET_AWAY, PRESET_AWAY_AND_ECO)
|
need_eco = preset_mode in (PRESET_ECO)
|
||||||
need_eco = preset_mode in (PRESET_ECO, PRESET_AWAY_AND_ECO)
|
|
||||||
is_away = self.device.away
|
|
||||||
is_eco = self.device.mode == NEST_MODE_ECO
|
is_eco = self.device.mode == NEST_MODE_ECO
|
||||||
|
|
||||||
if is_away != need_away:
|
|
||||||
pass
|
|
||||||
# self.device.set_away()
|
|
||||||
|
|
||||||
if is_eco != need_eco:
|
if is_eco != need_eco:
|
||||||
if need_eco:
|
self.device.set_eco_mode(need_eco)
|
||||||
self.device.set_eco_mode()
|
|
||||||
else:
|
|
||||||
self.device.mode = MODE_HASS_TO_NEST[self._operation_list[0]]
|
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Updates data"""
|
"""Updates data"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user