mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
thermostat: split up services
This commit is contained in:
parent
df450c3d1f
commit
afa4fc4ef5
@ -75,51 +75,54 @@ def setup(hass, config):
|
|||||||
SCAN_INTERVAL, DISCOVERY_PLATFORMS)
|
SCAN_INTERVAL, DISCOVERY_PLATFORMS)
|
||||||
component.setup(config)
|
component.setup(config)
|
||||||
|
|
||||||
def thermostat_service(service):
|
|
||||||
""" Handles calls to the services. """
|
|
||||||
|
|
||||||
# Convert the entity ids to valid light ids
|
|
||||||
target_thermostats = component.extract_from_service(service)
|
|
||||||
|
|
||||||
if service.service == SERVICE_SET_AWAY_MODE:
|
|
||||||
away_mode = service.data.get(ATTR_AWAY_MODE)
|
|
||||||
|
|
||||||
if away_mode is None:
|
|
||||||
_LOGGER.error(
|
|
||||||
"Received call to %s without attribute %s",
|
|
||||||
SERVICE_SET_AWAY_MODE, ATTR_AWAY_MODE)
|
|
||||||
|
|
||||||
elif away_mode:
|
|
||||||
for thermostat in target_thermostats:
|
|
||||||
thermostat.turn_away_mode_on()
|
|
||||||
else:
|
|
||||||
for thermostat in target_thermostats:
|
|
||||||
thermostat.turn_away_mode_off()
|
|
||||||
|
|
||||||
elif service.service == SERVICE_SET_TEMPERATURE:
|
|
||||||
temperature = util.convert(
|
|
||||||
service.data.get(ATTR_TEMPERATURE), float)
|
|
||||||
|
|
||||||
if temperature is None:
|
|
||||||
return
|
|
||||||
|
|
||||||
for thermostat in target_thermostats:
|
|
||||||
thermostat.set_temperature(convert(
|
|
||||||
temperature, hass.config.temperature_unit,
|
|
||||||
thermostat.unit_of_measurement))
|
|
||||||
|
|
||||||
for thermostat in target_thermostats:
|
|
||||||
thermostat.update_ha_state(True)
|
|
||||||
|
|
||||||
descriptions = load_yaml_config_file(
|
descriptions = load_yaml_config_file(
|
||||||
os.path.join(os.path.dirname(__file__), 'services.yaml'))
|
os.path.join(os.path.dirname(__file__), 'services.yaml'))
|
||||||
|
|
||||||
hass.services.register(
|
def away_mode_set_service(service):
|
||||||
DOMAIN, SERVICE_SET_AWAY_MODE, thermostat_service,
|
""" Set away mode on target thermostats """
|
||||||
descriptions.get(SERVICE_SET_AWAY_MODE))
|
|
||||||
|
target_thermostats = component.extract_from_service(service)
|
||||||
|
|
||||||
|
away_mode = service.data.get(ATTR_AWAY_MODE)
|
||||||
|
|
||||||
|
if away_mode is None:
|
||||||
|
_LOGGER.error(
|
||||||
|
"Received call to %s without attribute %s",
|
||||||
|
SERVICE_SET_AWAY_MODE, ATTR_AWAY_MODE)
|
||||||
|
return
|
||||||
|
|
||||||
|
for thermostat in target_thermostats:
|
||||||
|
if away_mode:
|
||||||
|
thermostat.turn_away_mode_on()
|
||||||
|
else:
|
||||||
|
thermostat.turn_away_mode_off()
|
||||||
|
|
||||||
|
thermostat.update_ha_state(True)
|
||||||
|
|
||||||
hass.services.register(
|
hass.services.register(
|
||||||
DOMAIN, SERVICE_SET_TEMPERATURE, thermostat_service,
|
DOMAIN, SERVICE_SET_AWAY_MODE, away_mode_set_service,
|
||||||
|
descriptions.get(SERVICE_SET_AWAY_MODE))
|
||||||
|
|
||||||
|
def temperature_set_service(service):
|
||||||
|
""" Set temperature on the target thermostats """
|
||||||
|
|
||||||
|
target_thermostats = component.extract_from_service(service)
|
||||||
|
|
||||||
|
temperature = util.convert(
|
||||||
|
service.data.get(ATTR_TEMPERATURE), float)
|
||||||
|
|
||||||
|
if temperature is None:
|
||||||
|
return
|
||||||
|
|
||||||
|
for thermostat in target_thermostats:
|
||||||
|
thermostat.set_temperature(convert(
|
||||||
|
temperature, hass.config.temperature_unit,
|
||||||
|
thermostat.unit_of_measurement))
|
||||||
|
|
||||||
|
thermostat.update_ha_state(True)
|
||||||
|
|
||||||
|
hass.services.register(
|
||||||
|
DOMAIN, SERVICE_SET_TEMPERATURE, temperature_set_service,
|
||||||
descriptions.get(SERVICE_SET_TEMPERATURE))
|
descriptions.get(SERVICE_SET_TEMPERATURE))
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
Loading…
x
Reference in New Issue
Block a user