2016-10-25 04:49:49 +00:00
|
|
|
"""The tests for the mochad switch platform."""
|
2021-01-01 21:31:56 +00:00
|
|
|
import unittest.mock as mock
|
|
|
|
|
2017-05-14 04:25:54 +00:00
|
|
|
import pytest
|
|
|
|
|
2016-10-25 04:49:49 +00:00
|
|
|
from homeassistant.components import switch
|
2019-02-02 15:13:16 +00:00
|
|
|
from homeassistant.components.mochad import switch as mochad
|
2020-10-22 12:58:54 +00:00
|
|
|
from homeassistant.setup import async_setup_component
|
2016-10-25 04:49:49 +00:00
|
|
|
|
|
|
|
|
2017-05-14 04:25:54 +00:00
|
|
|
@pytest.fixture(autouse=True)
|
|
|
|
def pymochad_mock():
|
|
|
|
"""Mock pymochad."""
|
2019-12-06 01:02:34 +00:00
|
|
|
with mock.patch("homeassistant.components.mochad.switch.device"), mock.patch(
|
|
|
|
"homeassistant.components.mochad.switch.MochadException"
|
2019-07-31 19:25:30 +00:00
|
|
|
):
|
2017-05-14 04:25:54 +00:00
|
|
|
yield
|
|
|
|
|
|
|
|
|
2020-10-22 12:58:54 +00:00
|
|
|
@pytest.fixture
|
|
|
|
def switch_mock(hass):
|
|
|
|
"""Mock switch."""
|
|
|
|
controller_mock = mock.MagicMock()
|
|
|
|
dev_dict = {"address": "a1", "name": "fake_switch"}
|
|
|
|
return mochad.MochadSwitch(hass, controller_mock, dev_dict)
|
2016-10-25 04:49:49 +00:00
|
|
|
|
|
|
|
|
2020-10-22 12:58:54 +00:00
|
|
|
async def test_setup_adds_proper_devices(hass):
|
|
|
|
"""Test if setup adds devices."""
|
|
|
|
good_config = {
|
|
|
|
"mochad": {},
|
|
|
|
"switch": {
|
|
|
|
"platform": "mochad",
|
|
|
|
"devices": [{"name": "Switch1", "address": "a1"}],
|
|
|
|
},
|
|
|
|
}
|
|
|
|
assert await async_setup_component(hass, switch.DOMAIN, good_config)
|
2016-10-25 04:49:49 +00:00
|
|
|
|
|
|
|
|
2020-10-22 12:58:54 +00:00
|
|
|
async def test_name(switch_mock):
|
|
|
|
"""Test the name."""
|
2021-03-20 12:55:10 +00:00
|
|
|
assert switch_mock.name == "fake_switch"
|
2016-10-25 04:49:49 +00:00
|
|
|
|
|
|
|
|
2020-10-22 12:58:54 +00:00
|
|
|
async def test_turn_on(switch_mock):
|
|
|
|
"""Test turn_on."""
|
|
|
|
switch_mock.turn_on()
|
|
|
|
switch_mock.switch.send_cmd.assert_called_once_with("on")
|
2016-10-25 04:49:49 +00:00
|
|
|
|
|
|
|
|
2020-10-22 12:58:54 +00:00
|
|
|
async def test_turn_off(switch_mock):
|
|
|
|
"""Test turn_off."""
|
|
|
|
switch_mock.turn_off()
|
|
|
|
switch_mock.switch.send_cmd.assert_called_once_with("off")
|