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, 'B2-04-A - one')) self.assertEqual(self.m_pyhouse_obj.Uuids.All[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.All, 'B2-04-B - two')) self.assertEqual(self.m_pyhouse_obj.Uuids.All[l_obj_1.UUID].UuidType, l_obj_1.UuidType)
def _get_one_interface(self, 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( ) # We need a way to persist the UUID instead of this l_interface.NodeInterfaceType = 'Other' l_afList = Interfaces()._find_addr_lists(p_interface_name) for l_afID in l_afList.keys(): 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_INET(l_afList[l_afID]) l_interface.V6Address = l_v6 return l_interface, l_v4, l_v6
def saveMqttData(self, p_json): """Mqtt data is returned, so update the info. """ l_json = json_tools.decode_json_unicode(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: {}".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 saveMqttData(self, p_json): """Mqtt data is returned, so update the info. """ l_json = json_tools.decode_json_unicode(p_json) l_delete = l_json['Delete'] l_ix = int(l_json['Key']) if l_delete: try: del self.m_pyhouse_obj.Core.Mqtt.Brokers except AttributeError: LOG.error( "web_mqtt - Failed to delete - JSON: {}".format(l_json)) return try: l_obj = self.m_pyhouse_obj.Core.Mqtt.Brokers[l_ix] except KeyError: LOG.warning('Creating a new Mqtt Broker Key: {}'.format(l_ix)) l_obj = MqttBrokerInformation() # 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.Core.Mqtt.Brokers[l_obj.Key] = l_obj
def _read_file(p_pyhouse_obj, p_filename): l_name = _build_file(p_pyhouse_obj, p_filename) try: l_file = open(l_name, 'r') l_ret = l_file.read() except IOError: l_ret = toolUuid.create_uuid() return l_ret
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 l_uuid_obj = UuidData() l_uuid_obj.UUID = l_obj.UUID l_uuid_obj.UuidType = 'Thermostat' UtilUuid.add_uuid(p_pyhouse_obj, l_uuid_obj) 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 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, 'B2-04-A - one')) self.assertEqual(self.m_pyhouse_obj._Uuids.All[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.All, 'B2-04-B - two')) self.assertEqual(self.m_pyhouse_obj._Uuids.All[l_obj_1.UUID].UuidType, l_obj_1.UuidType)
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_bad = l_xml l_xml = Uuid.create_uuid() LOG.error("A valid UUID was not found for {} - {} generating a new one. {}".format(p_name, l_xml_bad, l_xml)) 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_bad = l_xml l_xml = Uuid.create_uuid() LOG.warn( "A valid UUID was not found for {} - {} generating a new one. {}" .format(p_name, l_xml_bad, l_xml)) return l_xml
def _add_default_login(): l_obj = LoginData() l_obj.Name = 'admin' l_obj.Key = 0 l_obj.Active = True l_obj.UUID = Uuid.create_uuid() l_obj.LoginFullName = 'Administrator' l_obj.LoginPasswordCurrent = 'admin' l_obj.LoginPasswordNew = '' l_obj.LoginPasswordChangeFlag = False l_obj.LoginRole = 1 LOG.info('Adding admin login.') return l_obj
def init_uuids(p_pyhouse_obj): """be sure that all the uuid files exist in /etc/pyhouse Computer.uuid House.uuid Domain.uuid """ p_pyhouse_obj.Uuids.All = {} l_path = os.path.join(CONFIG_DIR, 'Computer.uuid') try: l_file = open(l_path, mode='r') _l_uuid = l_file.read() except IOError: _l_uuid = toolUuid.create_uuid()
def read_all_controllers_xml(p_pyhouse_obj): """Called from lighting. Get the entire configuration of all the controllers and place them in a holding dict. @param p_pyhouse_obj: is the entire PyHouse Data @param p_controller_section_xml: is the XML element containing all controllers. <ControllerSection> @param p_version: is the old version of the XML Config file @return: a dict of all the controllers configured. """ l_count = 0 l_dict = {} l_xml = p_pyhouse_obj.Xml.XmlRoot if l_xml is None: return l_dict l_xml = l_xml.find('HouseDivision') if l_xml is None: return l_dict l_xml = l_xml.find('LightingSection') if l_xml is None: return l_dict l_xml = l_xml.find('ControllerSection') if l_xml is None: return l_dict try: for l_one_xml in l_xml.iterfind('Controller'): l_obj = Utility._read_one_controller_xml(p_pyhouse_obj, l_one_xml) l_obj.Key = l_count l_dict[l_count] = l_obj l_uuid_obj = UuidData() l_uuid_obj.UUID = l_obj.UUID l_uuid_obj.UuidType = 'Controller' UtilUuid.add_uuid(p_pyhouse_obj, l_uuid_obj) LOG.info('Loaded controller {}'.format(l_obj.Name)) l_count += 1 except AttributeError as e_error: # No Controller section LOG.warning('No Controllers found - {}'.format(e_error)) LOG.info("Loaded {} Controllers".format(l_count)) return l_dict
def _setup_Uuids(self): """ """ l_obj = UuidInformation() l_obj.All = UuidData() l_obj.All = {} l_path = os.path.join(CONFIG_DIR, 'Computer.uuid') try: l_file = open(l_path, mode='r') _l_uuid = l_file.read() except IOError: _l_uuid = toolUuid.create_uuid() # LOG.debug(PrettyFormatAny.form(self.m_pyhouse_obj, 'SetupUuids-PyHouse', 190)) return l_obj
def read_all_GarageDoors_xml(p_pyhouse_obj): """ @param p_pyhouse_obj: is the master information store @param p_version: is the XML version of the file to use. @return: a dict of Garage Doors info """ l_count = 0 l_dict = {} l_xml = p_pyhouse_obj.Xml.XmlRoot if l_xml is None: return l_dict l_xml = l_xml.find('HouseDivision') if l_xml is None: return l_dict l_xml = l_xml.find('SecuritySection') if l_xml is None: return l_dict l_xml = l_xml.find('GarageDoorSection') if l_xml is None: return l_dict try: for l_one_xml in l_xml.iterfind('GarageDoor'): l_obj = Utility._read_one_door_xml(p_pyhouse_obj, l_one_xml) l_obj.Key = l_count # Renumber l_dict[l_count] = l_obj l_uuid_obj = UuidData() l_uuid_obj.UUID = l_obj.UUID l_uuid_obj.UuidType = 'GarageDoor' UtilUuid.add_uuid(p_pyhouse_obj, l_uuid_obj) LOG.info('Loaded Garage Door {}'.format(l_obj.Name)) l_count += 1 except AttributeError as e_err: # No Lights section LOG.warning('No Garage Doors defined - {}'.format(e_err)) # print('XXX-1', e_err) l_dict = {} LOG.info("Loaded {} Garage Doors".format(l_count)) return l_dict
def write_base_UUID_object_xml(p_element_name, p_object): """ @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 = XmlConfigTools().write_base_object_xml(p_element_name, p_object) 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.create_uuid() PutGetXML.put_uuid_element(l_elem, 'UUID', l_UUID) return l_elem
def read_all_MotionSensors_xml(p_pyhouse_obj): """ @param p_pyhouse_obj: is the master information store @return: a dict of Motion Sensor info """ l_count = 0 l_dict = {} l_xml = p_pyhouse_obj.Xml.XmlRoot if l_xml is None: return l_dict l_xml = l_xml.find('HouseDivision') if l_xml is None: return l_dict l_xml = l_xml.find('SecuritySection') if l_xml is None: return l_dict l_xml = l_xml.find('MotionDetectorSection') if l_xml is None: return l_dict try: for l_one_xml in l_xml.iterfind('Motion'): l_obj = Utility._read_one_motion_xml(p_pyhouse_obj, l_one_xml) l_obj.Key = l_count # Renumber l_dict[l_count] = l_obj l_uuid_obj = UuidData() l_uuid_obj.UUID = l_obj.UUID l_uuid_obj.UuidType = 'MotionDetector' UtilUuid.add_uuid(p_pyhouse_obj, l_uuid_obj) LOG.info('Loaded Motion Detectors {}'.format(l_obj.Name)) l_count += 1 except AttributeError as e_err: # No such section LOG.warning('No Motion Detectors defined - {}'.format(e_err)) # print('XXX-1', e_err) l_dict = {} LOG.info("Loaded {} Motion Detectors".format(l_count)) return l_dict
def write_base_UUID_object_xml(p_element_name, p_object): """ @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 = XmlConfigTools().write_base_object_xml( p_element_name, p_object) 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.create_uuid() PutGetXML.put_uuid_element(l_elem, 'UUID', l_UUID) return l_elem
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_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_01_None(self): l_test = None l_uuid = Uuid.make_valid(l_test) # print('UUID = {}'.format(l_uuid)) self.assertNotEqual(l_uuid, l_test)
def _add_uuid(p_pyhouse_obj, p_obj): l_obj = UuidData() l_obj.UUID = p_obj.UUID l_obj.UuidType = 'House' Uuid.add_uuid(p_pyhouse_obj, l_obj)