Add support for on/off climate (#25026)

* Add support for on/off climate

* address comments

* Add test for sync overwrite

* Add more tests
This commit is contained in:
Pascal Vizeli authored and Paulus Schoutsen committed 2019-07-11 15:28:11 -07:00
1 parent f5a4af40ee
commit d47905d119
5 files changed
+153 -56

No files matched your search

+24 -1
View File
@@ -10,7 +10,8 @@ from homeassistant.components.climate.const import (
ATTR_TARGET_TEMP_LOW, DOMAIN, SERVICE_SET_AUX_HEAT, SERVICE_SET_FAN_MODE,
SERVICE_SET_HUMIDITY, SERVICE_SET_HVAC_MODE, SERVICE_SET_PRESET_MODE,
SERVICE_SET_SWING_MODE, SERVICE_SET_TEMPERATURE)
from homeassistant.const import ATTR_ENTITY_ID, ATTR_TEMPERATURE
from homeassistant.const import (
ATTR_ENTITY_ID, ATTR_TEMPERATURE, SERVICE_TURN_OFF, SERVICE_TURN_ON)
from homeassistant.loader import bind_hass
@@ -188,3 +189,25 @@ def set_swing_mode(hass, swing_mode, entity_id=None):
data[ATTR_ENTITY_ID] = entity_id
hass.services.call(DOMAIN, SERVICE_SET_SWING_MODE, data)
async def async_turn_on(hass, entity_id=None):
"""Turn on device."""
data = {}
if entity_id is not None:
data[ATTR_ENTITY_ID] = entity_id
await hass.services.async_call(
DOMAIN, SERVICE_TURN_ON, data, blocking=True)
async def async_turn_off(hass, entity_id=None):
"""Turn off device."""
data = {}
if entity_id is not None:
data[ATTR_ENTITY_ID] = entity_id
await hass.services.async_call(
DOMAIN, SERVICE_TURN_OFF, data, blocking=True)
+25 -1
View File
@@ -1,9 +1,11 @@
"""The tests for the climate component."""
from unittest.mock import MagicMock
import pytest
import voluptuous as vol
from homeassistant.components.climate import SET_TEMPERATURE_SCHEMA
from homeassistant.components.climate import (
SET_TEMPERATURE_SCHEMA, ClimateDevice)
from tests.common import async_mock_service
@@ -37,3 +39,25 @@ async def test_set_temp_schema(hass, caplog):
assert len(calls) == 1
assert calls[-1].data == data
async def test_sync_turn_on(hass):
"""Test if adding turn_on work."""
climate = ClimateDevice()
climate.hass = hass
climate.turn_on = MagicMock()
await climate.async_turn_on()
assert climate.turn_on.called
async def test_sync_turn_off(hass):
"""Test if adding turn_on work."""
climate = ClimateDevice()
climate.hass = hass
climate.turn_off = MagicMock()
await climate.async_turn_off()
assert climate.turn_off.called