mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Add service set_hvac_mode (#2303)
* set hvac_mode * Update __init__.py * Update __init__.py
This commit is contained in:
parent
40840044ca
commit
1f7792678b
@ -28,6 +28,7 @@ SCAN_INTERVAL = 60
|
||||
SERVICE_SET_AWAY_MODE = "set_away_mode"
|
||||
SERVICE_SET_TEMPERATURE = "set_temperature"
|
||||
SERVICE_SET_FAN_MODE = "set_fan_mode"
|
||||
SERVICE_SET_HVAC_MODE = "set_hvac_mode"
|
||||
|
||||
STATE_HEAT = "heat"
|
||||
STATE_COOL = "cool"
|
||||
@ -36,6 +37,7 @@ STATE_IDLE = "idle"
|
||||
ATTR_CURRENT_TEMPERATURE = "current_temperature"
|
||||
ATTR_AWAY_MODE = "away_mode"
|
||||
ATTR_FAN = "fan"
|
||||
ATTR_HVAC_MODE = "hvac_mode"
|
||||
ATTR_MAX_TEMP = "max_temp"
|
||||
ATTR_MIN_TEMP = "min_temp"
|
||||
ATTR_TEMPERATURE_LOW = "target_temp_low"
|
||||
@ -56,6 +58,10 @@ SET_FAN_MODE_SCHEMA = vol.Schema({
|
||||
vol.Optional(ATTR_ENTITY_ID): cv.entity_ids,
|
||||
vol.Required(ATTR_FAN): cv.boolean,
|
||||
})
|
||||
SET_HVAC_MODE_SCHEMA = vol.Schema({
|
||||
vol.Optional(ATTR_ENTITY_ID): cv.entity_ids,
|
||||
vol.Required(ATTR_HVAC_MODE): cv.string,
|
||||
})
|
||||
|
||||
|
||||
def set_away_mode(hass, away_mode, entity_id=None):
|
||||
@ -92,6 +98,18 @@ def set_fan_mode(hass, fan_mode, entity_id=None):
|
||||
hass.services.call(DOMAIN, SERVICE_SET_FAN_MODE, data)
|
||||
|
||||
|
||||
def set_hvac_mode(hass, hvac_mode, entity_id=None):
|
||||
"""Set specified thermostat hvac mode."""
|
||||
data = {
|
||||
ATTR_HVAC_MODE: hvac_mode
|
||||
}
|
||||
|
||||
if entity_id:
|
||||
data[ATTR_ENTITY_ID] = entity_id
|
||||
|
||||
hass.services.call(DOMAIN, SERVICE_SET_HVAC_MODE, data)
|
||||
|
||||
|
||||
# pylint: disable=too-many-branches
|
||||
def setup(hass, config):
|
||||
"""Setup thermostats."""
|
||||
@ -157,6 +175,22 @@ def setup(hass, config):
|
||||
descriptions.get(SERVICE_SET_FAN_MODE),
|
||||
schema=SET_FAN_MODE_SCHEMA)
|
||||
|
||||
def hvac_mode_set_service(service):
|
||||
"""Set hvac mode on target thermostats."""
|
||||
target_thermostats = component.extract_from_service(service)
|
||||
|
||||
hvac_mode = service.data[ATTR_HVAC_MODE]
|
||||
|
||||
for thermostat in target_thermostats:
|
||||
thermostat.set_hvac_mode(hvac_mode)
|
||||
|
||||
thermostat.update_ha_state(True)
|
||||
|
||||
hass.services.register(
|
||||
DOMAIN, SERVICE_SET_HVAC_MODE, hvac_mode_set_service,
|
||||
descriptions.get(SERVICE_SET_HVAC_MODE),
|
||||
schema=SET_HVAC_MODE_SCHEMA)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
@ -243,6 +277,10 @@ class ThermostatDevice(Entity):
|
||||
"""Set new target temperature."""
|
||||
pass
|
||||
|
||||
def set_hvac_mode(self, hvac_mode):
|
||||
"""Set hvac mode."""
|
||||
pass
|
||||
|
||||
def turn_away_mode_on(self):
|
||||
"""Turn away mode on."""
|
||||
pass
|
||||
|
Loading…
x
Reference in New Issue
Block a user