mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 19:27:45 +00:00
Service validation for the thermostat component.
This commit is contained in:
parent
05469e6d9b
commit
730514cea8
@ -7,14 +7,16 @@ https://home-assistant.io/components/thermostat/
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.helpers.entity_component import EntityComponent
|
from homeassistant.helpers.entity_component import EntityComponent
|
||||||
|
|
||||||
from homeassistant.config import load_yaml_config_file
|
from homeassistant.config import load_yaml_config_file
|
||||||
import homeassistant.util as util
|
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
from homeassistant.helpers.temperature import convert
|
from homeassistant.helpers.temperature import convert
|
||||||
from homeassistant.helpers.config_validation import PLATFORM_SCHEMA # noqa
|
from homeassistant.helpers.config_validation import PLATFORM_SCHEMA # noqa
|
||||||
from homeassistant.components import (ecobee, zwave)
|
from homeassistant.components import (ecobee, zwave)
|
||||||
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_ENTITY_ID, ATTR_TEMPERATURE, STATE_ON, STATE_OFF, STATE_UNKNOWN,
|
ATTR_ENTITY_ID, ATTR_TEMPERATURE, STATE_ON, STATE_OFF, STATE_UNKNOWN,
|
||||||
TEMP_CELCIUS)
|
TEMP_CELCIUS)
|
||||||
@ -48,6 +50,19 @@ DISCOVERY_PLATFORMS = {
|
|||||||
zwave.DISCOVER_THERMOSTATS: 'zwave'
|
zwave.DISCOVER_THERMOSTATS: 'zwave'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SET_AWAY_MODE_SCHEMA = vol.Schema({
|
||||||
|
vol.Optional(ATTR_ENTITY_ID): cv.entity_ids,
|
||||||
|
vol.Required(ATTR_AWAY_MODE): cv.boolean,
|
||||||
|
})
|
||||||
|
SET_TEMPERATURE_SCHEMA = vol.Schema({
|
||||||
|
vol.Optional(ATTR_ENTITY_ID): cv.entity_ids,
|
||||||
|
vol.Required(ATTR_TEMPERATURE): vol.Coerce(float),
|
||||||
|
})
|
||||||
|
SET_FAN_MODE_SCHEMA = vol.Schema({
|
||||||
|
vol.Optional(ATTR_ENTITY_ID): cv.entity_ids,
|
||||||
|
vol.Required(ATTR_FAN): cv.boolean,
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
def set_away_mode(hass, away_mode, entity_id=None):
|
def set_away_mode(hass, away_mode, entity_id=None):
|
||||||
"""Turn all or specified thermostat away mode on."""
|
"""Turn all or specified thermostat away mode on."""
|
||||||
@ -97,13 +112,7 @@ def setup(hass, config):
|
|||||||
"""Set away mode on target thermostats."""
|
"""Set away mode on target thermostats."""
|
||||||
target_thermostats = component.extract_from_service(service)
|
target_thermostats = component.extract_from_service(service)
|
||||||
|
|
||||||
away_mode = service.data.get(ATTR_AWAY_MODE)
|
away_mode = service.data[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:
|
for thermostat in target_thermostats:
|
||||||
if away_mode:
|
if away_mode:
|
||||||
@ -115,20 +124,14 @@ def setup(hass, config):
|
|||||||
|
|
||||||
hass.services.register(
|
hass.services.register(
|
||||||
DOMAIN, SERVICE_SET_AWAY_MODE, away_mode_set_service,
|
DOMAIN, SERVICE_SET_AWAY_MODE, away_mode_set_service,
|
||||||
descriptions.get(SERVICE_SET_AWAY_MODE))
|
descriptions.get(SERVICE_SET_AWAY_MODE),
|
||||||
|
schema=SET_AWAY_MODE_SCHEMA)
|
||||||
|
|
||||||
def temperature_set_service(service):
|
def temperature_set_service(service):
|
||||||
"""Set temperature on the target thermostats."""
|
"""Set temperature on the target thermostats."""
|
||||||
target_thermostats = component.extract_from_service(service)
|
target_thermostats = component.extract_from_service(service)
|
||||||
|
|
||||||
temperature = util.convert(
|
temperature = service.data[ATTR_TEMPERATURE]
|
||||||
service.data.get(ATTR_TEMPERATURE), float)
|
|
||||||
|
|
||||||
if temperature is None:
|
|
||||||
_LOGGER.error(
|
|
||||||
"Received call to %s without attribute %s",
|
|
||||||
SERVICE_SET_TEMPERATURE, ATTR_TEMPERATURE)
|
|
||||||
return
|
|
||||||
|
|
||||||
for thermostat in target_thermostats:
|
for thermostat in target_thermostats:
|
||||||
thermostat.set_temperature(convert(
|
thermostat.set_temperature(convert(
|
||||||
@ -139,19 +142,14 @@ def setup(hass, config):
|
|||||||
|
|
||||||
hass.services.register(
|
hass.services.register(
|
||||||
DOMAIN, SERVICE_SET_TEMPERATURE, temperature_set_service,
|
DOMAIN, SERVICE_SET_TEMPERATURE, temperature_set_service,
|
||||||
descriptions.get(SERVICE_SET_TEMPERATURE))
|
descriptions.get(SERVICE_SET_TEMPERATURE),
|
||||||
|
schema=SET_TEMPERATURE_SCHEMA)
|
||||||
|
|
||||||
def fan_mode_set_service(service):
|
def fan_mode_set_service(service):
|
||||||
"""Set fan mode on target thermostats."""
|
"""Set fan mode on target thermostats."""
|
||||||
target_thermostats = component.extract_from_service(service)
|
target_thermostats = component.extract_from_service(service)
|
||||||
|
|
||||||
fan_mode = service.data.get(ATTR_FAN)
|
fan_mode = service.data[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:
|
for thermostat in target_thermostats:
|
||||||
if fan_mode:
|
if fan_mode:
|
||||||
@ -163,7 +161,8 @@ def setup(hass, config):
|
|||||||
|
|
||||||
hass.services.register(
|
hass.services.register(
|
||||||
DOMAIN, SERVICE_SET_FAN_MODE, fan_mode_set_service,
|
DOMAIN, SERVICE_SET_FAN_MODE, fan_mode_set_service,
|
||||||
descriptions.get(SERVICE_SET_FAN_MODE))
|
descriptions.get(SERVICE_SET_FAN_MODE),
|
||||||
|
schema=SET_FAN_MODE_SCHEMA)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user