2016-11-24 17:52:15 +00:00
|
|
|
"""The tests for the litejet component."""
|
|
|
|
import unittest
|
|
|
|
from unittest import mock
|
|
|
|
|
2017-03-05 09:41:54 +00:00
|
|
|
from homeassistant import setup
|
2016-11-24 17:52:15 +00:00
|
|
|
from homeassistant.components import litejet
|
2018-09-26 16:02:05 +00:00
|
|
|
|
2016-11-24 17:52:15 +00:00
|
|
|
from tests.common import get_test_home_assistant
|
2018-09-26 16:02:05 +00:00
|
|
|
from tests.components.scene import common
|
2016-11-24 17:52:15 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
ENTITY_SCENE = "scene.mock_scene_1"
|
2016-11-24 17:52:15 +00:00
|
|
|
ENTITY_SCENE_NUMBER = 1
|
2019-07-31 19:25:30 +00:00
|
|
|
ENTITY_OTHER_SCENE = "scene.mock_scene_2"
|
2016-11-24 17:52:15 +00:00
|
|
|
ENTITY_OTHER_SCENE_NUMBER = 2
|
|
|
|
|
|
|
|
|
|
|
|
class TestLiteJetScene(unittest.TestCase):
|
|
|
|
"""Test the litejet component."""
|
|
|
|
|
2019-12-05 05:47:35 +00:00
|
|
|
@mock.patch("homeassistant.components.litejet.LiteJet")
|
2016-11-24 17:52:15 +00:00
|
|
|
def setup_method(self, method, mock_pylitejet):
|
2018-08-19 20:29:08 +00:00
|
|
|
"""Set up things to be run when tests are started."""
|
2016-11-24 17:52:15 +00:00
|
|
|
self.hass = get_test_home_assistant()
|
|
|
|
self.hass.start()
|
|
|
|
|
|
|
|
def get_scene_name(number):
|
2020-04-07 21:14:28 +00:00
|
|
|
return f"Mock Scene #{number}"
|
2016-11-24 17:52:15 +00:00
|
|
|
|
|
|
|
self.mock_lj = mock_pylitejet.return_value
|
|
|
|
self.mock_lj.loads.return_value = range(0)
|
|
|
|
self.mock_lj.button_switches.return_value = range(0)
|
|
|
|
self.mock_lj.all_switches.return_value = range(0)
|
|
|
|
self.mock_lj.scenes.return_value = range(1, 3)
|
|
|
|
self.mock_lj.get_scene_name.side_effect = get_scene_name
|
|
|
|
|
2017-03-05 09:41:54 +00:00
|
|
|
assert setup.setup_component(
|
2020-01-20 16:44:55 +00:00
|
|
|
self.hass,
|
|
|
|
litejet.DOMAIN,
|
|
|
|
{"litejet": {"port": "/dev/serial/by-id/mock-litejet"}},
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2016-11-24 17:52:15 +00:00
|
|
|
self.hass.block_till_done()
|
|
|
|
|
|
|
|
def teardown_method(self, method):
|
|
|
|
"""Stop everything that was started."""
|
|
|
|
self.hass.stop()
|
|
|
|
|
|
|
|
def scene(self):
|
2016-12-28 18:04:59 +00:00
|
|
|
"""Get the current scene."""
|
2016-11-24 17:52:15 +00:00
|
|
|
return self.hass.states.get(ENTITY_SCENE)
|
|
|
|
|
|
|
|
def other_scene(self):
|
2016-12-28 18:04:59 +00:00
|
|
|
"""Get the other scene."""
|
2016-11-24 17:52:15 +00:00
|
|
|
return self.hass.states.get(ENTITY_OTHER_SCENE)
|
|
|
|
|
|
|
|
def test_activate(self):
|
|
|
|
"""Test activating the scene."""
|
2018-09-26 16:02:05 +00:00
|
|
|
common.activate(self.hass, ENTITY_SCENE)
|
2016-11-24 17:52:15 +00:00
|
|
|
self.hass.block_till_done()
|
2019-07-31 19:25:30 +00:00
|
|
|
self.mock_lj.activate_scene.assert_called_once_with(ENTITY_SCENE_NUMBER)
|