mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
thermostat: add service to control fan mode
This commit is contained in:
parent
a0ed469aa2
commit
df94c909f7
@ -27,6 +27,7 @@ SCAN_INTERVAL = 60
|
|||||||
|
|
||||||
SERVICE_SET_AWAY_MODE = "set_away_mode"
|
SERVICE_SET_AWAY_MODE = "set_away_mode"
|
||||||
SERVICE_SET_TEMPERATURE = "set_temperature"
|
SERVICE_SET_TEMPERATURE = "set_temperature"
|
||||||
|
SERVICE_SET_FAN_MODE = "set_fan_mode"
|
||||||
|
|
||||||
STATE_HEAT = "heat"
|
STATE_HEAT = "heat"
|
||||||
STATE_COOL = "cool"
|
STATE_COOL = "cool"
|
||||||
@ -70,6 +71,19 @@ def set_temperature(hass, temperature, entity_id=None):
|
|||||||
hass.services.call(DOMAIN, SERVICE_SET_TEMPERATURE, data)
|
hass.services.call(DOMAIN, SERVICE_SET_TEMPERATURE, data)
|
||||||
|
|
||||||
|
|
||||||
|
def set_fan_mode(hass, fan_mode, entity_id=None):
|
||||||
|
""" Turn all or specified thermostat fan mode on. """
|
||||||
|
data = {
|
||||||
|
ATTR_FAN: fan_mode
|
||||||
|
}
|
||||||
|
|
||||||
|
if entity_id:
|
||||||
|
data[ATTR_ENTITY_ID] = entity_id
|
||||||
|
|
||||||
|
hass.services.call(DOMAIN, SERVICE_SET_FAN_MODE, data)
|
||||||
|
|
||||||
|
|
||||||
|
# pylint: disable=too-many-branches
|
||||||
def setup(hass, config):
|
def setup(hass, config):
|
||||||
""" Setup thermostats. """
|
""" Setup thermostats. """
|
||||||
component = EntityComponent(_LOGGER, DOMAIN, hass,
|
component = EntityComponent(_LOGGER, DOMAIN, hass,
|
||||||
@ -126,6 +140,31 @@ def setup(hass, config):
|
|||||||
DOMAIN, SERVICE_SET_TEMPERATURE, temperature_set_service,
|
DOMAIN, SERVICE_SET_TEMPERATURE, temperature_set_service,
|
||||||
descriptions.get(SERVICE_SET_TEMPERATURE))
|
descriptions.get(SERVICE_SET_TEMPERATURE))
|
||||||
|
|
||||||
|
def fan_mode_set_service(service):
|
||||||
|
""" Set fan mode on target thermostats """
|
||||||
|
|
||||||
|
target_thermostats = component.extract_from_service(service)
|
||||||
|
|
||||||
|
fan_mode = service.data.get(ATTR_FAN)
|
||||||
|
|
||||||
|
if fan_mode is None:
|
||||||
|
_LOGGER.error(
|
||||||
|
"Received call to %s without attribute %s",
|
||||||
|
SERVICE_SET_FAN_MODE, ATTR_FAN)
|
||||||
|
return
|
||||||
|
|
||||||
|
for thermostat in target_thermostats:
|
||||||
|
if fan_mode:
|
||||||
|
thermostat.turn_fan_on()
|
||||||
|
else:
|
||||||
|
thermostat.turn_fan_off()
|
||||||
|
|
||||||
|
thermostat.update_ha_state(True)
|
||||||
|
|
||||||
|
hass.services.register(
|
||||||
|
DOMAIN, SERVICE_SET_FAN_MODE, fan_mode_set_service,
|
||||||
|
descriptions.get(SERVICE_SET_FAN_MODE))
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
@ -237,6 +276,14 @@ class ThermostatDevice(Entity):
|
|||||||
""" Turns away mode off. """
|
""" Turns away mode off. """
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def turn_fan_on(self):
|
||||||
|
""" Turns fan on. """
|
||||||
|
pass
|
||||||
|
|
||||||
|
def turn_fan_off(self):
|
||||||
|
""" Turns fan off. """
|
||||||
|
pass
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def min_temp(self):
|
def min_temp(self):
|
||||||
""" Return minimum temperature. """
|
""" Return minimum temperature. """
|
||||||
|
@ -22,3 +22,15 @@ set_temperature:
|
|||||||
temperature:
|
temperature:
|
||||||
description: New target temperature for thermostat
|
description: New target temperature for thermostat
|
||||||
example: 25
|
example: 25
|
||||||
|
|
||||||
|
set_fan_mode:
|
||||||
|
description: Turn fan on/off for a thermostat
|
||||||
|
|
||||||
|
fields:
|
||||||
|
entity_id:
|
||||||
|
description: Name(s) of entities to change
|
||||||
|
example: 'thermostat.nest'
|
||||||
|
|
||||||
|
fan:
|
||||||
|
description: New value of fan mode
|
||||||
|
example: true
|
||||||
|
Loading…
x
Reference in New Issue
Block a user