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