mirror of
https://github.com/USA-RedDragon/badnest.git
synced 2025-01-18 12:55:25 +00:00
Merge pull request #56 from chrismarcellino/master
Add target humidity support to allow automation
This commit is contained in:
commit
1069805ed8
@ -261,6 +261,10 @@ class NestAPI():
|
||||
sensor_data["fan_timer_timeout"]
|
||||
self.device_data[sn]['current_humidity'] = \
|
||||
sensor_data["current_humidity"]
|
||||
self.device_data[sn]['target_humidity'] = \
|
||||
sensor_data["target_humidity"]
|
||||
self.device_data[sn]['target_humidity_enabled'] = \
|
||||
sensor_data["target_humidity_enabled"]
|
||||
if sensor_data["eco"]["mode"] == 'manual-eco' or \
|
||||
sensor_data["eco"]["mode"] == 'auto-eco':
|
||||
self.device_data[sn]['eco'] = True
|
||||
@ -371,6 +375,33 @@ class NestAPI():
|
||||
self.login()
|
||||
self.thermostat_set_temperature(device_id, temp, temp_high)
|
||||
|
||||
def thermostat_set_target_humidity(self, device_id, humidity):
|
||||
if device_id not in self.thermostats:
|
||||
return
|
||||
|
||||
try:
|
||||
self._session.post(
|
||||
f"{self._czfe_url}/v5/put",
|
||||
json={
|
||||
"objects": [
|
||||
{
|
||||
"object_key": f'device.{device_id}',
|
||||
"op": "MERGE",
|
||||
"value": {"target_humidity": humidity},
|
||||
}
|
||||
]
|
||||
},
|
||||
headers={"Authorization": f"Basic {self._access_token}"},
|
||||
)
|
||||
except requests.exceptions.RequestException as e:
|
||||
_LOGGER.error(e)
|
||||
_LOGGER.error('Failed to set humidity, trying again')
|
||||
self.thermostat_set_target_humidity(device_id, humidity)
|
||||
except KeyError:
|
||||
_LOGGER.debug('Failed to set humidity, trying to log in again')
|
||||
self.login()
|
||||
self.thermostat_set_target_humidity(device_id, humidity)
|
||||
|
||||
def thermostat_set_mode(self, device_id, mode):
|
||||
if device_id not in self.thermostats:
|
||||
return
|
||||
|
@ -16,6 +16,7 @@ from homeassistant.components.climate.const import (
|
||||
SUPPORT_PRESET_MODE,
|
||||
SUPPORT_TARGET_TEMPERATURE,
|
||||
SUPPORT_TARGET_TEMPERATURE_RANGE,
|
||||
SUPPORT_TARGET_HUMIDITY,
|
||||
PRESET_ECO,
|
||||
PRESET_NONE,
|
||||
CURRENT_HVAC_HEAT,
|
||||
@ -52,6 +53,10 @@ ACTION_NEST_TO_HASS = {
|
||||
|
||||
MODE_NEST_TO_HASS = {v: k for k, v in MODE_HASS_TO_NEST.items()}
|
||||
|
||||
ROUND_TARGET_HUMIDITY_TO_NEAREST = 5
|
||||
NEST_HUMIDITY_MIN = 10
|
||||
NEST_HUMIDITY_MAX = 60
|
||||
|
||||
PRESET_MODES = [PRESET_NONE, PRESET_ECO]
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
@ -109,6 +114,10 @@ class NestClimate(ClimateDevice):
|
||||
if self.device.device_data[device_id]['has_fan']:
|
||||
self._support_flags = self._support_flags | SUPPORT_FAN_MODE
|
||||
|
||||
if self.device.device_data[device_id]['target_humidity_enabled']:
|
||||
self._support_flags = self._support_flags | SUPPORT_TARGET_HUMIDITY
|
||||
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
"""Return an unique ID."""
|
||||
@ -144,6 +153,21 @@ class NestClimate(ClimateDevice):
|
||||
"""Return the current humidity."""
|
||||
return self.device.device_data[self.device_id]['current_humidity']
|
||||
|
||||
@property
|
||||
def target_humidity(self):
|
||||
"""Return the target humidity."""
|
||||
return self.device.device_data[self.device_id]['target_humidity']
|
||||
|
||||
@property
|
||||
def min_humidity(self):
|
||||
"""Return the min target humidity."""
|
||||
return NEST_HUMIDITY_MIN
|
||||
|
||||
@property
|
||||
def max_humidity(self):
|
||||
"""Return the max target humidity."""
|
||||
return NEST_HUMIDITY_MAX
|
||||
|
||||
@property
|
||||
def target_temperature(self):
|
||||
"""Return the temperature we try to reach."""
|
||||
@ -253,6 +277,18 @@ class NestClimate(ClimateDevice):
|
||||
temp,
|
||||
)
|
||||
|
||||
def set_humidity(self, humidity):
|
||||
"""Set new target humidity."""
|
||||
humidity = int(round(float(humidity) / ROUND_TARGET_HUMIDITY_TO_NEAREST) * ROUND_TARGET_HUMIDITY_TO_NEAREST)
|
||||
if humidity < NEST_HUMIDITY_MIN:
|
||||
humidity = NEST_HUMIDITY_MIN
|
||||
if humidity > NEST_HUMIDITY_MAX:
|
||||
humidity = NEST_HUMIDITY_MAX
|
||||
self.device.thermostat_set_target_humidity(
|
||||
self.device_id,
|
||||
humidity,
|
||||
)
|
||||
|
||||
def set_hvac_mode(self, hvac_mode):
|
||||
"""Set operation mode."""
|
||||
self.device.thermostat_set_mode(
|
||||
|
Loading…
Reference in New Issue
Block a user