def test_incoming(self): i = MagicMock() hi = HAInterface(i) d = InterfaceDevice(address='asdf', devices=hi) hi._onCommand(Command.ON, 'asdf') time.sleep(1) self.assertEqual(d.state, State.ON)
def test_random_sync(self): # Should randomly sync state with the objects # Usually for X10 devices that do not have an acknowledgement self.device.sync = True device = InterfaceDevice(address='asdf', sync=True) self.assertIsNotNone(device) self.assertTrue(device.sync)
def test_initial(self): interface = Mock() p = PropertyMock(side_effect=ValueError) type(interface).state = p device = InterfaceDevice(address='asdf', devices=interface, initial=State.ON) interface.on.assert_called_with('asdf') # interface.initial.assert_called_with('asdf') device1 = StateDevice() device1.on() interface2 = Mock() type(interface2).state = p device = InterfaceDevice(address='asdf', devices=interface2, initial=State.ON) interface2.on.assert_called_with('asdf')
def test_loop_prevention(self): d = InterfaceDevice(devices=(self.interface), delay={ Attribute.COMMAND: Command.OFF, Attribute.SECS: 2 }) d.on() self.interface.on.assert_called_once_with(None) d.command(command=Command.OFF, source=self.interface) time.sleep(3) self.assertFalse(self.interface.off.called)
def test_receive_state(self): mi = Mock() mi.read = self.response interface = StateInterface(mi) device = InterfaceDevice(address=None, devices=interface, initial_state=State.UNKNOWN) self.assertEqual(device.state, State.UNKNOWN) self._response = State.ON time.sleep(2) self.assertEqual(device.state, State.ON)
def test_controlled_devices_no_delay_default(self): i = Mock() d1 = StateDevice() d2 = InterfaceDevice( devices=(i, d1), delay={ Attribute.COMMAND: Command.OFF, Attribute.SECS: 3 }, initial=State.ON, ) d1.off() self.assertEqual(d2.state, State.ON) d2.command(command=Command.OFF, source=i) self.assertEqual(d2.state, State.OFF)
def test_scene_activate(self): interface = Mock() interface.onCommand.return_value = True d1 = InterfaceDevice('d1', interface) d2 = InterfaceDevice('d2', interface) scene = Scene( address='s1', devices= (interface, {d1: { 'state': State.ON, 'rate': 10, }, d2: { 'state': (State.LEVEL, 30), 'rate': 10, }, }), update=True, ) self.assertIsNotNone(scene) #scene.activate() scene.on()
def test_no_param_init(self): d = InterfaceDevice() self.assertIsNotNone(d)
def setUp(self): self.interface = Mock() p = PropertyMock(side_effect=ValueError) type(self.interface).state = p self.device = InterfaceDevice('D1', self.interface)
def test_on_state(self): s = InterfaceDevice(address='D3', devices=self.interface) s.off() self.assertEqual(s.state, State.OFF) self.interface._onState(State.ON, 'D3') self.assertEqual(s.state, State.ON)