mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +00:00
Black
This commit is contained in:
@@ -8,40 +8,61 @@ import voluptuous as vol
|
||||
from homeassistant.components import ecobee
|
||||
from homeassistant.components.climate import ClimateDevice
|
||||
from homeassistant.components.climate.const import (
|
||||
DOMAIN, HVAC_MODE_COOL, HVAC_MODE_HEAT, HVAC_MODE_AUTO, HVAC_MODE_OFF,
|
||||
ATTR_TARGET_TEMP_LOW, ATTR_TARGET_TEMP_HIGH, SUPPORT_TARGET_TEMPERATURE,
|
||||
SUPPORT_AUX_HEAT, SUPPORT_TARGET_TEMPERATURE_RANGE, SUPPORT_FAN_MODE,
|
||||
PRESET_AWAY, FAN_AUTO, FAN_ON, CURRENT_HVAC_IDLE, CURRENT_HVAC_HEAT,
|
||||
CURRENT_HVAC_COOL, SUPPORT_PRESET_MODE, PRESET_NONE, CURRENT_HVAC_FAN,
|
||||
DOMAIN,
|
||||
HVAC_MODE_COOL,
|
||||
HVAC_MODE_HEAT,
|
||||
HVAC_MODE_AUTO,
|
||||
HVAC_MODE_OFF,
|
||||
ATTR_TARGET_TEMP_LOW,
|
||||
ATTR_TARGET_TEMP_HIGH,
|
||||
SUPPORT_TARGET_TEMPERATURE,
|
||||
SUPPORT_AUX_HEAT,
|
||||
SUPPORT_TARGET_TEMPERATURE_RANGE,
|
||||
SUPPORT_FAN_MODE,
|
||||
PRESET_AWAY,
|
||||
FAN_AUTO,
|
||||
FAN_ON,
|
||||
CURRENT_HVAC_IDLE,
|
||||
CURRENT_HVAC_HEAT,
|
||||
CURRENT_HVAC_COOL,
|
||||
SUPPORT_PRESET_MODE,
|
||||
PRESET_NONE,
|
||||
CURRENT_HVAC_FAN,
|
||||
CURRENT_HVAC_DRY,
|
||||
)
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID, STATE_ON, ATTR_TEMPERATURE, TEMP_FAHRENHEIT)
|
||||
ATTR_ENTITY_ID,
|
||||
STATE_ON,
|
||||
ATTR_TEMPERATURE,
|
||||
TEMP_FAHRENHEIT,
|
||||
)
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
||||
_CONFIGURING = {}
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
ATTR_FAN_MIN_ON_TIME = 'fan_min_on_time'
|
||||
ATTR_RESUME_ALL = 'resume_all'
|
||||
ATTR_FAN_MIN_ON_TIME = "fan_min_on_time"
|
||||
ATTR_RESUME_ALL = "resume_all"
|
||||
|
||||
DEFAULT_RESUME_ALL = False
|
||||
PRESET_TEMPERATURE = 'temp'
|
||||
PRESET_VACATION = 'vacation'
|
||||
PRESET_HOLD_NEXT_TRANSITION = 'next_transition'
|
||||
PRESET_HOLD_INDEFINITE = 'indefinite'
|
||||
AWAY_MODE = 'awayMode'
|
||||
PRESET_HOME = 'home'
|
||||
PRESET_SLEEP = 'sleep'
|
||||
PRESET_TEMPERATURE = "temp"
|
||||
PRESET_VACATION = "vacation"
|
||||
PRESET_HOLD_NEXT_TRANSITION = "next_transition"
|
||||
PRESET_HOLD_INDEFINITE = "indefinite"
|
||||
AWAY_MODE = "awayMode"
|
||||
PRESET_HOME = "home"
|
||||
PRESET_SLEEP = "sleep"
|
||||
|
||||
# Order matters, because for reverse mapping we don't want to map HEAT to AUX
|
||||
ECOBEE_HVAC_TO_HASS = collections.OrderedDict([
|
||||
('heat', HVAC_MODE_HEAT),
|
||||
('cool', HVAC_MODE_COOL),
|
||||
('auto', HVAC_MODE_AUTO),
|
||||
('off', HVAC_MODE_OFF),
|
||||
('auxHeatOnly', HVAC_MODE_HEAT),
|
||||
])
|
||||
ECOBEE_HVAC_TO_HASS = collections.OrderedDict(
|
||||
[
|
||||
("heat", HVAC_MODE_HEAT),
|
||||
("cool", HVAC_MODE_COOL),
|
||||
("auto", HVAC_MODE_AUTO),
|
||||
("off", HVAC_MODE_OFF),
|
||||
("auxHeatOnly", HVAC_MODE_HEAT),
|
||||
]
|
||||
)
|
||||
|
||||
ECOBEE_HVAC_ACTION_TO_HASS = {
|
||||
# Map to None if we do not know how to represent.
|
||||
@@ -63,8 +84,8 @@ ECOBEE_HVAC_ACTION_TO_HASS = {
|
||||
}
|
||||
|
||||
PRESET_TO_ECOBEE_HOLD = {
|
||||
PRESET_HOLD_NEXT_TRANSITION: 'nextTransition',
|
||||
PRESET_HOLD_INDEFINITE: 'indefinite',
|
||||
PRESET_HOLD_NEXT_TRANSITION: "nextTransition",
|
||||
PRESET_HOLD_INDEFINITE: "indefinite",
|
||||
}
|
||||
|
||||
PRESET_MODES = [
|
||||
@@ -74,25 +95,33 @@ PRESET_MODES = [
|
||||
PRESET_HOME,
|
||||
PRESET_SLEEP,
|
||||
PRESET_HOLD_NEXT_TRANSITION,
|
||||
PRESET_HOLD_INDEFINITE
|
||||
PRESET_HOLD_INDEFINITE,
|
||||
]
|
||||
|
||||
SERVICE_SET_FAN_MIN_ON_TIME = 'ecobee_set_fan_min_on_time'
|
||||
SERVICE_RESUME_PROGRAM = 'ecobee_resume_program'
|
||||
SERVICE_SET_FAN_MIN_ON_TIME = "ecobee_set_fan_min_on_time"
|
||||
SERVICE_RESUME_PROGRAM = "ecobee_resume_program"
|
||||
|
||||
SET_FAN_MIN_ON_TIME_SCHEMA = vol.Schema({
|
||||
vol.Optional(ATTR_ENTITY_ID): cv.entity_ids,
|
||||
vol.Required(ATTR_FAN_MIN_ON_TIME): vol.Coerce(int),
|
||||
})
|
||||
SET_FAN_MIN_ON_TIME_SCHEMA = vol.Schema(
|
||||
{
|
||||
vol.Optional(ATTR_ENTITY_ID): cv.entity_ids,
|
||||
vol.Required(ATTR_FAN_MIN_ON_TIME): vol.Coerce(int),
|
||||
}
|
||||
)
|
||||
|
||||
RESUME_PROGRAM_SCHEMA = vol.Schema({
|
||||
vol.Optional(ATTR_ENTITY_ID): cv.entity_ids,
|
||||
vol.Optional(ATTR_RESUME_ALL, default=DEFAULT_RESUME_ALL): cv.boolean,
|
||||
})
|
||||
RESUME_PROGRAM_SCHEMA = vol.Schema(
|
||||
{
|
||||
vol.Optional(ATTR_ENTITY_ID): cv.entity_ids,
|
||||
vol.Optional(ATTR_RESUME_ALL, default=DEFAULT_RESUME_ALL): cv.boolean,
|
||||
}
|
||||
)
|
||||
|
||||
SUPPORT_FLAGS = (SUPPORT_TARGET_TEMPERATURE | SUPPORT_PRESET_MODE |
|
||||
SUPPORT_AUX_HEAT | SUPPORT_TARGET_TEMPERATURE_RANGE |
|
||||
SUPPORT_FAN_MODE)
|
||||
SUPPORT_FLAGS = (
|
||||
SUPPORT_TARGET_TEMPERATURE
|
||||
| SUPPORT_PRESET_MODE
|
||||
| SUPPORT_AUX_HEAT
|
||||
| SUPPORT_TARGET_TEMPERATURE_RANGE
|
||||
| SUPPORT_FAN_MODE
|
||||
)
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
@@ -100,12 +129,14 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
if discovery_info is None:
|
||||
return
|
||||
data = ecobee.NETWORK
|
||||
hold_temp = discovery_info['hold_temp']
|
||||
hold_temp = discovery_info["hold_temp"]
|
||||
_LOGGER.info(
|
||||
"Loading ecobee thermostat component with hold_temp set to %s",
|
||||
hold_temp)
|
||||
devices = [Thermostat(data, index, hold_temp)
|
||||
for index in range(len(data.ecobee.thermostats))]
|
||||
"Loading ecobee thermostat component with hold_temp set to %s", hold_temp
|
||||
)
|
||||
devices = [
|
||||
Thermostat(data, index, hold_temp)
|
||||
for index in range(len(data.ecobee.thermostats))
|
||||
]
|
||||
add_entities(devices)
|
||||
|
||||
def fan_min_on_time_set_service(service):
|
||||
@@ -114,8 +145,9 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
fan_min_on_time = service.data[ATTR_FAN_MIN_ON_TIME]
|
||||
|
||||
if entity_id:
|
||||
target_thermostats = [device for device in devices
|
||||
if device.entity_id in entity_id]
|
||||
target_thermostats = [
|
||||
device for device in devices if device.entity_id in entity_id
|
||||
]
|
||||
else:
|
||||
target_thermostats = devices
|
||||
|
||||
@@ -130,8 +162,9 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
resume_all = service.data.get(ATTR_RESUME_ALL)
|
||||
|
||||
if entity_id:
|
||||
target_thermostats = [device for device in devices
|
||||
if device.entity_id in entity_id]
|
||||
target_thermostats = [
|
||||
device for device in devices if device.entity_id in entity_id
|
||||
]
|
||||
else:
|
||||
target_thermostats = devices
|
||||
|
||||
@@ -141,12 +174,18 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
thermostat.schedule_update_ha_state(True)
|
||||
|
||||
hass.services.register(
|
||||
DOMAIN, SERVICE_SET_FAN_MIN_ON_TIME, fan_min_on_time_set_service,
|
||||
schema=SET_FAN_MIN_ON_TIME_SCHEMA)
|
||||
DOMAIN,
|
||||
SERVICE_SET_FAN_MIN_ON_TIME,
|
||||
fan_min_on_time_set_service,
|
||||
schema=SET_FAN_MIN_ON_TIME_SCHEMA,
|
||||
)
|
||||
|
||||
hass.services.register(
|
||||
DOMAIN, SERVICE_RESUME_PROGRAM, resume_program_set_service,
|
||||
schema=RESUME_PROGRAM_SCHEMA)
|
||||
DOMAIN,
|
||||
SERVICE_RESUME_PROGRAM,
|
||||
resume_program_set_service,
|
||||
schema=RESUME_PROGRAM_SCHEMA,
|
||||
)
|
||||
|
||||
|
||||
class Thermostat(ClimateDevice):
|
||||
@@ -156,17 +195,16 @@ class Thermostat(ClimateDevice):
|
||||
"""Initialize the thermostat."""
|
||||
self.data = data
|
||||
self.thermostat_index = thermostat_index
|
||||
self.thermostat = self.data.ecobee.get_thermostat(
|
||||
self.thermostat_index)
|
||||
self._name = self.thermostat['name']
|
||||
self.thermostat = self.data.ecobee.get_thermostat(self.thermostat_index)
|
||||
self._name = self.thermostat["name"]
|
||||
self.hold_temp = hold_temp
|
||||
self.vacation = None
|
||||
self._climate_list = self.climate_list
|
||||
|
||||
self._operation_list = []
|
||||
if self.thermostat['settings']['heatStages']:
|
||||
if self.thermostat["settings"]["heatStages"]:
|
||||
self._operation_list.append(HVAC_MODE_HEAT)
|
||||
if self.thermostat['settings']['coolStages']:
|
||||
if self.thermostat["settings"]["coolStages"]:
|
||||
self._operation_list.append(HVAC_MODE_COOL)
|
||||
if len(self._operation_list) == 2:
|
||||
self._operation_list.insert(0, HVAC_MODE_AUTO)
|
||||
@@ -183,8 +221,7 @@ class Thermostat(ClimateDevice):
|
||||
else:
|
||||
self.data.update()
|
||||
|
||||
self.thermostat = self.data.ecobee.get_thermostat(
|
||||
self.thermostat_index)
|
||||
self.thermostat = self.data.ecobee.get_thermostat(self.thermostat_index)
|
||||
|
||||
@property
|
||||
def supported_features(self):
|
||||
@@ -194,7 +231,7 @@ class Thermostat(ClimateDevice):
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the Ecobee Thermostat."""
|
||||
return self.thermostat['name']
|
||||
return self.thermostat["name"]
|
||||
|
||||
@property
|
||||
def temperature_unit(self):
|
||||
@@ -204,20 +241,20 @@ class Thermostat(ClimateDevice):
|
||||
@property
|
||||
def current_temperature(self):
|
||||
"""Return the current temperature."""
|
||||
return self.thermostat['runtime']['actualTemperature'] / 10.0
|
||||
return self.thermostat["runtime"]["actualTemperature"] / 10.0
|
||||
|
||||
@property
|
||||
def target_temperature_low(self):
|
||||
"""Return the lower bound temperature we try to reach."""
|
||||
if self.hvac_mode == HVAC_MODE_AUTO:
|
||||
return self.thermostat['runtime']['desiredHeat'] / 10.0
|
||||
return self.thermostat["runtime"]["desiredHeat"] / 10.0
|
||||
return None
|
||||
|
||||
@property
|
||||
def target_temperature_high(self):
|
||||
"""Return the upper bound temperature we try to reach."""
|
||||
if self.hvac_mode == HVAC_MODE_AUTO:
|
||||
return self.thermostat['runtime']['desiredCool'] / 10.0
|
||||
return self.thermostat["runtime"]["desiredCool"] / 10.0
|
||||
return None
|
||||
|
||||
@property
|
||||
@@ -226,22 +263,22 @@ class Thermostat(ClimateDevice):
|
||||
if self.hvac_mode == HVAC_MODE_AUTO:
|
||||
return None
|
||||
if self.hvac_mode == HVAC_MODE_HEAT:
|
||||
return self.thermostat['runtime']['desiredHeat'] / 10.0
|
||||
return self.thermostat["runtime"]["desiredHeat"] / 10.0
|
||||
if self.hvac_mode == HVAC_MODE_COOL:
|
||||
return self.thermostat['runtime']['desiredCool'] / 10.0
|
||||
return self.thermostat["runtime"]["desiredCool"] / 10.0
|
||||
return None
|
||||
|
||||
@property
|
||||
def fan(self):
|
||||
"""Return the current fan status."""
|
||||
if 'fan' in self.thermostat['equipmentStatus']:
|
||||
if "fan" in self.thermostat["equipmentStatus"]:
|
||||
return STATE_ON
|
||||
return HVAC_MODE_OFF
|
||||
|
||||
@property
|
||||
def fan_mode(self):
|
||||
"""Return the fan setting."""
|
||||
return self.thermostat['runtime']['desiredFanMode']
|
||||
return self.thermostat["runtime"]["desiredFanMode"]
|
||||
|
||||
@property
|
||||
def fan_modes(self):
|
||||
@@ -251,29 +288,28 @@ class Thermostat(ClimateDevice):
|
||||
@property
|
||||
def preset_mode(self):
|
||||
"""Return current preset mode."""
|
||||
events = self.thermostat['events']
|
||||
events = self.thermostat["events"]
|
||||
for event in events:
|
||||
if not event['running']:
|
||||
if not event["running"]:
|
||||
continue
|
||||
|
||||
if event['type'] == 'hold':
|
||||
if event['holdClimateRef'] == 'away':
|
||||
if int(event['endDate'][0:4]) - \
|
||||
int(event['startDate'][0:4]) <= 1:
|
||||
if event["type"] == "hold":
|
||||
if event["holdClimateRef"] == "away":
|
||||
if int(event["endDate"][0:4]) - int(event["startDate"][0:4]) <= 1:
|
||||
# A temporary hold from away climate is a hold
|
||||
return PRESET_AWAY
|
||||
# A permanent hold from away climate
|
||||
return PRESET_AWAY
|
||||
if event['holdClimateRef'] != "":
|
||||
if event["holdClimateRef"] != "":
|
||||
# Any other hold based on climate
|
||||
return event['holdClimateRef']
|
||||
return event["holdClimateRef"]
|
||||
# Any hold not based on a climate is a temp hold
|
||||
return PRESET_TEMPERATURE
|
||||
if event['type'].startswith('auto'):
|
||||
if event["type"].startswith("auto"):
|
||||
# All auto modes are treated as holds
|
||||
return event['type'][4:].lower()
|
||||
if event['type'] == 'vacation':
|
||||
self.vacation = event['name']
|
||||
return event["type"][4:].lower()
|
||||
if event["type"] == "vacation":
|
||||
self.vacation = event["name"]
|
||||
return PRESET_VACATION
|
||||
|
||||
return None
|
||||
@@ -281,7 +317,7 @@ class Thermostat(ClimateDevice):
|
||||
@property
|
||||
def hvac_mode(self):
|
||||
"""Return current operation."""
|
||||
return ECOBEE_HVAC_TO_HASS[self.thermostat['settings']['hvacMode']]
|
||||
return ECOBEE_HVAC_TO_HASS[self.thermostat["settings"]["hvacMode"]]
|
||||
|
||||
@property
|
||||
def hvac_modes(self):
|
||||
@@ -291,15 +327,15 @@ class Thermostat(ClimateDevice):
|
||||
@property
|
||||
def climate_mode(self):
|
||||
"""Return current mode, as the user-visible name."""
|
||||
cur = self.thermostat['program']['currentClimateRef']
|
||||
climates = self.thermostat['program']['climates']
|
||||
current = list(filter(lambda x: x['climateRef'] == cur, climates))
|
||||
return current[0]['name']
|
||||
cur = self.thermostat["program"]["currentClimateRef"]
|
||||
climates = self.thermostat["program"]["climates"]
|
||||
current = list(filter(lambda x: x["climateRef"] == cur, climates))
|
||||
return current[0]["name"]
|
||||
|
||||
@property
|
||||
def current_humidity(self) -> Optional[int]:
|
||||
"""Return the current humidity."""
|
||||
return self.thermostat['runtime']['actualHumidity']
|
||||
return self.thermostat["runtime"]["actualHumidity"]
|
||||
|
||||
@property
|
||||
def hvac_action(self):
|
||||
@@ -311,17 +347,21 @@ class Thermostat(ClimateDevice):
|
||||
|
||||
We are unable to map all actions to HA equivalents.
|
||||
"""
|
||||
if self.thermostat['equipmentStatus'] == "":
|
||||
if self.thermostat["equipmentStatus"] == "":
|
||||
return CURRENT_HVAC_IDLE
|
||||
|
||||
actions = [
|
||||
ECOBEE_HVAC_ACTION_TO_HASS[status] for status in
|
||||
self.thermostat['equipmentStatus'].split(",")
|
||||
ECOBEE_HVAC_ACTION_TO_HASS[status]
|
||||
for status in self.thermostat["equipmentStatus"].split(",")
|
||||
if ECOBEE_HVAC_ACTION_TO_HASS[status] is not None
|
||||
]
|
||||
|
||||
for action in (CURRENT_HVAC_HEAT, CURRENT_HVAC_COOL,
|
||||
CURRENT_HVAC_DRY, CURRENT_HVAC_FAN):
|
||||
for action in (
|
||||
CURRENT_HVAC_HEAT,
|
||||
CURRENT_HVAC_COOL,
|
||||
CURRENT_HVAC_DRY,
|
||||
CURRENT_HVAC_FAN,
|
||||
):
|
||||
if action in actions:
|
||||
return action
|
||||
|
||||
@@ -330,19 +370,19 @@ class Thermostat(ClimateDevice):
|
||||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return device specific state attributes."""
|
||||
status = self.thermostat['equipmentStatus']
|
||||
status = self.thermostat["equipmentStatus"]
|
||||
return {
|
||||
"fan": self.fan,
|
||||
"climate_mode": self.climate_mode,
|
||||
"equipment_running": status,
|
||||
"climate_list": self.climate_list,
|
||||
"fan_min_on_time": self.thermostat['settings']['fanMinOnTime']
|
||||
"fan_min_on_time": self.thermostat["settings"]["fanMinOnTime"],
|
||||
}
|
||||
|
||||
@property
|
||||
def is_aux_heat(self):
|
||||
"""Return true if aux heater."""
|
||||
return 'auxHeat' in self.thermostat['equipmentStatus']
|
||||
return "auxHeat" in self.thermostat["equipmentStatus"]
|
||||
|
||||
def set_preset_mode(self, preset_mode):
|
||||
"""Activate a preset."""
|
||||
@@ -353,28 +393,30 @@ class Thermostat(ClimateDevice):
|
||||
|
||||
# If we are currently in vacation mode, cancel it.
|
||||
if self.preset_mode == PRESET_VACATION:
|
||||
self.data.ecobee.delete_vacation(
|
||||
self.thermostat_index, self.vacation)
|
||||
self.data.ecobee.delete_vacation(self.thermostat_index, self.vacation)
|
||||
|
||||
if preset_mode == PRESET_AWAY:
|
||||
self.data.ecobee.set_climate_hold(self.thermostat_index, 'away',
|
||||
'indefinite')
|
||||
self.data.ecobee.set_climate_hold(
|
||||
self.thermostat_index, "away", "indefinite"
|
||||
)
|
||||
|
||||
elif preset_mode == PRESET_TEMPERATURE:
|
||||
self.set_temp_hold(self.current_temperature)
|
||||
|
||||
elif preset_mode in (
|
||||
PRESET_HOLD_NEXT_TRANSITION, PRESET_HOLD_INDEFINITE):
|
||||
elif preset_mode in (PRESET_HOLD_NEXT_TRANSITION, PRESET_HOLD_INDEFINITE):
|
||||
self.data.ecobee.set_climate_hold(
|
||||
self.thermostat_index, PRESET_TO_ECOBEE_HOLD[preset_mode],
|
||||
self.hold_preference())
|
||||
self.thermostat_index,
|
||||
PRESET_TO_ECOBEE_HOLD[preset_mode],
|
||||
self.hold_preference(),
|
||||
)
|
||||
|
||||
elif preset_mode == PRESET_NONE:
|
||||
self.data.ecobee.resume_program(self.thermostat_index)
|
||||
|
||||
else:
|
||||
self.data.ecobee.set_climate_hold(
|
||||
self.thermostat_index, preset_mode, self.hold_preference())
|
||||
self.thermostat_index, preset_mode, self.hold_preference()
|
||||
)
|
||||
|
||||
@property
|
||||
def preset_modes(self):
|
||||
@@ -386,38 +428,45 @@ class Thermostat(ClimateDevice):
|
||||
if cool_temp is not None:
|
||||
cool_temp_setpoint = cool_temp
|
||||
else:
|
||||
cool_temp_setpoint = (
|
||||
self.thermostat['runtime']['desiredCool'] / 10.0)
|
||||
cool_temp_setpoint = self.thermostat["runtime"]["desiredCool"] / 10.0
|
||||
|
||||
if heat_temp is not None:
|
||||
heat_temp_setpoint = heat_temp
|
||||
else:
|
||||
heat_temp_setpoint = (
|
||||
self.thermostat['runtime']['desiredCool'] / 10.0)
|
||||
heat_temp_setpoint = self.thermostat["runtime"]["desiredCool"] / 10.0
|
||||
|
||||
self.data.ecobee.set_hold_temp(self.thermostat_index,
|
||||
cool_temp_setpoint, heat_temp_setpoint,
|
||||
self.hold_preference())
|
||||
_LOGGER.debug("Setting ecobee hold_temp to: heat=%s, is=%s, "
|
||||
"cool=%s, is=%s", heat_temp,
|
||||
isinstance(heat_temp, (int, float)), cool_temp,
|
||||
isinstance(cool_temp, (int, float)))
|
||||
self.data.ecobee.set_hold_temp(
|
||||
self.thermostat_index,
|
||||
cool_temp_setpoint,
|
||||
heat_temp_setpoint,
|
||||
self.hold_preference(),
|
||||
)
|
||||
_LOGGER.debug(
|
||||
"Setting ecobee hold_temp to: heat=%s, is=%s, " "cool=%s, is=%s",
|
||||
heat_temp,
|
||||
isinstance(heat_temp, (int, float)),
|
||||
cool_temp,
|
||||
isinstance(cool_temp, (int, float)),
|
||||
)
|
||||
|
||||
self.update_without_throttle = True
|
||||
|
||||
def set_fan_mode(self, fan_mode):
|
||||
"""Set the fan mode. Valid values are "on" or "auto"."""
|
||||
if fan_mode.lower() != STATE_ON and \
|
||||
fan_mode.lower() != HVAC_MODE_AUTO:
|
||||
if fan_mode.lower() != STATE_ON and fan_mode.lower() != HVAC_MODE_AUTO:
|
||||
error = "Invalid fan_mode value: Valid values are 'on' or 'auto'"
|
||||
_LOGGER.error(error)
|
||||
return
|
||||
|
||||
cool_temp = self.thermostat['runtime']['desiredCool'] / 10.0
|
||||
heat_temp = self.thermostat['runtime']['desiredHeat'] / 10.0
|
||||
self.data.ecobee.set_fan_mode(self.thermostat_index, fan_mode,
|
||||
cool_temp, heat_temp,
|
||||
self.hold_preference())
|
||||
cool_temp = self.thermostat["runtime"]["desiredCool"] / 10.0
|
||||
heat_temp = self.thermostat["runtime"]["desiredHeat"] / 10.0
|
||||
self.data.ecobee.set_fan_mode(
|
||||
self.thermostat_index,
|
||||
fan_mode,
|
||||
cool_temp,
|
||||
heat_temp,
|
||||
self.hold_preference(),
|
||||
)
|
||||
|
||||
_LOGGER.info("Setting fan mode to: %s", fan_mode)
|
||||
|
||||
@@ -432,12 +481,11 @@ class Thermostat(ClimateDevice):
|
||||
heatCoolMinDelta property.
|
||||
https://www.ecobee.com/home/developer/api/examples/ex5.shtml
|
||||
"""
|
||||
if self.hvac_mode == HVAC_MODE_HEAT or \
|
||||
self.hvac_mode == HVAC_MODE_COOL:
|
||||
if self.hvac_mode == HVAC_MODE_HEAT or self.hvac_mode == HVAC_MODE_COOL:
|
||||
heat_temp = temp
|
||||
cool_temp = temp
|
||||
else:
|
||||
delta = self.thermostat['settings']['heatCoolMinDelta'] / 10
|
||||
delta = self.thermostat["settings"]["heatCoolMinDelta"] / 10
|
||||
heat_temp = temp - delta
|
||||
cool_temp = temp + delta
|
||||
self.set_auto_temp_hold(heat_temp, cool_temp)
|
||||
@@ -448,14 +496,14 @@ class Thermostat(ClimateDevice):
|
||||
high_temp = kwargs.get(ATTR_TARGET_TEMP_HIGH)
|
||||
temp = kwargs.get(ATTR_TEMPERATURE)
|
||||
|
||||
if self.hvac_mode == HVAC_MODE_AUTO and \
|
||||
(low_temp is not None or high_temp is not None):
|
||||
if self.hvac_mode == HVAC_MODE_AUTO and (
|
||||
low_temp is not None or high_temp is not None
|
||||
):
|
||||
self.set_auto_temp_hold(low_temp, high_temp)
|
||||
elif temp is not None:
|
||||
self.set_temp_hold(temp)
|
||||
else:
|
||||
_LOGGER.error(
|
||||
"Missing valid arguments for set_temperature in %s", kwargs)
|
||||
_LOGGER.error("Missing valid arguments for set_temperature in %s", kwargs)
|
||||
|
||||
def set_humidity(self, humidity):
|
||||
"""Set the humidity level."""
|
||||
@@ -463,8 +511,9 @@ class Thermostat(ClimateDevice):
|
||||
|
||||
def set_hvac_mode(self, hvac_mode):
|
||||
"""Set HVAC mode (auto, auxHeatOnly, cool, heat, off)."""
|
||||
ecobee_value = next((k for k, v in ECOBEE_HVAC_TO_HASS.items()
|
||||
if v == hvac_mode), None)
|
||||
ecobee_value = next(
|
||||
(k for k, v in ECOBEE_HVAC_TO_HASS.items() if v == hvac_mode), None
|
||||
)
|
||||
if ecobee_value is None:
|
||||
_LOGGER.error("Invalid mode for set_hvac_mode: %s", hvac_mode)
|
||||
return
|
||||
@@ -473,30 +522,30 @@ class Thermostat(ClimateDevice):
|
||||
|
||||
def set_fan_min_on_time(self, fan_min_on_time):
|
||||
"""Set the minimum fan on time."""
|
||||
self.data.ecobee.set_fan_min_on_time(
|
||||
self.thermostat_index, fan_min_on_time)
|
||||
self.data.ecobee.set_fan_min_on_time(self.thermostat_index, fan_min_on_time)
|
||||
self.update_without_throttle = True
|
||||
|
||||
def resume_program(self, resume_all):
|
||||
"""Resume the thermostat schedule program."""
|
||||
self.data.ecobee.resume_program(
|
||||
self.thermostat_index, 'true' if resume_all else 'false')
|
||||
self.thermostat_index, "true" if resume_all else "false"
|
||||
)
|
||||
self.update_without_throttle = True
|
||||
|
||||
def hold_preference(self):
|
||||
"""Return user preference setting for hold time."""
|
||||
# Values returned from thermostat are 'useEndTime4hour',
|
||||
# 'useEndTime2hour', 'nextTransition', 'indefinite', 'askMe'
|
||||
default = self.thermostat['settings']['holdAction']
|
||||
if default == 'nextTransition':
|
||||
default = self.thermostat["settings"]["holdAction"]
|
||||
if default == "nextTransition":
|
||||
return default
|
||||
# add further conditions if other hold durations should be
|
||||
# supported; note that this should not include 'indefinite'
|
||||
# as an indefinite away hold is interpreted as away_mode
|
||||
return 'nextTransition'
|
||||
return "nextTransition"
|
||||
|
||||
@property
|
||||
def climate_list(self):
|
||||
"""Return the list of climates currently available."""
|
||||
climates = self.thermostat['program']['climates']
|
||||
return list(map((lambda x: x['name']), climates))
|
||||
climates = self.thermostat["program"]["climates"]
|
||||
return list(map((lambda x: x["name"]), climates))
|
||||
|
||||
Reference in New Issue
Block a user