core/tests/components/mochad/test_switch.py

55 lines
1.4 KiB
Python
Raw Normal View History

"""The tests for the mochad switch platform."""
2021-01-01 21:31:56 +00:00
import unittest.mock as mock
import pytest
from homeassistant.components import switch
from homeassistant.components.mochad import switch as mochad
from homeassistant.setup import async_setup_component
@pytest.fixture(autouse=True)
def pymochad_mock():
"""Mock pymochad."""
with mock.patch("homeassistant.components.mochad.switch.device"), mock.patch(
"homeassistant.components.mochad.switch.MochadException"
2019-07-31 19:25:30 +00:00
):
yield
@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)
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)
async def test_name(switch_mock):
"""Test the name."""
assert switch_mock.name == "fake_switch"
async def test_turn_on(switch_mock):
"""Test turn_on."""
switch_mock.turn_on()
switch_mock.switch.send_cmd.assert_called_once_with("on")
async def test_turn_off(switch_mock):
"""Test turn_off."""
switch_mock.turn_off()
switch_mock.switch.send_cmd.assert_called_once_with("off")