def _decode_computer(self, p_logmsg, p_topic, p_message): p_logmsg += '\tComputer:\n' # computer/browser/*** if p_topic[1] == 'browser': l_name = 'unknown' p_logmsg += '\tBrowser: Message {}'.format( PrettyFormatAny.form(p_message, 'Computer msg', 160)) # computer/ip elif p_topic[1] == 'ip': l_ip = self._get_field(p_message, 'ExternalIPv4Address') p_logmsg += '\tIPv4: {}'.format(l_ip) # computer/startup elif p_topic[1] == 'startup': self._extract_node(p_message) p_logmsg += '\tStartup {}'.format( PrettyFormatAny.form(p_message, 'Computer msg', 160)) if self.m_myname == self.m_sender: p_logmsg += '\tMy own startup of PyHouse\n' else: p_logmsg += '\tAnother computer started up: {}'.format( self.m_sender) # computer/shutdown elif p_topic[1] == 'shutdown': del self.m_pyhouse_obj.Computer.Nodes[self.m_name] p_logmsg += '\tSelf Shutdown {}'.format( PrettyFormatAny.form(p_message, 'Computer msg', 160)) # computer/node/??? elif p_topic[1] == 'node': p_logmsg += syncAPI(self.m_pyhouse_obj).DecodeMqttMessage( p_topic, p_message) # computer/*** else: p_logmsg += '\tUnknown sub-topic {}'.format( PrettyFormatAny.form(p_message, 'Computer msg', 160)) return p_logmsg
def test_01_CreateJson(self): """ Create a JSON object for Location. """ l_obj = lightsAPI.read_all_lights_xml(self.m_pyhouse_obj, self.m_xml.light_sect) print(PrettyFormatAny.form(l_obj, 'Lights')) l_json = json_tools.encode_json(l_obj) print(PrettyFormatAny.form(l_json, 'JSON'))
def test_3_Node_0(self): print(PrettyFormatAny.form(self.m_xml.node, 'B1-3-A One Node XML')) l_node = nodesXml._read_one_node_xml(self.m_xml.node) print(PrettyFormatAny.form(l_node, 'B1-3-B One Node', 108)) self.assertEqual(l_node.Name, TESTING_NODES_NODE_NAME_0) self.assertEqual(l_node.Key, int(TESTING_NODES_NODE_KEY_0)) self.assertEqual(l_node.Active, bool(TESTING_NODES_NODE_ACTIVE_0)) self.assertEqual(l_node.NodeRole, int(TESTING_NODES_NODE_ROLL_0))
def test_01_FindXml(self): """ Be sure that the XML contains the right stuff. """ self.assertEqual(self.m_xml.root.tag, 'PyHouse', 'Invalid XML - not a PyHouse XML config file') self.assertEqual(self.m_xml.house_div.tag, 'HouseDivision', 'XML - No House Division') print(PrettyFormatAny.form(self.m_pyhouse_obj, 'Pyhouse', 120)) print(PrettyFormatAny.form(self.m_pyhouse_obj.Computer, 'Pyhouse', 120)) print(PrettyFormatAny.form(self.m_pyhouse_obj.House, 'Pyhouse', 120))
def test_4_Node_1(self): l_ix = self.m_xml.node_sect[1] print(PrettyFormatAny.form(l_ix, 'B1-4-A One Node XML')) l_node = nodesXml._read_one_node_xml(l_ix) print(PrettyFormatAny.form(l_node, 'B1-4-B One Node', 108)) self.assertEqual(l_node.Name, TESTING_NODES_NODE_NAME_1) self.assertEqual(l_node.Key, int(TESTING_NODES_NODE_KEY_1)) self.assertEqual(l_node.Active, bool(TESTING_NODES_NODE_ACTIVE_1)) self.assertEqual(l_node.NodeRole, int(TESTING_NODES_NODE_ROLL_1))
def test_03_AddrLists(self): """ I don't know how to test the returned list for validity. Uncomment the print to see what your computer returned. """ l_names = Interfaces.find_all_interface_names() # On my laptop: returns 7 interfaces. print(PrettyFormatAny.form(l_names, 'Address Lists')) l_ret = Interfaces._find_addr_lists(l_names[0]) print(PrettyFormatAny.form(l_ret, 'Address Lists'))
def test_04_Interfaces(self): l_int = Interfaces._list_interfaces() for l_name in l_int: l_ifa = Interfaces._list_ifaddresses(l_name) print(PrettyFormatAny.form(l_ifa, 'A2-04 Interface Addresses', 170)) l_all = Interfaces._get_all_interfaces() print(PrettyFormatAny.form(l_int, 'A2-04 Interfaces', 170)) for l_ix in l_all: print('{} {}'.format(l_ix, PrettyFormatAny.form(l_all[l_ix], 'Interface', 170))) print(PrettyFormatAny.form(l_all, 'A2-04 Interfaces', 170))
def test_03_AllLogins(self): """ Read all login objects. """ l_xml = self.m_xml.web_sect l_obj, l_count = webXml._read_all_logins(l_xml) print(PrettyFormatAny.form(l_xml, 'XML')) print(PrettyFormatAny.form(l_obj, 'All login')) print(PrettyFormatAny.form(l_obj[0], 'All login')) self.assertEqual(l_count, 2) self.assertEqual(len(l_obj), 2)
def test_01_Add(self): l_node = nodesXml._read_one_node_xml(self.m_xml.node) print(PrettyFormatAny.form(l_node, 'Node')) l_json = json_tools.encode_json(l_node) print(PrettyFormatAny.form(l_json, 'PyHouse')) l_msg = json_tools.decode_json_unicode(l_json) Util.add_node(self.m_pyhouse_obj, l_msg) print( PrettyFormatAny.form(self.m_pyhouse_obj.Computer.Nodes, 'PyHouse')) self.assertNotEqual(self.m_pyhouse_obj.Xml, TESTING_NODES_NODE_NAME_0)
def test_01_Interface(self): l_ctlr = self.m_xml.controller_sect[1] l_device = ControllerData() l_obj = lightingcoreAPI.read_core_lighting_xml(l_device, l_ctlr, self.m_version) print(PrettyFormatAny.form(l_obj, 'L L')) L_interface = usbXML.read_interface_xml(l_ctlr) stuff_new_attrs(l_obj, L_interface) print(PrettyFormatAny.form(l_obj, 'L L')) self.assertEqual(l_obj.Vendor, int(TESTING_USB_VENDOR)) self.assertEqual(l_obj.Product, int(TESTING_USB_PRODUCT))
def test_02_OneLogin(self): """ Read one Login object. """ l_xml = self.m_xml.login_sect.find('Login') l_obj = webXml._read_one_login(l_xml) print(PrettyFormatAny.form(l_xml, 'XML')) print(PrettyFormatAny.form(l_obj, 'One login')) self.assertEqual(l_obj.Name, TESTING_LOGIN_NAME_0) self.assertEqual(l_obj.LoginFullName, TESTING_LOGIN_FULL_NAME_0) self.assertEqual(l_obj.LoginPasswordCurrent, TESTING_LOGIN_PASSWORD_0) self.assertEqual(l_obj.LoginRole, TESTING_LOGIN_ROLE_0)
def test_02_Data(self): self.m_pyhouse_obj.Computer.Nodes = nodes_xml.Xml.read_all_nodes_xml( self.m_pyhouse_obj) print( PrettyFormatAny.form(self.m_pyhouse_obj.Computer.Nodes, 'PyHouse Computer Nodes')) print( PrettyFormatAny.form( self.m_pyhouse_obj.Computer.Nodes[TESTING_NODES_NODE_NAME_0], 'PyHouse Computer Nodes')) self.assertEqual(len(self.m_pyhouse_obj.Computer.Nodes), 2)
def test_05_AllLights(self): l_objs = lightsAPI.read_all_lights_xml(self.m_pyhouse_obj, self.m_xml.light_sect) self.m_pyhouse_obj.House.Lighting = LightingData() self.m_pyhouse_obj.House.Lighting.Lights = l_objs print(PrettyFormatAny.form(self.m_pyhouse_obj.House, 'PyHouse')) self.m_pyhouse_obj.House.Lighting.Lights = l_objs print(PrettyFormatAny.form(l_objs, 'Lights')) l_xml = lightsAPI.write_all_lights_xml(self.m_pyhouse_obj) print(PrettyFormatAny.form(l_xml, 'Lights XML')) l_xml0 = l_xml.find('Light') self.assertEqual(l_xml0.find('UUID').text, TESTING_LIGHT_UUID_0) self.assertEqual(l_xml0.find('Comment').text, TESTING_LIGHT_COMMENT_0)
def DecodeMqttMessage(self, p_topic, p_message): l_msg = '\tNodeSync\n' if p_topic[2] == 'whoisthere': l_msg += '\tName: {} who is there'.format(p_message['Name']) l_msg += '\t {}\n'.format( PrettyFormatAny.form(p_message, 'Who Is There Message', 160)) Util.send_i_am(self.m_pyhouse_obj) elif p_topic[2] == 'iam': l_msg += '\tName {} i am'.format(p_message['Name']) l_msg += '\t {}\n'.format( PrettyFormatAny.form(p_message, 'I Am Message', 160)) Util.add_node(self.m_pyhouse_obj, p_message) else: l_msg += '*** Unknown Message type {}'.format(p_topic) return l_msg
def _decode_weather(self, p_logmsg, p_topic, p_message): p_logmsg += '\tWeather:\n' l_temp = float(self._get_field(p_message, 'Temperature')) p_logmsg += '\tName: {}\n'.format(self._get_field(p_message, 'Location')) p_logmsg += '\tTemp: {} ({})'.format(l_temp, ((l_temp / 5.0) * 9.0) + 32.0) p_logmsg += '\tWeather info {}'.format(PrettyFormatAny.form(p_message, 'Weather msg', 160)) return p_logmsg
def test_01_OneInterface(self): l_interface = nodesXml._read_one_interface_xml(self.m_xml.interface) l_xml = nodesXml._write_one_interface_xml(l_interface) print(PrettyFormatAny.form(l_xml, 'One Interface')) self.assertEqual(l_xml.attrib['Name'], 'eth0') self.assertEqual(l_xml.attrib['Key'], '0') self.assertEqual(l_xml.attrib['Active'], 'True')
def test_03_AllLogins(self): """ Write All logins. """ l_obj = self.m_web_obj.Logins l_xml = webXml._write_all_logins(l_obj) print(PrettyFormatAny.form(l_xml, 'Web')) self.assertEqual(l_xml.find('Login/FullName').text, TESTING_LOGIN_FULL_NAME_0)
def test_04_Add(self): l_obj_0 = UuidData() l_obj_0.UUID = '12345678-dead-beef-dead-fedcba987654' l_obj_0.UuidType = 'House' Uuid.add_uuid(self.m_pyhouse_obj, l_obj_0) print(PrettyFormatAny.form(self.m_pyhouse_obj.Uuids, 'B1-4-A one')) self.assertEqual(self.m_pyhouse_obj.Uuids[l_obj_0.UUID].UuidType, l_obj_0.UuidType) # l_obj_1 = UuidData() l_obj_1.UUID = '01234567-dead-beef-dead-fedcba987654' l_obj_1.UuidType = 'Room' Uuid.add_uuid(self.m_pyhouse_obj, l_obj_1) print(PrettyFormatAny.form(self.m_pyhouse_obj.Uuids, 'B1-4-B two')) self.assertEqual(self.m_pyhouse_obj.Uuids[l_obj_1.UUID].UuidType, l_obj_1.UuidType)
def test_04_OneLight(self): """ Write out the XML file for the location section """ l_obj = Utility._read_one_light_xml(self.m_pyhouse_obj, self.m_xml.light) l_xml = Utility._write_one_light_xml(self.m_pyhouse_obj, l_obj) print(PrettyFormatAny.form(l_xml, 'XML')) self.assertEqual(l_xml.attrib['Name'], TESTING_LIGHT_NAME_0) self.assertEqual(l_xml.attrib['Key'], TESTING_LIGHT_KEY_0) self.assertEqual(l_xml.attrib['Active'], TESTING_LIGHT_ACTIVE_0) self.assertEqual(l_xml.find('UUID').text, TESTING_LIGHT_UUID_0) self.assertEqual(l_xml.find('Comment').text, TESTING_LIGHT_COMMENT_0) self.assertEqual( l_xml.find('DeviceFamily').text, TESTING_DEVICE_FAMILY_INSTEON) self.assertEqual( l_xml.find('RoomName').text, TESTING_LIGHT_ROOM_NAME_0) self.assertEqual( l_xml.find('RoomUUID').text, TESTING_LIGHT_ROOM_UUID_0) self.assertEqual( l_xml.find('CurLevel').text, TESTING_LIGHT_CUR_LEVEL_0) self.assertEqual( l_xml.find('IsDimmable').text, TESTING_LIGHT_IS_DIMMABLE_0) self.assertEqual( l_xml.find('InsteonAddress').text, TESTING_INSTEON_ADDRESS_0) self.assertEqual(l_xml.find('DevCat').text, TESTING_INSTEON_DEVCAT_0) self.assertEqual( l_xml.find('GroupList').text, TESTING_INSTEON_GROUP_LIST_0) self.assertEqual( l_xml.find('GroupNumber').text, TESTING_INSTEON_GROUP_NUM_0) self.assertEqual( l_xml.find('ProductKey').text, TESTING_INSTEON_PRODUCT_KEY_0)
def test_04_Web(self): """ Write All logins. """ l_xml = webXml.write_web_xml(self.m_pyhouse_obj) print(PrettyFormatAny.form(l_xml, 'Web')) self.assertEqual(l_xml.find('Port').text, TESTING_WEB_PORT) self.assertEqual(l_xml.find('LoginSection/Login/FullName').text, TESTING_LOGIN_FULL_NAME_0)
def test_03_OneNode(self): l_node = nodesXml._read_one_node_xml(self.m_xml.node) l_xml = nodesXml._write_one_node_xml(l_node) print(PrettyFormatAny.form(l_xml, 'All Interfaces')) self.assertEqual(l_xml.attrib['Name'], 'pi-01') self.assertEqual(l_xml.attrib['Key'], '0') self.assertEqual(l_xml.attrib['Active'], 'True')
def test_01_BaseObject(self): l_base_obj = CoreLightingData() self.m_api.read_base_object_xml(l_base_obj, self.m_xml.light) print(PrettyFormatAny.form(l_base_obj)) self.assertEqual(l_base_obj.Name, 'None') self.assertEqual(l_base_obj.Key, 0) self.assertEqual(l_base_obj.Active, False)
def mqtt_dispatch(self, p_topic, p_message): """ """ self.m_sender = self._get_field(p_message, 'Sender') self.m_name = self._get_field(p_message, 'Name') self.m_room_name = self._get_field(p_message, 'RoomName') l_logmsg = 'Dispatch\n\tTopic: {}\n'.format(p_topic) l_logmsg += '\tSender: {}\n'.format(self.m_sender) if p_topic[0] == 'computer': l_logmsg = self._decode_computer(l_logmsg, p_topic, p_message) elif p_topic[0] == 'hvac': l_logmsg = self._decode_hvac(l_logmsg, p_topic, p_message) elif p_topic[0] == 'lighting': l_logmsg = self._decode_lighting(l_logmsg, p_topic, p_message) elif p_topic[0] == 'room': l_logmsg = Rooms(self.m_pyhouse_obj)._decode_room( l_logmsg, p_topic, p_message) elif p_topic[0] == 'schedule': l_logmsg = self._decode_schedule(l_logmsg, p_topic, p_message) elif p_topic[0] == 'weather': l_logmsg = self._decode_weather(l_logmsg, p_topic, p_message) else: l_logmsg += 'OTHER: Unknown' l_logmsg += '\tMessage: {}\n'.format( PrettyFormatAny.form(p_message, 'Message', 160)) return l_logmsg
def test_2_Controllers(self): """ Be sure that the XML contains the right stuff. """ l_xml = self.m_xml.controller_sect print(PrettyFormatAny.form(l_xml, 'Controllers')) self.assertEqual(l_xml[0].attrib['Name'], TESTING_CONTROLLER_NAME_0) self.assertEqual(l_xml[1].attrib['Name'], TESTING_CONTROLLER_NAME_1)
def test_06_OneController(self): """ Read in the xml file and fill in the lights """ l_obj = Utility._read_one_controller_xml(self.m_pyhouse_obj, self.m_xml.controller) print(PrettyFormatAny.form(l_obj, 'B1-06-A - OneController', 100)) self.assertEqual(l_obj.Name, TESTING_CONTROLLER_NAME_0) self.assertEqual(l_obj.Active, (TESTING_CONTROLLER_ACTIVE_0 == 'True')) self.assertEqual(l_obj.LightingType, TESTING_CONTROLLER_TYPE_0) self.assertEqual(l_obj.Comment, TESTING_DEVICE_COMMENT) self.assertEqual(l_obj.DeviceFamily, TESTING_DEVICE_FAMILY_INSTEON) self.assertEqual(l_obj.DeviceType, int(TESTING_DEVICE_TYPE)) self.assertEqual(l_obj.DeviceSubType, int(TESTING_DEVICE_SUBTYPE)) self.assertEqual(l_obj.RoomName, TESTING_DEVICE_ROOM_NAME) self.assertEqual(l_obj.InterfaceType, TESTING_INTERFACE_TYPE_SERIAL) self.assertEqual(l_obj.Port, TESTING_INTERFACE_PORT_SERIAL) self.assertEqual(l_obj.BaudRate, int(TESTING_SERIAL_BAUD_RATE)) self.assertEqual(l_obj.ByteSize, int(TESTING_SERIAL_BYTE_SIZE)) self.assertEqual(l_obj.Parity, TESTING_SERIAL_PARITY) self.assertEqual(str(l_obj.RtsCts), TESTING_SERIAL_RTS_CTS) self.assertEqual(l_obj.StopBits, float(TESTING_SERIAL_STOP_BITS)) self.assertEqual(l_obj.Timeout, float(TESTING_SERIAL_TIMEOUT)) self.assertEqual(l_obj.XonXoff, TESTING_SERIAL_XON_XOFF == 'True') self.assertEqual(l_obj.InsteonAddress, conversions.dotted_hex2int(TESTING_INSTEON_ADDRESS_0)) self.assertEqual(l_obj.DevCat, conversions.dotted_hex2int(TESTING_INSTEON_DEVCAT_0)) self.assertEqual(l_obj.GroupList, TESTING_INSTEON_GROUP_LIST_0) self.assertEqual(l_obj.GroupNumber, int(TESTING_INSTEON_GROUP_NUM_0))
def test_03_OneNode(self): l_node = nodesXml._read_one_node_xml(self.m_xml.node) print(PrettyFormatAny.form(l_node, 'One Node')) self.assertEqual(l_node.Name, TESTING_NODES_NODE_NAME_0, 'Bad Name') self.assertEqual(l_node.Key, 0, 'Bad Key') self.assertEqual(l_node.Active, True, 'Bad Active') self.assertEqual(l_node.NodeRole, 0, 'Bad NodeRole')
def test_06_OneController(self): """ Read in the xml file and fill in the lights """ l_obj = Utility._read_one_controller_xml(self.m_pyhouse_obj, self.m_xml.controller, self.m_version) print(PrettyFormatAny.form(l_obj, 'OneController', 100)) self.assertEqual(l_obj.Name, TESTING_CONTROLLER_NAME_0) self.assertEqual(l_obj.Active, (TESTING_CONTROLLER_ACTIVE_0 == 'True')) self.assertEqual(l_obj.LightingType, TESTING_CONTROLLER_TYPE_0) self.assertEqual(l_obj.Comment, TESTING_DEVICE_COMMENT) self.assertEqual(l_obj.DeviceFamily, TESTING_DEVICE_FAMILY_INSTEON) self.assertEqual(l_obj.DeviceType, int(TESTING_DEVICE_TYPE)) self.assertEqual(l_obj.DeviceSubType, int(TESTING_DEVICE_SUBTYPE)) self.assertEqual(l_obj.RoomName, TESTING_DEVICE_ROOM_NAME) self.assertEqual(l_obj.InterfaceType, TESTING_INTERFACE_TYPE_SERIAL) self.assertEqual(l_obj.Port, TESTING_INTERFACE_PORT_SERIAL) self.assertEqual(l_obj.BaudRate, int(TESTING_SERIAL_BAUD_RATE)) self.assertEqual(l_obj.ByteSize, int(TESTING_SERIAL_BYTE_SIZE)) self.assertEqual(l_obj.Parity, TESTING_SERIAL_PARITY) self.assertEqual(l_obj.RtsCts, TESTING_SERIAL_RTS_CTS == 'True') self.assertEqual(l_obj.StopBits, float(TESTING_SERIAL_STOP_BITS)) self.assertEqual(l_obj.Timeout, float(TESTING_SERIAL_TIMEOUT)) self.assertEqual(l_obj.XonXoff, TESTING_SERIAL_XON_XOFF == 'True') self.assertEqual(l_obj.InsteonAddress, conversions.dotted_hex2int(TESTING_INSTEON_ADDRESS_0)) self.assertEqual(l_obj.DevCat, conversions.dotted_hex2int(TESTING_INSTEON_DEVCAT_0)) self.assertEqual(l_obj.GroupList, TESTING_INSTEON_GROUP_LIST_0) self.assertEqual(l_obj.GroupNumber, int(TESTING_INSTEON_GROUP_NUM_0))
def test_01_Zone(self): """ """ l_xml = self.m_xml.irrigation_zone l_obj = self.m_api._read_one_zone(l_xml) print(PrettyFormatAny.form(l_obj, 'B1-01-A - Zone')) self.assertEqual(l_obj.Name, 'Front Rotors # 1')
def test_01_write_house_xml(self): l_house_obj = houseXml.read_house_xml(self.m_pyhouse_obj) self.m_pyhouse_obj.House = l_house_obj l_xml = houseXml.write_house_xml(self.m_pyhouse_obj) print(PrettyFormatAny.form(l_xml, 'XML')) self.assertEqual(l_xml.tag, 'HouseDivision') self.assertEqual(l_xml.attrib['Name'], TESTING_HOUSE_NAME)
def test_03_AllPools(self): """ Read all pool info """ l_obj = poolXml.read_all_pools_xml(self.m_pyhouse_obj) print(PrettyFormatAny.form(l_obj, 'Pool')) # print(PrettyFormatAny.form(l_obj[0], 'Pool')) self.assertEqual(len(l_obj), 2)
def test_03_Sched(self): SetupPyHouseObj().LoadHouse(self.m_pyhouse_obj) print(PrettyFormatAny.form(self.m_pyhouse_obj.House, 'PyHouse.House 1')) l_delay = 1 l_list = [0, 1] l_id = scheduleUtility.schedule_next_event(self.m_pyhouse_obj, l_delay) time.sleep(2 * l_delay)
def test_02_AllInterfaces(self): l_interfaces = nodesXml._read_interfaces_xml(self.m_xml.interface_sect) print(PrettyFormatAny.form(l_interfaces, 'Interfaces')) self.assertEqual(len(l_interfaces), 3) self.assertEqual(l_interfaces[0].Name, TESTING_NODES_INTERFACE_NAME_0_0, 'Bad Name') self.assertEqual(l_interfaces[1].Name, TESTING_NODES_INTERFACE_NAME_0_1, 'Bad Name') self.assertEqual(l_interfaces[2].Name, 'lo', 'Bad Name') self.assertEqual(len(l_interfaces), 3, 'Wrong interface count.')
def test_01_one(self): """ No way to test the dispatch routine """ self.m_pyhouse_obj.House.Schedules[0].ScheduleType = 'TeStInG14159' # to set dispatch to testing l_schedule = self.m_pyhouse_obj.House.Schedules[0] print(PrettyFormatAny.form(l_schedule, 'C1-01-A - Sched')) ScheduleExecution.dispatch_one_schedule(self.m_pyhouse_obj, l_schedule) self.assertEqual(True, True)
def test_02_AddrFamilyName(self): """ We are interested in: IPv4 (AF_INET) IPv6 (AF_INET6) MAC (AF_LINK) """ l_ret = Interfaces._find_addr_family_name(17) print(PrettyFormatAny.form(l_ret, 'B1-02 Address Lists')) self.assertEqual(l_ret, 'AF_PACKET') l_ret = Interfaces._find_addr_family_name(2) print(PrettyFormatAny.form(l_ret, 'B1-02 Address Lists')) self.assertEqual(l_ret, 'AF_INET') l_ret = Interfaces._find_addr_family_name(23) print(PrettyFormatAny.form(l_ret, 'B1-02 Address Lists')) self.assertEqual(l_ret, 'AF_INET6')
def test_04_Web(self): """ Read all Web info. """ self.m_pyhouse_obj.Computer.Web = webXml.read_web_xml(self.m_pyhouse_obj) l_obj = webXml.read_web_xml(self.m_pyhouse_obj) print(PrettyFormatAny.form(l_obj, 'All Web')) self.assertEqual(l_obj.WebPort, int(TESTING_WEB_PORT)) self.assertEqual(len(l_obj.Logins), 2)
def test_01_PyHouse(self): """ Be sure that the XML contains the right stuff. """ print(PrettyFormatAny.form(self.m_xml, 'A1-01-A - Tags')) self.assertEqual(self.m_xml.root.tag, 'PyHouse') self.assertEqual(self.m_xml.computer_div.tag, 'ComputerDivision') self.assertEqual(self.m_xml.mqtt_sect.tag, 'MqttSection') self.assertEqual(self.m_xml.broker.tag, 'Broker')
def test_5_AllNodes(self): l_nodes = nodesXml.read_all_nodes_xml(self.m_pyhouse_obj) print(PrettyFormatAny.form(l_nodes, 'B1-5 All Nodes', 108)) # print(PrettyFormatAny.form(l_nodes[TESTING_NODES_NODE_NAME_0], 'Node 0', 10)) # print(PrettyFormatAny.form(l_nodes[TESTING_NODES_NODE_NAME_0].NodeInterfaces, 'All Nodes', 10)) self.assertEqual(len(l_nodes), 2) self.assertEqual(l_nodes[TESTING_NODES_NODE_UUID_0].Name, TESTING_NODES_NODE_NAME_0) self.assertEqual(l_nodes[TESTING_NODES_NODE_UUID_1].Name, TESTING_NODES_NODE_NAME_1)
def test_01_Xml(self): """ Did we get the XML correctly """ l_xml = self.m_xml.light print(PrettyFormatAny.form(l_xml, 'XML')) self.assertEqual(l_xml.attrib['Name'], TESTING_LIGHT_NAME_0) self.assertEqual( l_xml.find('DeviceFamily').text, TESTING_DEVICE_FAMILY_INSTEON)
def test_03_AllLogins(self): """ Write All logins. """ l_obj = self.m_web_obj.Logins l_xml = webXml._write_all_logins(l_obj) print(PrettyFormatAny.form(l_xml, 'Web')) self.assertEqual( l_xml.find('Login/FullName').text, TESTING_LOGIN_FULL_NAME_0)
def test_03_Family(self): """ Did we get everything set up for the rest of the tests of this class. """ l_xml = self.m_xml.light l_device = self.m_device_obj l_light = FamUtil.read_family_data(self.m_pyhouse_obj, l_device, l_xml) print(PrettyFormatAny.form(l_light, 'Light')) self.assertEqual(l_light.InsteonAddress, conversions.dotted_hex2int(TESTING_INSTEON_ADDRESS_0))
def test_01_OneInterface(self): l_interface = nodesXml._read_one_interface_xml(self.m_xml.interface) print(PrettyFormatAny.form(l_interface, 'Interface')) self.assertEqual(l_interface.Name, TESTING_NODES_INTERFACE_NAME_0_0, 'Bad Name') self.assertEqual(l_interface.Key, int(TESTING_NODES_INTERFACE_KEY_0_0), 'Bad Key') self.assertEqual(l_interface.Active, bool(TESTING_NODES_INTERFACE_ACTIVE_0_0), 'Bad Active') self.assertEqual(l_interface.MacAddress, TESTING_NODES_INTERFACE_MAC_ADDRESS_0_0, 'Bad MacAddress') self.assertEqual(l_interface.V4Address, TESTING_NODES_INTERFACE_ADDRESS_V4_0_0, 'Bad V4Address') self.assertEqual(l_interface.V6Address, TESTING_NODES_INTERFACE_ADDRESS_V6_0_0)
def test_05_AllLights(self): l_objs = lightsAPI.read_all_lights_xml(self.m_pyhouse_obj, self.m_xml.light_sect, self.m_version) self.m_pyhouse_obj.House.Lighting.Lights = l_objs # print(PrettyFormatAny.form(l_objs, 'Lights')) l_xml = lightsAPI.write_all_lights_xml(self.m_pyhouse_obj) print(PrettyFormatAny.form(l_xml, 'Lights XML')) l_xml0 = l_xml.find('Light') self.assertEqual(l_xml0.find('UUID').text, TESTING_DEVICE_UUID) self.assertEqual(l_xml0.find('Comment').text, TESTING_DEVICE_COMMENT)
def test_02_GetFamilyObj(self): l_obj = FamUtil._get_family_obj(self.m_pyhouse_obj, self.m_device_obj) print(PrettyFormatAny.form(l_obj, 'Family')) self.assertEqual(l_obj.Name, TESTING_LIGHT_NAME_0) self.assertEqual(l_obj.Active, True) self.assertEqual(l_obj.Key, 1) self.assertEqual(l_obj.FamilyDeviceModuleName, 'Insteon_device') self.assertEqual(l_obj.FamilyPackageName, 'Modules.Families.Insteon') self.assertEqual(l_obj.FamilyXmlModuleName, 'Insteon_xml')
def test_04_Web(self): """ Read all Web info. """ self.m_pyhouse_obj.Computer.Web = webXml.read_web_xml( self.m_pyhouse_obj) l_obj = webXml.read_web_xml(self.m_pyhouse_obj) print(PrettyFormatAny.form(l_obj, 'All Web')) self.assertEqual(l_obj.WebPort, int(TESTING_WEB_PORT)) self.assertEqual(len(l_obj.Logins), 2)
def test_04_Web(self): """ Write All logins. """ l_xml = webXml.write_web_xml(self.m_pyhouse_obj) print(PrettyFormatAny.form(l_xml, 'Web')) self.assertEqual(l_xml.find('Port').text, TESTING_WEB_PORT) self.assertEqual( l_xml.find('LoginSection/Login/FullName').text, TESTING_LOGIN_FULL_NAME_0)
def test_04_GetInsteon(self): """ Did we get a family? """ l_family = FamUtil.get_family(self.m_device_obj) print(PrettyFormatAny.form(l_family, 'Family')) self.assertEqual(l_family, TESTING_DEVICE_FAMILY_INSTEON) self.m_device_obj.DeviceFamily = 'UPB' l_family = FamUtil.get_family(self.m_device_obj) self.assertEqual(l_family, 'UPB')
def _open_find_device(p_USB_obj): """First step in opening a USB device. @return: None if no such device or a pyusb device object """ l_vpn = Utility.format_names(p_USB_obj) l_device = None try: l_device = usb.core.find(idVendor = p_USB_obj.Vendor, idProduct = p_USB_obj.Product) except (usb.USBError, ValueError): LOG.error("ERROR no such USB device for {}".format(l_vpn)) return None if l_device == None: LOG.error('ERROR - USB device not found {}'.format(l_vpn)) return None LOG.debug(PrettyFormatAny.form(l_device, 'Device')) LOG.debug(PrettyFormatAny.form(p_USB_obj, 'pUSB_obj')) p_USB_obj.UsbDevice = API._save_find_device(p_USB_obj, l_device) LOG.info('Found a device - HID: {}'.format(l_vpn)) return l_device
def test_01_AllIfaceNames(self): """ This will be different on different computers I don't know how to test the returned list for validity. Uncomment the print to see what your computer returned. """ print('B1-01') l_names = Interfaces.find_all_interface_names() print(PrettyFormatAny.form(l_names, 'B1-01 Names')) self.assertGreater(len(l_names), 1)
def test_02_BaseObject(self): """Write Base Object XML w/ NO UUID """ l_base_obj = CoreLightingData() XmlConfigTools.read_base_object_xml(l_base_obj, self.m_xml.light) l_base_obj.Key = 44 l_xml = XmlConfigTools.write_base_object_xml('Light', l_base_obj, no_uuid = True) print(PrettyFormatAny.form(l_xml, 'XML')) self.assertEqual(l_xml.attrib['Name'], 'Insteon Light') self.assertEqual(l_xml.attrib['Key'], '44')
def test_02_LightData(self): l_obj = Utility._read_one_light_xml(self.m_pyhouse_obj, self.m_xml.light) l_xml = Utility._write_base_device('Light', l_obj) Utility._write_light_data(l_obj, l_xml) print(PrettyFormatAny.form(l_xml, 'XML')) self.assertEqual( l_xml.find('CurLevel').text, TESTING_LIGHT_CUR_LEVEL_0) self.assertEqual( l_xml.find('IsDimmable').text, TESTING_LIGHT_DIMMABLE_1)
def _decode_schedule(self, p_logmsg, p_topic, p_message): p_logmsg += '\tSchedule:\n' if p_topic[1] == 'execute': p_logmsg += '\tType: {}\n'.format(self._get_field(p_message, 'ScheduleType')) p_logmsg += '\tRoom: {}\n'.format(self.m_room_name) p_logmsg += '\tLight: {}\n'.format(self._get_field(p_message, 'LightName')) p_logmsg += '\tLevel: {}'.format(self._get_field(p_message, 'Level')) else: p_logmsg += '\tUnknown sub-topic {}'.format(PrettyFormatAny.form(p_message, 'Schedule msg', 160)) return p_logmsg
def test_03_AllPools(self): """ Write Pool Section with all pools. """ l_xml = poolXml.write_all_pools_xml(self.m_pyhouse_obj) print(PrettyFormatAny.form(l_xml, 'Pool')) l_xml1 = l_xml.find('Pool') l_xml2 = l_xml[1] self.assertEqual(l_xml2.attrib['Name'], TESTING_POOL_NAME_1) self.assertEqual(l_xml2.attrib['Key'], TESTING_POOL_KEY_1) self.assertEqual(l_xml2.attrib['Active'], TESTING_POOL_ACTIVE_1) self.assertEqual(l_xml2.find('Comment').text, TESTING_POOL_COMMENT_1)
def _decode_computer(self, p_logmsg, p_topic, p_message): p_logmsg += '\tComputer:\n' if p_topic[1] == 'ip': l_ip = self._get_field(p_message, 'ExternalIPv4Address') p_logmsg += '\tIPv4: {}'.format(l_ip) elif p_topic[1] == 'startup': self._extract_node(p_message) p_logmsg += '\tStartup {}'.format(PrettyFormatAny.form(p_message, 'Computer msg', 160)) if self.m_myname == self.m_sender: p_logmsg += '\tMy own startup of PyHouse\n' else: p_logmsg += '\tAnother computer started up: {}'.format(self.m_sender) pass elif p_topic[1] == 'shutdown': del self.m_pyhouse_obj.Computer.Nodes[self.m_name] p_logmsg += '\tSelf Shutdown {}'.format(PrettyFormatAny.form(p_message, 'Computer msg', 160)) pass else: p_logmsg += '\tUnknown sub-topic {}'.format(PrettyFormatAny.form(p_message, 'Computer msg', 160)) return p_logmsg
def _initilaize_pim(p_controller_obj): """Initialize a new UPBData object. """ l_pim = UPBData() l_pim.InterfaceType = p_controller_obj.InterfaceType l_pim.Name = p_controller_obj.Name l_pim.UPBAddress = p_controller_obj.UPBAddress l_pim.UPBPassword = p_controller_obj.UPBPassword l_pim.UPBNetworkID = p_controller_obj.UPBNetworkID LOG.info('Initializing UPB PIM named: {}, Type={}'.format(l_pim.Name, l_pim.InterfaceType)) LOG.debug(PrettyFormatAny.form(l_pim, 'PIM data')) return l_pim
def test_01_BaseObject(self): """Write Base Object XML w/UUID """ l_base_obj = CoreLightingData() XmlConfigTools.read_base_object_xml(l_base_obj, self.m_xml.light) l_base_obj.Key = 43 l_uuid = '12345678-fedc-1111-ffff-aaBBccDDeeFF' l_base_obj.UUID = l_uuid l_xml = XmlConfigTools.write_base_object_xml('Light', l_base_obj) print(PrettyFormatAny.form(l_xml, 'XML')) self.assertEqual(l_xml.attrib['Name'], 'Insteon Light') self.assertEqual(l_xml.attrib['Key'], '43') self.assertEqual(l_xml.find('UUID').text, l_uuid)
def _get_family_obj(p_pyhouse_obj, p_device_obj): """ Given some device object, extract the Family Name """ try: l_family_obj = p_pyhouse_obj.House.FamilyData[p_device_obj.DeviceFamily] except KeyError as e_err: l_msg = PrettyFormatAny.form(p_pyhouse_obj.House.FamilyData, 'ERROR ') LOG.error('Could not get family object for:\n\tDevice Name:\t{}\n\tFamily:\t\t{}\n\tKey Error:\t{}{}'\ .format( p_device_obj.Name, p_device_obj.DeviceFamily, e_err, l_msg)) l_family_obj = p_pyhouse_obj.House.FamilyData['Null'] return l_family_obj
def test_01_Interface(self): l_ctlr = self.m_xml.controller_sect[1] l_device = ControllerData() l_obj = lightingcoreAPI.read_core_lighting_xml(l_device, l_ctlr, self.m_version) L_interface = usbXML.read_interface_xml(l_ctlr) stuff_new_attrs(l_obj, L_interface) # l_xml = lightingcoreAPI.write_core_lighting_xml('TestController', l_obj) usbXML.write_interface_xml(l_xml, l_obj) print(PrettyFormatAny.form(l_xml, 'XML')) self.assertEqual(l_xml.attrib['Name'], TESTING_CONTROLLER_NAME_1) self.assertEqual(l_xml.attrib['Key'], TESTING_CONTROLLER_KEY_1) self.assertEqual(l_xml.attrib['Active'], TESTING_CONTROLLER_ACTIVE_1) self.assertEqual(l_xml.find('Vendor').text, TESTING_USB_VENDOR) self.assertEqual(l_xml.find('Product').text, TESTING_USB_PRODUCT)