Add mochad component (#3970)
This commit adds a new component for communicating with mochad[1] a socket interface for the CM15A and CM19A USB X10 controllers. This commit leverages the pymochad library to interface with a mochad socket either on a local or remote machine. Mochad is added as as a generic platform because it supports multiple different classes of device, however in this patch only the switch device implemented as a starting point. Future patches will include other devices types. (although that's dependent on someone gaining access to those) [1] https://sourceforge.net/projects/mochad/
This commit is contained in:
parent
23f54b07c7
commit
0ff500ca25
7 changed files with 272 additions and 0 deletions
79
tests/components/switch/test_mochad.py
Normal file
79
tests/components/switch/test_mochad.py
Normal file
|
@ -0,0 +1,79 @@
|
|||
"""The tests for the mochad switch platform."""
|
||||
import unittest
|
||||
import unittest.mock as mock
|
||||
|
||||
from homeassistant.bootstrap import setup_component
|
||||
from homeassistant.components import switch
|
||||
from homeassistant.components.switch import mochad
|
||||
|
||||
from tests.common import get_test_home_assistant
|
||||
|
||||
|
||||
class TestMochadSwitchSetup(unittest.TestCase):
|
||||
"""Test the mochad switch."""
|
||||
|
||||
PLATFORM = mochad
|
||||
COMPONENT = switch
|
||||
THING = 'switch'
|
||||
|
||||
def setUp(self):
|
||||
"""Setup things to be run when tests are started."""
|
||||
super(TestMochadSwitchSetup, self).setUp()
|
||||
self.hass = get_test_home_assistant()
|
||||
|
||||
def tearDown(self):
|
||||
"""Stop everyhing that was started."""
|
||||
self.hass.stop()
|
||||
super(TestMochadSwitchSetup, self).tearDown()
|
||||
|
||||
@mock.patch('pymochad.controller.PyMochad')
|
||||
@mock.patch('homeassistant.components.switch.mochad.MochadSwitch')
|
||||
def test_setup_adds_proper_devices(self, mock_switch, mock_client):
|
||||
"""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):
|
||||
"""Setup things to be run when tests are started."""
|
||||
super(TestMochadSwitch, self).setUp()
|
||||
self.hass = get_test_home_assistant()
|
||||
controller_mock = mock.MagicMock()
|
||||
device_patch = mock.patch('pymochad.device.Device')
|
||||
device_patch.start()
|
||||
self.addCleanup(device_patch.stop)
|
||||
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.device.send_cmd.assert_called_once_with('on')
|
||||
|
||||
def test_turn_off(self):
|
||||
"""Test turn_off."""
|
||||
self.switch.turn_off()
|
||||
self.switch.device.send_cmd.assert_called_once_with('off')
|
|
@ -300,6 +300,18 @@ def test_temperature_unit():
|
|||
schema('F')
|
||||
|
||||
|
||||
def test_x10_address():
|
||||
"""Test x10 addr validator."""
|
||||
schema = vol.Schema(cv.x10_address)
|
||||
with pytest.raises(vol.Invalid):
|
||||
schema('Q1')
|
||||
schema('q55')
|
||||
schema('garbage_addr')
|
||||
|
||||
schema('a1')
|
||||
schema('C11')
|
||||
|
||||
|
||||
def test_template():
|
||||
"""Test template validator."""
|
||||
schema = vol.Schema(cv.template)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue