core/tests/components/water_heater/common.py

57 lines
1.6 KiB
Python
Raw Normal View History

"""Collection of helper methods.
All containing methods are legacy helpers that should not be used by new
components. Instead call the service directly.
"""
from homeassistant.components.water_heater import (
2019-07-31 19:25:30 +00:00
_LOGGER,
ATTR_AWAY_MODE,
ATTR_OPERATION_MODE,
DOMAIN,
SERVICE_SET_AWAY_MODE,
SERVICE_SET_OPERATION_MODE,
SERVICE_SET_TEMPERATURE,
2019-07-31 19:25:30 +00:00
)
from homeassistant.const import ATTR_ENTITY_ID, ATTR_TEMPERATURE, ENTITY_MATCH_ALL
from homeassistant.loader import bind_hass
@bind_hass
def set_away_mode(hass, away_mode, entity_id=ENTITY_MATCH_ALL):
"""Turn all or specified water_heater devices away mode on."""
2019-07-31 19:25:30 +00:00
data = {ATTR_AWAY_MODE: away_mode}
if entity_id:
data[ATTR_ENTITY_ID] = entity_id
hass.services.call(DOMAIN, SERVICE_SET_AWAY_MODE, data)
@bind_hass
def set_temperature(
hass, temperature=None, entity_id=ENTITY_MATCH_ALL, operation_mode=None
):
"""Set new target temperature."""
kwargs = {
2019-07-31 19:25:30 +00:00
key: value
for key, value in [
(ATTR_TEMPERATURE, temperature),
(ATTR_ENTITY_ID, entity_id),
2019-07-31 19:25:30 +00:00
(ATTR_OPERATION_MODE, operation_mode),
]
if value is not None
}
_LOGGER.debug("set_temperature start data=%s", kwargs)
hass.services.call(DOMAIN, SERVICE_SET_TEMPERATURE, kwargs)
@bind_hass
def set_operation_mode(hass, operation_mode, entity_id=ENTITY_MATCH_ALL):
"""Set new target operation mode."""
data = {ATTR_OPERATION_MODE: operation_mode}
if entity_id is not None:
data[ATTR_ENTITY_ID] = entity_id
hass.services.call(DOMAIN, SERVICE_SET_OPERATION_MODE, data)