def test_load_interface_call(self, mock_apicall): """Test if interface is called correctly.""" async def return_async_value(val): return val pyvlx = PyVLX() devices = Devices(pyvlx) get_response = \ '{"token":"aEGjVG0T3jj1VNEJTFmMBw==","result":true,"deviceSta' + \ 'tus":"IDLE","data":[{"name": "Volet roulant cour", "id": 0, ' + \ '"scenes": ["Fermer volet cour", "Ouvrir volet cour"], "categ' + \ 'ory": "Roller shutter", "typeId": 2, "subtype": 0}, {"name":' + \ '"Fenêtre cour", "id": 1, "scenes": ["Fermer fenetre cour", "' + \ 'Ouvrir fenetre cour"], "category": "Window opener", "typeId"' + \ ': 4, "subtype": 1}, {"name": "Fenêtre jardin", "id": 2, "sce' + \ 'nes": ["Fermer fenetre jardin", "Ouvrir fenetre jardin"], "c' + \ 'ategory": "Window opener", "typeId": 4, "subtype": 1}, {"nam' + \ 'e": "Volet roulant jardin", "id": 3, "scenes": ["Fermer vole' + \ 't jardin", "Ouvrir Volet jardin"], "category": "Roller shutt' + \ 'er", "typeId": 2, "subtype": 0}]}' mock_apicall.return_value = return_async_value( json.loads(get_response)) self.loop.run_until_complete(asyncio.Task(devices.load())) mock_apicall.assert_called_with('products', 'get') self.assertEqual(len(devices), 4) self.assertEqual(devices[0], RollerShutter(pyvlx, 0, 'Volet roulant cour', 0, 2)) self.assertEqual(devices[1], Window(pyvlx, 1, 'Fenêtre cour', 1, 4)) self.assertEqual(devices[2], Window(pyvlx, 2, 'Fenêtre jardin', 1, 4)) self.assertEqual(devices[3], RollerShutter(pyvlx, 3, 'Volet roulant jardin', 0, 2))
def test_load_windows_and_roller_shutters(self): """Test load configuration with windows and rollershutters.""" pyvlx = PyVLX() devices = Devices(pyvlx) get_response = \ '{"token":"aEGjVG0T3jj1VNEJTFmMBw==","result":true,"deviceSta' + \ 'tus":"IDLE","data":[{"name": "Volet roulant cour", "id": 0, ' + \ '"scenes": ["Fermer volet cour", "Ouvrir volet cour"], "categ' + \ 'ory": "Roller shutter", "typeId": 2, "subtype": 0}, {"name":' + \ '"Fenêtre cour", "id": 1, "scenes": ["Fermer fenetre cour", "' + \ 'Ouvrir fenetre cour"], "category": "Window opener", "typeId"' + \ ': 4, "subtype": 1}, {"name": "Fenêtre jardin", "id": 2, "sce' + \ 'nes": ["Fermer fenetre jardin", "Ouvrir fenetre jardin"], "c' + \ 'ategory": "Window opener", "typeId": 4, "subtype": 1}, {"nam' + \ 'e": "Volet roulant jardin", "id": 3, "scenes": ["Fermer vole' + \ 't jardin", "Ouvrir Volet jardin"], "category": "Roller shutt' + \ 'er", "typeId": 2, "subtype": 0}]}' devices.data_import(json.loads(get_response)) self.assertEqual(len(devices), 4) self.assertEqual(devices[0], RollerShutter(pyvlx, 0, 'Volet roulant cour', 0, 2)) self.assertEqual(devices[1], Window(pyvlx, 1, 'Fenêtre cour', 1, 4)) self.assertEqual(devices[2], Window(pyvlx, 2, 'Fenêtre jardin', 1, 4)) self.assertEqual(devices[3], RollerShutter(pyvlx, 3, 'Volet roulant jardin', 0, 2))
def test_str(self): """Test string representation of RollerShutter objec.""" pyvlx = PyVLX() rollershutter = RollerShutter(pyvlx, 0, 'Test Shutter', 0, 2) self.assertEqual( str(rollershutter), '<RollerShutter name="Test Shutter" id="0" subtype="0" ' 'typeId="2" />')
def test_nq(self): """Testing eq method with negative results.""" pyvlx = PyVLX() node1 = Blind(pyvlx=pyvlx, node_id=23, name='xxx') node2 = Blind(pyvlx=pyvlx, node_id=24, name='xxx') node3 = RollerShutter(pyvlx=pyvlx, node_id=23, name='xxx') self.assertNotEqual(node1, node2) self.assertNotEqual(node2, node3) self.assertNotEqual(node3, node1)
def test_roller_shutter_str(self): """Test string representation of RolllerShutter object.""" pyvlx = PyVLX() roller_shutter = RollerShutter(pyvlx=pyvlx, node_id=23, name='Test Roller Shutter') self.assertEqual( str(roller_shutter), '<RollerShutter name="Test Roller Shutter" node_id="23"/>')
def test_roller_shutter(self): """Test convert_frame_to_node roller shutter.""" frame = FrameGetNodeInformationNotification() frame.node_id = 23 frame.name = "Fnord23" frame.node_type = NodeTypeWithSubtype.ROLLER_SHUTTER pyvlx = PyVLX() node = convert_frame_to_node(pyvlx, frame) self.assertEqual( node, RollerShutter(pyvlx=pyvlx, name="Fnord23", node_id=23))
def test_roller_shutter_str(self): """Test string representation of RolllerShutter object.""" pyvlx = PyVLX() roller_shutter = RollerShutter( pyvlx=pyvlx, node_id=23, name="Test Roller Shutter", serial_number="aa:bb:aa:bb:aa:bb:aa:23", position_parameter=Parameter( Parameter.from_int(int(0.97 * Parameter.MAX))), ) self.assertEqual( str(roller_shutter), '<RollerShutter name="Test Roller Shutter" node_id="23" serial_number="aa:bb:aa:bb:aa:bb:aa:23" position="97 %"/>', )
def test_get_item(self): """Test get_item.""" pyvlx = PyVLX() nodes = Nodes(pyvlx) window = Window(pyvlx, 0, 'Window') nodes.add(window) blind = Blind(pyvlx, 1, 'Blind') nodes.add(blind) roller_shutter = RollerShutter(pyvlx, 4, 'Roller Shutter') nodes.add(roller_shutter) self.assertEqual(nodes['Window'], window) self.assertEqual(nodes['Blind'], blind) self.assertEqual(nodes['Roller Shutter'], roller_shutter) self.assertEqual(nodes[0], window) self.assertEqual(nodes[1], blind) self.assertEqual(nodes[4], roller_shutter)
def test_get_item(self): """Test get_item.""" pyvlx = PyVLX() nodes = Nodes(pyvlx) window = Window(pyvlx, 0, "Window", "aa:bb:aa:bb:aa:bb:aa:00") nodes.add(window) blind = Blind(pyvlx, 1, "Blind", "aa:bb:aa:bb:aa:bb:aa:01") nodes.add(blind) roller_shutter = RollerShutter(pyvlx, 4, "Roller Shutter", "aa:bb:aa:bb:aa:bb:aa:04") nodes.add(roller_shutter) self.assertEqual(nodes["Window"], window) self.assertEqual(nodes["Blind"], blind) self.assertEqual(nodes["Roller Shutter"], roller_shutter) self.assertEqual(nodes[0], window) self.assertEqual(nodes[1], blind) self.assertEqual(nodes[4], roller_shutter)
def test_nq(self): """Testing eq method with negative results.""" pyvlx = PyVLX() node1 = Blind(pyvlx=pyvlx, node_id=23, name="xxx", serial_number="aa:bb:aa:bb:aa:bb:aa:23") node2 = Blind(pyvlx=pyvlx, node_id=24, name="xxx", serial_number="aa:bb:aa:bb:aa:bb:aa:24") node3 = RollerShutter(pyvlx=pyvlx, node_id=23, name="xxx", serial_number="aa:bb:aa:bb:aa:bb:aa:23") self.assertNotEqual(node1, node2) self.assertNotEqual(node2, node3) self.assertNotEqual(node3, node1)
def test_get_name(self): """Test get_name().""" pyvlx = PyVLX() rollershutter = RollerShutter(pyvlx, 0, 'Test Shutter', 0, 2) self.assertEqual(rollershutter.get_name(), "Test Shutter")