Water heater support (#17058)
* Moved econet to water_heater * Wink and Econet are now in water heater! * Removed away mode from econet and added demo water heater * Added demo tests * Updated coveragerc * Fix lint issues. * updated requirements all * Requirements all actually updated. * Reset wink and econet and fixed service. * Reset wink and econet to the correct dev state * Reset requirements_all and .coveragerc and removed the new econet and wink water_heater files * Removed @bind_hass service methods * Actually reset the .coverage file * Fixed the tests * Addressed @MartinHjelmare's comments * Removed unused import * Switched to async_add_executor_job * Fixed lint * Removed is_on * Added celsius demo water heater and tests. * Removed metric import
This commit is contained in:
1 parent
ff4204244b
commit
f2d8f3bcb8
6 files changed
+572
No files matched your search
@@ -0,0 +1 @@
|
||||
"""The tests for water heater component."""
|
||||
@@ -0,0 +1,51 @@
|
||||
"""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 (
|
||||
_LOGGER, ATTR_AWAY_MODE,
|
||||
ATTR_OPERATION_MODE, DOMAIN, SERVICE_SET_AWAY_MODE,
|
||||
SERVICE_SET_TEMPERATURE, SERVICE_SET_OPERATION_MODE)
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID, ATTR_TEMPERATURE)
|
||||
from homeassistant.loader import bind_hass
|
||||
|
||||
|
||||
@bind_hass
|
||||
def set_away_mode(hass, away_mode, entity_id=None):
|
||||
"""Turn all or specified water_heater devices away mode on."""
|
||||
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=None,
|
||||
operation_mode=None):
|
||||
"""Set new target temperature."""
|
||||
kwargs = {
|
||||
key: value for key, value in [
|
||||
(ATTR_TEMPERATURE, temperature),
|
||||
(ATTR_ENTITY_ID, entity_id),
|
||||
(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=None):
|
||||
"""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)
|
||||
@@ -0,0 +1,118 @@
|
||||
"""The tests for the demo water_heater component."""
|
||||
import unittest
|
||||
|
||||
from homeassistant.util.unit_system import (
|
||||
IMPERIAL_SYSTEM
|
||||
)
|
||||
from homeassistant.setup import setup_component
|
||||
from homeassistant.components import water_heater
|
||||
|
||||
from tests.common import get_test_home_assistant
|
||||
from tests.components.water_heater import common
|
||||
|
||||
|
||||
ENTITY_WATER_HEATER = 'water_heater.demo_water_heater'
|
||||
ENTITY_WATER_HEATER_CELSIUS = 'water_heater.demo_water_heater_celsius'
|
||||
|
||||
|
||||
class TestDemowater_heater(unittest.TestCase):
|
||||
"""Test the demo water_heater."""
|
||||
|
||||
def setUp(self): # pylint: disable=invalid-name
|
||||
"""Set up things to be run when tests are started."""
|
||||
self.hass = get_test_home_assistant()
|
||||
self.hass.config.units = IMPERIAL_SYSTEM
|
||||
self.assertTrue(setup_component(self.hass, water_heater.DOMAIN, {
|
||||
'water_heater': {
|
||||
'platform': 'demo',
|
||||
}}))
|
||||
|
||||
def tearDown(self): # pylint: disable=invalid-name
|
||||
"""Stop down everything that was started."""
|
||||
self.hass.stop()
|
||||
|
||||
def test_setup_params(self):
|
||||
"""Test the initial parameters."""
|
||||
state = self.hass.states.get(ENTITY_WATER_HEATER)
|
||||
self.assertEqual(119, state.attributes.get('temperature'))
|
||||
self.assertEqual('off', state.attributes.get('away_mode'))
|
||||
self.assertEqual("eco", state.attributes.get('operation_mode'))
|
||||
|
||||
def test_default_setup_params(self):
|
||||
"""Test the setup with default parameters."""
|
||||
state = self.hass.states.get(ENTITY_WATER_HEATER)
|
||||
self.assertEqual(110, state.attributes.get('min_temp'))
|
||||
self.assertEqual(140, state.attributes.get('max_temp'))
|
||||
|
||||
def test_set_only_target_temp_bad_attr(self):
|
||||
"""Test setting the target temperature without required attribute."""
|
||||
state = self.hass.states.get(ENTITY_WATER_HEATER)
|
||||
self.assertEqual(119, state.attributes.get('temperature'))
|
||||
common.set_temperature(self.hass, None, ENTITY_WATER_HEATER)
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(119, state.attributes.get('temperature'))
|
||||
|
||||
def test_set_only_target_temp(self):
|
||||
"""Test the setting of the target temperature."""
|
||||
state = self.hass.states.get(ENTITY_WATER_HEATER)
|
||||
self.assertEqual(119, state.attributes.get('temperature'))
|
||||
common.set_temperature(self.hass, 110, ENTITY_WATER_HEATER)
|
||||
self.hass.block_till_done()
|
||||
state = self.hass.states.get(ENTITY_WATER_HEATER)
|
||||
self.assertEqual(110, state.attributes.get('temperature'))
|
||||
|
||||
def test_set_operation_bad_attr_and_state(self):
|
||||
"""Test setting operation mode without required attribute.
|
||||
|
||||
Also check the state.
|
||||
"""
|
||||
state = self.hass.states.get(ENTITY_WATER_HEATER)
|
||||
self.assertEqual("eco", state.attributes.get('operation_mode'))
|
||||
self.assertEqual("eco", state.state)
|
||||
common.set_operation_mode(self.hass, None, ENTITY_WATER_HEATER)
|
||||
self.hass.block_till_done()
|
||||
state = self.hass.states.get(ENTITY_WATER_HEATER)
|
||||
self.assertEqual("eco", state.attributes.get('operation_mode'))
|
||||
self.assertEqual("eco", state.state)
|
||||
|
||||
def test_set_operation(self):
|
||||
"""Test setting of new operation mode."""
|
||||
state = self.hass.states.get(ENTITY_WATER_HEATER)
|
||||
self.assertEqual("eco", state.attributes.get('operation_mode'))
|
||||
self.assertEqual("eco", state.state)
|
||||
common.set_operation_mode(self.hass, "electric", ENTITY_WATER_HEATER)
|
||||
self.hass.block_till_done()
|
||||
state = self.hass.states.get(ENTITY_WATER_HEATER)
|
||||
self.assertEqual("electric", state.attributes.get('operation_mode'))
|
||||
self.assertEqual("electric", state.state)
|
||||
|
||||
def test_set_away_mode_bad_attr(self):
|
||||
"""Test setting the away mode without required attribute."""
|
||||
state = self.hass.states.get(ENTITY_WATER_HEATER)
|
||||
self.assertEqual('off', state.attributes.get('away_mode'))
|
||||
common.set_away_mode(self.hass, None, ENTITY_WATER_HEATER)
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual('off', state.attributes.get('away_mode'))
|
||||
|
||||
def test_set_away_mode_on(self):
|
||||
"""Test setting the away mode on/true."""
|
||||
common.set_away_mode(self.hass, True, ENTITY_WATER_HEATER)
|
||||
self.hass.block_till_done()
|
||||
state = self.hass.states.get(ENTITY_WATER_HEATER)
|
||||
self.assertEqual('on', state.attributes.get('away_mode'))
|
||||
|
||||
def test_set_away_mode_off(self):
|
||||
"""Test setting the away mode off/false."""
|
||||
common.set_away_mode(self.hass, False, ENTITY_WATER_HEATER_CELSIUS)
|
||||
self.hass.block_till_done()
|
||||
state = self.hass.states.get(ENTITY_WATER_HEATER_CELSIUS)
|
||||
self.assertEqual('off', state.attributes.get('away_mode'))
|
||||
|
||||
def test_set_only_target_temp_with_convert(self):
|
||||
"""Test the setting of the target temperature."""
|
||||
state = self.hass.states.get(ENTITY_WATER_HEATER_CELSIUS)
|
||||
self.assertEqual(113, state.attributes.get('temperature'))
|
||||
common.set_temperature(self.hass, 114, ENTITY_WATER_HEATER_CELSIUS)
|
||||
self.hass.block_till_done()
|
||||
state = self.hass.states.get(ENTITY_WATER_HEATER_CELSIUS)
|
||||
self.assertEqual(114, state.attributes.get('temperature'))
|
||||
Reference in new issue
Block a user