Fix broken thermostat demo and prevent happening again
parent
96cfff192a
commit
51dd718282
|
@ -17,7 +17,7 @@ DOMAIN = "demo"
|
||||||
DEPENDENCIES = ['introduction', 'conversation']
|
DEPENDENCIES = ['introduction', 'conversation']
|
||||||
|
|
||||||
COMPONENTS_WITH_DEMO_PLATFORM = [
|
COMPONENTS_WITH_DEMO_PLATFORM = [
|
||||||
'switch', 'light', 'sensor', 'media_player', 'notify']
|
'switch', 'light', 'sensor', 'thermostat', 'media_player', 'notify']
|
||||||
|
|
||||||
|
|
||||||
def setup(hass, config):
|
def setup(hass, config):
|
||||||
|
|
|
@ -133,29 +133,25 @@ class ThermostatDevice(Entity):
|
||||||
user_unit = self.hass.config.temperature_unit
|
user_unit = self.hass.config.temperature_unit
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
ATTR_CURRENT_TEMPERATURE: round(convert(self.current_temperature,
|
ATTR_CURRENT_TEMPERATURE: round(convert(
|
||||||
thermostat_unit,
|
self.current_temperature, thermostat_unit, user_unit), 1),
|
||||||
user_unit), 1),
|
ATTR_MIN_TEMP: round(convert(
|
||||||
ATTR_MIN_TEMP: round(convert(self.min_temp,
|
self.min_temp, thermostat_unit, user_unit), 0),
|
||||||
thermostat_unit,
|
ATTR_MAX_TEMP: round(convert(
|
||||||
user_unit), 0),
|
self.max_temp, thermostat_unit, user_unit), 0),
|
||||||
ATTR_MAX_TEMP: round(convert(self.max_temp,
|
ATTR_TEMPERATURE: round(convert(
|
||||||
thermostat_unit,
|
self.target_temperature, thermostat_unit, user_unit), 0),
|
||||||
user_unit), 0),
|
ATTR_TEMPERATURE_LOW: round(convert(
|
||||||
ATTR_TEMPERATURE: round(convert(self.target_temperature,
|
self.target_temperature_low, thermostat_unit, user_unit), 0),
|
||||||
thermostat_unit,
|
ATTR_TEMPERATURE_HIGH: round(convert(
|
||||||
user_unit), 0),
|
self.target_temperature_high, thermostat_unit, user_unit), 0),
|
||||||
ATTR_TEMPERATURE_LOW: round(convert(self.target_temperature_low,
|
|
||||||
thermostat_unit,
|
|
||||||
user_unit), 0),
|
|
||||||
ATTR_TEMPERATURE_HIGH: round(convert(self.target_temperature_high,
|
|
||||||
thermostat_unit,
|
|
||||||
user_unit), 0),
|
|
||||||
ATTR_OPERATION: self.operation
|
|
||||||
}
|
}
|
||||||
|
|
||||||
is_away = self.is_away_mode_on
|
operation = self.operation
|
||||||
|
if operation is not None:
|
||||||
|
data[ATTR_OPERATION] = operation
|
||||||
|
|
||||||
|
is_away = self.is_away_mode_on
|
||||||
if is_away is not None:
|
if is_away is not None:
|
||||||
data[ATTR_AWAY_MODE] = STATE_ON if is_away else STATE_OFF
|
data[ATTR_AWAY_MODE] = STATE_ON if is_away else STATE_OFF
|
||||||
|
|
||||||
|
@ -169,7 +165,7 @@ class ThermostatDevice(Entity):
|
||||||
@property
|
@property
|
||||||
def unit_of_measurement(self):
|
def unit_of_measurement(self):
|
||||||
""" Unit of measurement this thermostat expresses itself in. """
|
""" Unit of measurement this thermostat expresses itself in. """
|
||||||
return NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def current_temperature(self):
|
def current_temperature(self):
|
||||||
|
@ -179,7 +175,7 @@ class ThermostatDevice(Entity):
|
||||||
@property
|
@property
|
||||||
def operation(self):
|
def operation(self):
|
||||||
""" Returns current operation ie. heat, cool, idle """
|
""" Returns current operation ie. heat, cool, idle """
|
||||||
return NotImplementedError
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def target_temperature(self):
|
def target_temperature(self):
|
||||||
|
|
|
@ -4,15 +4,18 @@ tests.test_component_demo
|
||||||
|
|
||||||
Tests demo component.
|
Tests demo component.
|
||||||
"""
|
"""
|
||||||
|
import json
|
||||||
import unittest
|
import unittest
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
import homeassistant.core as ha
|
import homeassistant.core as ha
|
||||||
import homeassistant.components.demo as demo
|
import homeassistant.components.demo as demo
|
||||||
|
from homeassistant.remote import JSONEncoder
|
||||||
|
|
||||||
from tests.common import mock_http_component
|
from tests.common import mock_http_component
|
||||||
|
|
||||||
|
|
||||||
|
@patch('homeassistant.components.sun.setup')
|
||||||
class TestDemo(unittest.TestCase):
|
class TestDemo(unittest.TestCase):
|
||||||
""" Test the demo module. """
|
""" Test the demo module. """
|
||||||
|
|
||||||
|
@ -24,16 +27,24 @@ class TestDemo(unittest.TestCase):
|
||||||
""" Stop down stuff we started. """
|
""" Stop down stuff we started. """
|
||||||
self.hass.stop()
|
self.hass.stop()
|
||||||
|
|
||||||
@patch('homeassistant.components.sun.setup')
|
|
||||||
def test_if_demo_state_shows_by_default(self, mock_sun_setup):
|
def test_if_demo_state_shows_by_default(self, mock_sun_setup):
|
||||||
""" Test if demo state shows if we give no configuration. """
|
""" Test if demo state shows if we give no configuration. """
|
||||||
demo.setup(self.hass, {demo.DOMAIN: {}})
|
demo.setup(self.hass, {demo.DOMAIN: {}})
|
||||||
|
|
||||||
self.assertIsNotNone(self.hass.states.get('a.Demo_Mode'))
|
self.assertIsNotNone(self.hass.states.get('a.Demo_Mode'))
|
||||||
|
|
||||||
@patch('homeassistant.components.sun.setup')
|
|
||||||
def test_hiding_demo_state(self, mock_sun_setup):
|
def test_hiding_demo_state(self, mock_sun_setup):
|
||||||
""" Test if you can hide the demo card. """
|
""" Test if you can hide the demo card. """
|
||||||
demo.setup(self.hass, {demo.DOMAIN: {'hide_demo_state': 1}})
|
demo.setup(self.hass, {demo.DOMAIN: {'hide_demo_state': 1}})
|
||||||
|
|
||||||
self.assertIsNone(self.hass.states.get('a.Demo_Mode'))
|
self.assertIsNone(self.hass.states.get('a.Demo_Mode'))
|
||||||
|
|
||||||
|
def test_all_entities_can_be_loaded_over_json(self, mock_sun_setup):
|
||||||
|
""" Test if you can hide the demo card. """
|
||||||
|
demo.setup(self.hass, {demo.DOMAIN: {'hide_demo_state': 1}})
|
||||||
|
|
||||||
|
try:
|
||||||
|
json.dumps(self.hass.states.all(), cls=JSONEncoder)
|
||||||
|
except Exception:
|
||||||
|
self.fail('Unable to convert all demo entities to JSON. '
|
||||||
|
'Wrong data in state machine!')
|
||||||
|
|
Loading…
Reference in New Issue