def saveMqttData(self, p_json): """Mqtt data is returned, so update the info. """ l_json = JsonUnicode().decode_json(p_json) l_delete = l_json['Delete'] l_ix = int(l_json['Key']) if l_delete: try: del self.m_pyhouse_obj.Computer.Mqtt.Brokers except AttributeError: LOG.error( "web_mqtt - Failed to delete - JSON: {0:}".format(l_json)) return try: l_obj = self.m_pyhouse_obj.Computer.Mqtt.Brokers[l_ix] except KeyError: LOG.warning('Creating a new Mqtt Broker Key: {}'.format(l_ix)) l_obj = MqttBrokerData() # LOG.info('JSON {}'.format(l_json)) l_obj.Name = l_json['Name'] l_obj.Active = l_json['Active'] l_obj.Key = l_ix l_obj.UUID = Uuid.make_valid(l_json['UUID']) l_obj.BrokerAddress = l_json['BrokerAddress'] l_obj.BrokerPort = l_json['BrokerPort'] self.m_pyhouse_obj.Computer.Mqtt.Brokers[l_obj.Key] = l_obj
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 saveMqttData(self, p_json): """Mqtt data is returned, so update the info. """ l_json = JsonUnicode().decode_json(p_json) l_delete = l_json['Delete'] l_ix = int(l_json['Key']) if l_delete: try: del self.m_pyhouse_obj.Computer.Mqtt.Brokers except AttributeError: LOG.error("web_mqtt - Failed to delete - JSON: {0:}".format(l_json)) return try: l_obj = self.m_pyhouse_obj.Computer.Mqtt.Brokers[l_ix] except KeyError: LOG.warning('Creating a new Mqtt Broker Key: {}'.format(l_ix)) l_obj = MqttBrokerData() # LOG.info('JSON {}'.format(l_json)) l_obj.Name = l_json['Name'] l_obj.Active = l_json['Active'] l_obj.Key = l_ix l_obj.UUID = Uuid.make_valid(l_json['UUID']) l_obj.BrokerAddress = l_json['BrokerAddress'] l_obj.BrokerPort = l_json['BrokerPort'] self.m_pyhouse_obj.Computer.Mqtt.Brokers[l_obj.Key] = l_obj
def create_computer(_p_pyhouse_obj): l_xml = ComputerInformation() l_xml.Name = platform.node() l_xml.Key = 0 l_xml.Active = True l_xml.UUID = Uuid.create_uuid() LOG.warn('Created a new UUID for computer!') return l_xml
def get_uuid_from_xml(p_xml, p_name): """ UUIDs are always an element. """ l_xml = XML.get_any_field(p_xml, p_name) if l_xml is None or len(l_xml) != 36: l_xml = Uuid.create_uuid() LOG.error( "A valid UUID was not found for {} - generating a new one. {}". format(p_name, l_xml)) return l_xml
def _read_all_thermostats_xml(p_pyhouse_obj, p_xml): l_dict = {} l_count = 0 try: for l_xml in p_xml.iterfind('Thermostat'): l_obj = Utility._read_one_thermostat_xml(p_pyhouse_obj, l_xml) l_obj.Key = l_count l_dict[l_count] = l_obj p_pyhouse_obj.Uuids[l_obj.UUID] = UtilUuid.add_uuid( p_pyhouse_obj, 'Thermostat') l_count += 1 except AttributeError as e_err: LOG.error('Reading Hvac.Thermostat information - {}'.format(e_err)) LOG.info("Loaded {} Thermostats".format(l_count)) return l_dict
def write_base_object_xml(p_element_name, p_object): """ Note that UUID is optional. @param p_element_name: is the name of the XML element (Light, Button, etc.) @param p_object: is the device object that contains the info to be written. @return: An Element with Attributes filled in and perhaps sub-elements attached """ l_elem = ET.Element(p_element_name) try: PutGetXML.put_text_attribute(l_elem, 'Name', p_object.Name) PutGetXML.put_int_attribute(l_elem, 'Key', p_object.Key) PutGetXML.put_bool_attribute(l_elem, 'Active', p_object.Active) except AttributeError as e_err: PutGetXML.put_text_attribute(l_elem, 'Error: ', e_err) try: PutGetXML.put_uuid_element(l_elem, 'UUID', p_object.UUID) except AttributeError: PutGetXML.put_uuid_element(l_elem, 'UUID', 'No UUID Given') LOG.error('UUID missing for {}'.format(p_object.Name)) l_UUID = Uuid.make_valid('246') PutGetXML.put_uuid_element(l_elem, 'UUID', l_UUID) return l_elem
def read_all_lights_xml(p_pyhouse_obj, p_light_sect_xml): """ @param p_pyhouse_obj: is the master information store @param p_light_sect_xml: the "LightSection" of the config @param p_version: is the XML version of the file to use. @return: a dict of lights info """ l_count = 0 l_dict = {} try: for l_xml in p_light_sect_xml.iterfind('Light'): l_obj = Utility._read_one_light_xml(p_pyhouse_obj, l_xml) l_obj.Key = l_count # Renumber l_dict[l_count] = l_obj p_pyhouse_obj.Uuids[l_obj.UUID] = UtilUuid.add_uuid(p_pyhouse_obj, 'Light') l_count += 1 except AttributeError as e_err: # No Lights section LOG.warning('Lighting_Lights - No Lights defined - {}'.format(e_err)) # print('XXX-1', e_err) l_dict = {} LOG.info("Loaded {} Lights".format(l_count)) return l_dict
def _get_one_interface(p_interface_name): """ Gather the information about a single interface given the interface name. Only UP interfaces return data, apparently, """ l_interface = NodeInterfaceData() l_interface.Name = p_interface_name l_interface.Active = True l_interface.Key = 0 l_interface.UUID = toolUuid.create_uuid() l_interface.NodeInterfaceType = 'Other' l_afList = Interfaces._find_addr_lists(p_interface_name) for l_afID in l_afList.iterkeys(): l_v4 = [] l_v6 = [] l_afName = Interfaces._find_addr_family_name(l_afID) if l_afName == 'AF_PACKET': l_interface.MacAddress = l_afList[l_afID] if l_afName == 'AF_INET': l_v4 = Interfaces._get_address_list_INET(l_afList[l_afID]) l_interface.V4Address = l_v4 if l_afName == 'AF_INET6': l_v6 = Interfaces._get_address_list_INET6(l_afList[l_afID]) l_interface.V6Address = l_v6 return l_interface, l_v4, l_v6
def test_03_Valid(self): l_test = '12345678-dead-beef-dead-fedcba987654' l_uuid = Uuid.make_valid(l_test) # print('UUID = {}'.format(l_uuid)) self.assertEqual(l_uuid, l_test)
def test_02_Invalid(self): l_test = '123456' l_uuid = Uuid.make_valid(l_test) # print('UUID = {}'.format(l_uuid)) self.assertNotEqual(l_uuid, l_test)
def test_01_None(self): l_test = None l_uuid = Uuid.make_valid(l_test) # print('UUID = {}'.format(l_uuid)) self.assertNotEqual(l_uuid, l_test)