hass-core/tests/components/switch/test_mochad.py
Robert Svensson 0009be595c Device Registry (#15980)
* First draft

* Generate device id

* No obscure registry

* Dont store config_entry_id in device

* Storage

* Small mistake on rebase

* Do storage more like entity registry

* Improve device identification

* Add tests

* Remove deconz device support from PR

* Fix hound comments, voff!

* Fix comments and clean up

* Fix proper indentation

* Fix pydoc issues

* Fix mochad component to not use self.device

* Fix mochad light platform to not use self.device

* Fix TankUtilitySensor to not use self.device

* Fix Soundtouch to not use self.device

* Fix Plex to not use self.device

* Fix Emby to not use self.device

* Fix Heatmiser to not use self.device

* Fix Wemo lights to not use self.device

* Fix Lifx to not use self.device

* Fix Radiotherm to not use self.device

* Fix Juicenet to not use self.device

* Fix Qwikswitch to not use self.device

* Fix Xiaomi miio to not use self.device

* Fix Nest to not use self.device

* Fix Tellduslive to not use self.device

* Fix Knx to not use self.device

* Clean up a small mistake in soundtouch

* Fix comment from Ballob

* Fix bad indentation

* Fix indentatin

* Lint

* Remove unused variable

* Lint
2018-08-22 10:46:37 +02:00

84 lines
2.4 KiB
Python

"""The tests for the mochad switch platform."""
import unittest
import unittest.mock as mock
import pytest
from homeassistant.setup import setup_component
from homeassistant.components import switch
from homeassistant.components.switch import mochad
from tests.common import get_test_home_assistant
@pytest.fixture(autouse=True)
def pymochad_mock():
"""Mock pymochad."""
with mock.patch.dict('sys.modules', {
'pymochad': mock.MagicMock(),
'pymochad.exceptions': mock.MagicMock(),
}):
yield
class TestMochadSwitchSetup(unittest.TestCase):
"""Test the mochad switch."""
PLATFORM = mochad
COMPONENT = switch
THING = 'switch'
def setUp(self):
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
def tearDown(self):
"""Stop everything that was started."""
self.hass.stop()
@mock.patch('homeassistant.components.switch.mochad.MochadSwitch')
def test_setup_adds_proper_devices(self, mock_switch):
"""Test if setup adds devices."""
good_config = {
'mochad': {},
'switch': {
'platform': 'mochad',
'devices': [
{
'name': 'Switch1',
'address': 'a1',
},
],
}
}
self.assertTrue(setup_component(self.hass, switch.DOMAIN, good_config))
class TestMochadSwitch(unittest.TestCase):
"""Test for mochad switch platform."""
def setUp(self):
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
controller_mock = mock.MagicMock()
dev_dict = {'address': 'a1', 'name': 'fake_switch'}
self.switch = mochad.MochadSwitch(self.hass, controller_mock,
dev_dict)
def teardown_method(self, method):
"""Stop everything that was started."""
self.hass.stop()
def test_name(self):
"""Test the name."""
self.assertEqual('fake_switch', self.switch.name)
def test_turn_on(self):
"""Test turn_on."""
self.switch.turn_on()
self.switch.switch.send_cmd.assert_called_once_with('on')
def test_turn_off(self):
"""Test turn_off."""
self.switch.turn_off()
self.switch.switch.send_cmd.assert_called_once_with('off')