def getHeatRule(self): ALAPI.createCredentials(self.serverName, self.client) session = ALAPI.sessionObject() if session.latestSupportedApiVersion != '6': self.platformVersion = 'V5' print("hello") return False else: self.platformVersion = 'V6' rules = ALAPI.getRulesV6(session) #print(rules) #print(rules['rules']) oHeatRuleDict = {} heatRuleCount = 0 if (rules['rules']): for oActions in rules['rules']: oRuleList = [] if oActions['name'] in ('TooHot', 'TooCold'): heatRuleCount = heatRuleCount + 1 #print('Rule : ' + oActions['name']) #return oActions['name'] #print(" : ",end='') for status in oActions['actions']: #print(status['status'],end='') #print(" : ",end='') types = status['type'] for values in oActions['triggers']: #print(values['value']+' : '+types) #print('\n') #oRuleList.append((values['value'],types,status['status'])) oRuleList.append(values['value']) oRuleList.append(types) oRuleList.append(status['status']) oHeatRuleDict.update({oActions['name']: oRuleList}) if (heatRuleCount == 0): print('No Heating Rules are set') else: print('No rules are set') print(oHeatRuleDict) print('\n') return oHeatRuleDict
def getSyntheticDeviceID(nodeID): ALAPI.createCredentials(utils.getAttribute('common', 'currentEnvironment')) session = ALAPI.sessionObject() resp = ALAPI.getNodesV6(session) strSyntheticDeviceID = "" for oNode in resp['nodes']: if "nodeType" in oNode: if '.json' in oNode["nodeType"] and "consumers" in oNode[ "attributes"]: strConsumersID = oNode["attributes"]["consumers"][ "reportedValue"] print("strConsumersID", strConsumersID) if nodeID in strConsumersID: strSyntheticDeviceID = oNode["id"] break ALAPI.deleteSessionV6(session) return strSyntheticDeviceID
def getSPAttributes(nodeID): strMode = "" strState = "" syntheticNodeID = getSyntheticDeviceID(nodeID) ALAPI.createCredentials(utils.getAttribute('common', 'currentEnvironment')) session = ALAPI.sessionObject() resp = ALAPI.getNodesV6(session) for oNode in resp['nodes']: if nodeID in oNode["id"]: strState = getAttribute(oNode["attributes"], "state") elif oNode["id"] in syntheticNodeID: if getAttribute( oNode["attributes"]["syntheticDeviceConfiguration"], "enabled").upper() == "TRUE": strMode = "AUTO" strMode = "MANUAL" return strMode, strState
def getColourTemprature(nodeID): ALAPI.createCredentials(utils.getAttribute('common', 'currentEnvironment')) session = ALAPI.sessionObject() resp = ALAPI.getNodesV6(session) reportedValue = "" targetValue = "" for oNode in resp['nodes']: if nodeID in oNode["id"]: reportedValue = getAttribute(oNode["attributes"], "colourTemperature") targetValue = getAttribute(oNode["attributes"], "colourTemperature") print(reportedValue, "\n") print(targetValue, "\n") else: print("Light bulb brightness value is missing") return reportedValue, targetValue
def getCSAttributes(nodeID): finalCSState = "" #syntheticNodeID = getSyntheticDeviceID(nodeID) ALAPI.createCredentials(utils.getAttribute('common', 'currentEnvironment')) session = ALAPI.sessionObject() resp = ALAPI.getNodesV6(session) for oNode in resp['nodes']: #if "nodeType" in oNode: #if '.json' in oNode["nodeType"]: if nodeID in oNode["id"]: finalCSState = getAttribute(oNode["attributes"], "state") #if nodeID in oNode["id"]: #finalState = getAttribute(oNode["attributes"], "state") print('Reported state for contact sensor is' + finalCSState) else: print('Reported state for contact sensor is missing') return finalCSState
def getFWversion(self, resp): ALAPI.createCredentials(self.Environment.get()) session = ALAPI.sessionObject() resp = ALAPI.getNodesV6(session) oDeviceVersion = {} for oNode in resp['nodes']: if not 'supportsHotWater' in oNode['attributes']: if 'thermostatui.json' in oNode["nodeType"]: strModel = oNode["attributes"]["model"]["reportedValue"] oDeviceVersion[strModel] = oNode["attributes"][ "softwareVersion"]["reportedValue"] elif 'thermostat.json' in oNode["nodeType"]: strModel = oNode["attributes"]["model"]["reportedValue"] oDeviceVersion[strModel] = oNode["attributes"][ "softwareVersion"]["reportedValue"] elif 'hub.json' in oNode["nodeType"]: strModel = oNode["attributes"]["hardwareVersion"][ "reportedValue"] oDeviceVersion[strModel] = oNode["attributes"][ "softwareVersion"]["reportedValue"] elif 'smartplug.json' in oNode["nodeType"]: strModel = oNode["attributes"]["model"]["reportedValue"] oDeviceVersion[strModel] = oNode["attributes"][ "softwareVersion"]["reportedValue"] elif 'extender.json' in oNode["nodeType"]: strModel = oNode["attributes"]["model"]["reportedValue"] oDeviceVersion[strModel] = oNode["attributes"][ "softwareVersion"]["reportedValue"] elif 'contact.sensor.json' in oNode["nodeType"]: strModel = oNode["attributes"]["model"]["reportedValue"] oDeviceVersion[strModel] = oNode["attributes"][ "softwareVersion"]["reportedValue"] elif 'motion.sensor.json' in oNode["nodeType"]: strModel = oNode["attributes"]["model"]["reportedValue"] oDeviceVersion[strModel] = oNode["attributes"][ "softwareVersion"]["reportedValue"] elif 'connected.boiler.json' in oNode["nodeType"]: strModel = oNode["attributes"]["model"]["reportedValue"] oDeviceVersion[strModel] = oNode["attributes"][ "softwareVersion"]["reportedValue"] ALAPI.deleteSessionV6(session) return oDeviceVersion
def getNodeAndDeviceVersionID(): ALAPI.createCredentials(utils.getAttribute('common', 'currentEnvironment')) session = ALAPI.sessionObject() resp = ALAPI.getNodesV6(session) oDeviceDetails = {} for oNode in resp['nodes']: if ('supportsHotWater' not in oNode['attributes']) and "nodeType" in oNode: if '.json' in oNode["nodeType"] and "model" in oNode["attributes"]: if "reportedValue" in oNode["attributes"]["model"]: strModel = oNode["attributes"]["model"]["reportedValue"] strModelTemp = strModel intDeviceCntr = 0 while True: intDeviceCntr = intDeviceCntr + 1 strModel = strModelTemp + "_" + str(intDeviceCntr) if strModel in oDeviceDetails: continue else: break oDeviceDetails[strModel] = {} strName = "" oDeviceDetails[strModel]["nodeID"] = oNode["id"] if "name" in oNode: strName = oNode["name"] oDeviceDetails[strModel]["name"] = strName oDeviceDetails[strModel]["version"] = oNode["attributes"][ "softwareVersion"]["reportedValue"] oDeviceDetails[strModel]["presence"] = oNode["attributes"][ "presence"]["reportedValue"] elif "hardwareVersion" in oNode["attributes"]: strHubModel = oNode["attributes"]["hardwareVersion"][ "reportedValue"] if "NANO" in strHubModel: oDeviceDetails[strHubModel] = {} oDeviceDetails[strHubModel]["nodeID"] = oNode["id"] oDeviceDetails[strHubModel]["version"] = oNode[ "attributes"]["softwareVersion"]["reportedValue"] oDeviceDetails[strHubModel]["presence"] = oNode[ "attributes"]["presence"]["reportedValue"] ALAPI.deleteSessionV6(session) return oDeviceDetails
def setSPSchedulesAndValidateViaHub(context): ALAPI.createCredentials(utils.getAttribute('common', 'currentEnvironment')) session = ALAPI.sessionObject() #get node lists oDeviceNodeVersionList = getNodeAndDeviceVersionID() oDeviceDetails = {} intCntr = 1 context.reporter.HTML_TC_BusFlowKeyword_Initialize( 'Continuous Schedule Test Week: ' + str(intCntr)) for oRow in context.table: SmartPlug = oRow['SmartPlug'] intNoOfEvents = int(oRow['NoOfEvents']) oDeviceDetails[SmartPlug] = {} oDeviceDetails[SmartPlug]["id"] = SmartPlug oDeviceDetails[SmartPlug]["noOfEvents"] = intNoOfEvents oDeviceDetails[SmartPlug]["nodeId"] = oDeviceNodeVersionList[ SmartPlug]["nodeID"] oDeviceDetails[SmartPlug]["syntheticID"] = getSyntheticDeviceID( oDeviceNodeVersionList[SmartPlug]["nodeID"]) print('oDeviceNodeVersionList[SmartPlug]["nodeID"]', oDeviceNodeVersionList[SmartPlug]["nodeID"]) print("syntheticID", oDeviceDetails[SmartPlug]["syntheticID"]) payload, oSPSchedDict = SchUtils.createScheduleForSP(intNoOfEvents) print(oSPSchedDict, "\n") context.oSPSchedDict = oSPSchedDict context.SPNodeID = oDeviceDetails[SmartPlug]["nodeId"] r, success = ALAPI.setScheduleSP( session, oDeviceDetails[SmartPlug]["syntheticID"], payload) print(r, success) ALAPI.deleteSessionV6(session) SchUtils.runSPValidationForWeekSchedule(context) '''while True:
def upgrade_downgrade_firmware_forallViaHUB(context): print("ViaHub\n") oHeatScheduleDict = { 'sat': [('07:00', 28.5), ('09:00', 10.5), ('16:30', 23.5), ('22:00', 15), ('22:00', 15), ('22:00', 15)], 'sun': [('01:00', 27.5), ('02:00', 1), ('03:00', 12), ('04:00', 1), ('05:00', 28.5), ('23:45', 1)], 'fri': [('17:30', 1), ('18:00', 11), ('18:30', 28), ('19:00', 1), ('19:30', 29), ('20:00', 1)], 'wed': [('06:30', 29.5), ('08:30', 13), ('12:00', 19), ('16:30', 22.5), ('22:00', 31), ('22:00', 31)], 'mon': [('11:30', 27.5), ('11:45', 1), ('12:00', 12), ('12:15', 1), ('12:30', 28.5), ('12:45', 1)], 'tue': [('06:30', 20), ('08:30', 10), ('16:30', 20), ('22:00', 10), ('22:00', 10), ('22:00', 10)], 'thu': [('06:30', 20), ('08:30', 18.5), ('16:30', 27), ('22:00', 21), ('22:00', 21), ('22:00', 21)] } oAtributeDict = { 'HeatMode': '', 'WaterMode': '', 'HeatTemperature': '', 'HeatRunningState': '', 'WaterRuningState': '', 'HeatSchedule': '', 'WaterSchedule': '' } oModeList = ['MANUAL', 'AUTO', 'OFF', 'BOOST'] #get node lists ALAPI.createCredentials(utils.getAttribute('common', 'currentEnvironment')) session = ALAPI.sessionObject() resp = ALAPI.getNodesV6(session) nodeIdList = context.oThermostatEP.getNodeID(resp) ALAPI.deleteSessionV6(session) #Get the existing API details context.heatEP = context.oThermostatClass.heatEP context.waterEP = context.oThermostatClass.waterEP intModeListCntr = 0 intCntr = 0 while True: intCntr = intCntr + 1 context.reporter.HTML_TC_BusFlowKeyword_Initialize( 'Upgrade-Downgrade Counter : ' + str(intCntr)) for oRow in context.table: DeviceName = oRow['DeviceName'] DeviceType = oRow['DeviceType'] DeviceVersion1 = oRow['DeviceVersion1'] DeviceVersion2 = oRow['DeviceVersion2'] print(DeviceName, DeviceType, DeviceVersion1, DeviceVersion2, "\n") strModeToSet = "" targetHeatTemperature = 0.0 scheduleLockDuration = 0 oSchedule = {} if 'SLR' in DeviceType.upper(): strModeToSet = oModeList[intModeListCntr] targetHeatTemperature = 1.0 scheduleLockDuration = 0 if 'BOOST' in strModeToSet: targetHeatTemperature = 22.0 scheduleLockDuration = 60 if 'MANUAL' in strModeToSet: targetHeatTemperature = 20.0 context.heatEP.setModeViaAPI(nodeIdList[DeviceType], strModeToSet, targetHeatTemperature, scheduleLockDuration) heatWeeklyScheduleBefore = context.heatEP.getSchedule() if 'SLR2' in DeviceType.upper(): context.waterEP.setModeViaAPI( nodeIdList[DeviceType], strModeToSet, targetHeatTemperature=None, scheduleLockDuration=scheduleLockDuration) waterWeeklyScheduleBefore = context.waterEP.getSchedule() intModeListCntr = intModeListCntr + 1 if intModeListCntr == 4: intModeListCntr = 0 if not os.path.exists(context.networkBasePath): print("Network drive is not mounted") #Downgrade device if not 'NA' in DeviceVersion1.upper(): context.rFM.upgrade_or_downgrade_firmwareViaHUB( context.oThermostatEP, context.reporter, "Downgrade", DeviceType, DeviceVersion1) if 'SLT3' in DeviceType.upper(): #time.sleep(6000) #power_cycle_hub() print(strModeToSet) else: if 'CL01' in DeviceType.upper(): if context.rFM.verifyfirmwareVersionsViaHUB( context.oThermostatEP, context.reporter, "Downgrade", DeviceType, DeviceVersion1) == True: #time.sleep(12000) print() else: if context.rFM.verifyfirmwareVersionsViaHUB( context.oThermostatEP, context.reporter, "Downgrade", DeviceType, DeviceVersion1) == True: #time.sleep(2500) print(strModeToSet) context.rFM.validate_firmware_versionViaHUB( context.oThermostatEP, context.reporter, "Downgrade", DeviceType, DeviceVersion1) if 'SLR' in DeviceType.upper(): if 'AUTO' in strModeToSet: targetHeatTemperature = oSchdUt.getCurrentTempFromSchedule( context.heatEP.getSchedule())[0] heatWeeklyScheduleAfter = context.heatEP.getSchedule() context.rFM.validateAndUpdateLog(context.reporter, context.heatEP, 'Test', strModeToSet, targetHeatTemperature) oSchdUt.validateSchedulesOfOtherWeekdays( context.reporter, oSchedule, heatWeeklyScheduleBefore, heatWeeklyScheduleAfter) if 'SLR2' in DeviceType.upper(): if 'AUTO' in strModeToSet: targetHeatTemperature = oSchdUt.getCurrentTempFromSchedule( context.waterEP.getSchedule())[0] context.rFM.validateAndUpdateLog( context.reporter, context.waterEP, 'Test', strModeToSet, targetHeatTemperature) waterWeeklyScheduleAfter = context.waterEP.getSchedule( ) waterWeeklyScheduleBefore = oSchdUt.converWaterStateForSchedule( waterWeeklyScheduleBefore) waterWeeklyScheduleAfter = oSchdUt.converWaterStateForSchedule( waterWeeklyScheduleAfter) oSchdUt.validateSchedulesOfOtherWeekdays( context.reporter, oSchedule, waterWeeklyScheduleBefore, waterWeeklyScheduleAfter) time.sleep(30) #Upgrade Device if not 'NA' in DeviceVersion2.upper(): context.rFM.upgrade_or_downgrade_firmwareViaHUB( context.oThermostatEP, context.reporter, "Upgrade", DeviceType, DeviceVersion2) if 'SLT3' in DeviceType.upper(): #time.sleep(6000) #power_cycle_hub() print() else: if 'CL01' in DeviceType.upper(): if context.rFM.verifyfirmwareVersionsViaHUB( context.oThermostatEP, context.reporter, "Upgrade", DeviceType, DeviceVersion1) == True: #time.sleep(12000) print() else: if context.rFM.verifyfirmwareVersionsViaHUB( context.oThermostatEP, context.reporter, "Upgrade", DeviceType, DeviceVersion2) == True: #time.sleep(2500) print() context.rFM.validate_firmware_versionViaHUB( context.oThermostatEP, context.reporter, "Upgrade", DeviceType, DeviceVersion2) if 'SLR' in DeviceType.upper(): if 'AUTO' in strModeToSet: targetHeatTemperature = oSchdUt.getCurrentTempFromSchedule( context.heatEP.getSchedule())[0] heatWeeklyScheduleAfter = context.heatEP.getSchedule() context.rFM.validateAndUpdateLog(context.reporter, context.heatEP, 'Test', strModeToSet, targetHeatTemperature) oSchdUt.validateSchedulesOfOtherWeekdays( context.reporter, oSchedule, heatWeeklyScheduleBefore, heatWeeklyScheduleAfter) if 'SLR2' in DeviceType.upper(): if 'AUTO' in strModeToSet: targetHeatTemperature = oSchdUt.getCurrentTempFromSchedule( context.waterEP.getSchedule())[0] context.rFM.validateAndUpdateLog( context.reporter, context.waterEP, 'Test', strModeToSet, targetHeatTemperature) waterWeeklyScheduleAfter = context.waterEP.getSchedule( ) waterWeeklyScheduleBefore = oSchdUt.converWaterStateForSchedule( waterWeeklyScheduleBefore) waterWeeklyScheduleAfter = oSchdUt.converWaterStateForSchedule( waterWeeklyScheduleAfter) oSchdUt.validateSchedulesOfOtherWeekdays( context.reporter, oSchedule, waterWeeklyScheduleBefore, waterWeeklyScheduleAfter) context.reporter.intIterationCntr = context.reporter.intIterationCntr + 1
def _updateV6(self, nodeID=None): #Updating attributes for Light print("self.deviceType.upper()", self.deviceType.upper()) if "FWBULB" in self.deviceType.upper(): self.currentDeviceNodeId = pUtils.getDeviceNodeID(self.deviceType) self.mode, self.CurrentDeviceState, self.activeLightBrightness = pUtils.getLightAttributes( self.currentDeviceNodeId) self._weeklySchedule = pUtils.getDeviceScheduleInStandardFormat( self.deviceType) print(self._weeklySchedule) return True ALAPI.createCredentials(self.serverName, self.client) session = ALAPI.sessionObject() if session.latestSupportedApiVersion != '6': self.platformVersion = 'V5' print("V5") return False else: self.platformVersion = 'V6' resp = ALAPI.getNodesV6(session) if self.type == 'HEAT': boolWater = False else: boolWater = True for oNode in resp['nodes']: if not nodeID is None: if not oNode['parentNodeId'] == nodeID: continue if 'supportsHotWater' in oNode['attributes']: if oNode['attributes']['supportsHotWater'][ 'reportedValue'] == True and 'stateHotWaterRelay' in oNode[ 'attributes']: if boolWater: print("water") oAttributeList = oNode['attributes'] #oJson = oAttributeList['schedule']['reportedValue'] oJson = self.getAttribute(oAttributeList, 'schedule') if isinstance(oJson, str): oJson = json.loads(oJson) self._weeklySchedule = self._formatScheduleV6( oJson) #print('%%%%%%%%%%%^^^^^^^^^^^^^^^^^', oJson) strRunningState = self.getAttribute( oAttributeList, 'stateHotWaterRelay') if strRunningState == 'OFF': self.thermostatRunningState = '0000' else: self.thermostatRunningState = '0001' strActiveHeatCoolMode = self.getAttribute( oAttributeList, 'activeHeatCoolMode') boolActiveScheduleLock = self.getAttribute( oAttributeList, 'activeScheduleLock') lstActiveOverrides = self.getAttribute( oAttributeList, 'activeOverrides') if strActiveHeatCoolMode == 'OFF': self.mode = 'OFF' elif strActiveHeatCoolMode == 'HEAT' and boolActiveScheduleLock: self.mode = 'MANUAL' elif strActiveHeatCoolMode == 'HEAT' and not boolActiveScheduleLock: self.mode = 'AUTO' elif strActiveHeatCoolMode == 'BOOST': self.mode = 'BOOST' elif len(lstActiveOverrides ) > 0 and lstActiveOverrides[ 0] == "TARGET_HEAT_TEMPERATURE": self.mode = 'OVERRIDE' ''' print(self._weeklySchedule) print(self.mode) print(self.thermostatRunningState) ''' else: if not boolWater and 'stateHeatingRelay' in oNode[ 'attributes']: print('Heat') oAttributeList = oNode['attributes'] #oJson = oAttributeList['schedule']['reportedValue'] oJson = self.getAttribute(oAttributeList, 'schedule') if isinstance(oJson, str): oJson = json.loads(oJson) self._weeklySchedule = self._formatScheduleV6( oJson) strRunningState = self.getAttribute( oAttributeList, 'stateHeatingRelay') if strRunningState == 'OFF': self.thermostatRunningState = '0000' else: self.thermostatRunningState = '0001' if self.occupiedHeatingSetpointChanged: occupiedHeatingSetpoint = self.getAttribute( oAttributeList, 'targetHeatTemperature') self.occupiedHeatingSetpoint = float( '{:.1f}'.format( oAttributeList['targetHeatTemperature'] ['reportedValue'])) self.localTemperature = self.getAttribute( oAttributeList, 'temperature') strActiveHeatCoolMode = self.getAttribute( oAttributeList, 'activeHeatCoolMode') boolActiveScheduleLock = self.getAttribute( oAttributeList, 'activeScheduleLock') lstActiveOverrides = self.getAttribute( oAttributeList, 'activeOverrides') if strActiveHeatCoolMode == 'OFF': self.mode = 'OFF' elif strActiveHeatCoolMode == 'HEAT' and boolActiveScheduleLock: self.mode = 'MANUAL' elif strActiveHeatCoolMode == 'HEAT' and not boolActiveScheduleLock: self.mode = 'AUTO' elif strActiveHeatCoolMode == 'BOOST': self.mode = 'BOOST' elif len(lstActiveOverrides ) > 0 and lstActiveOverrides[ 0] == "TARGET_HEAT_TEMPERATURE": self.mode = 'OVERRIDE' ''' print(self._weeklySchedule) print(self.mode) print(self.occupiedHeatingSetpoint) print(self.thermostatRunningState) print(self.localTemperature) ''' ALAPI.deleteSessionV6(session) return True
def validateActiveLightFunctionViaHub(context, ActiveLightDevice): oColorTempList = { 0: "2700", 20: "3460", 40: "4220", 60: "4980", 80: "5740", 100: "6500" } oColorTempList = { 0: 2700, 20: 3460, 40: 4220, 60: 4980, 80: 5740, 100: 6500 } oColorTempPercentageList = list(oColorTempList.keys()) #get node lists #nodeIdList = context.oThermostatEP.getNodeID(resp) nodeIdList = SP.getNodeAndDeviceVersionID() print(nodeIdList) print(ActiveLightDevice) if 'ActiveLight' in ActiveLightDevice: if 'FWBulb01_1' in nodeIdList: strLightNodeID = nodeIdList['FWBulb01_1']["nodeID"] elif 'LDS_DimmerLight_1' in nodeIdList: strLightNodeID = nodeIdList['LDS_DimmerLight_1']["nodeID"] elif ActiveLightDevice in nodeIdList: strLightNodeID = nodeIdList[ActiveLightDevice]["nodeID"] else: context.reporter.ReportEvent('Test Validation', "Active light Node is missing.", "FAIL") return False intCntr = 0 #Open Text file to write the light parameters oFileWriter = open(context.reporter.strCurrentTXTFolder + "LUXvsTEMP.txt", 'w') oFileWriter.write("Iteration,ColorTemp,0_%,20_%,40_%,60_%,80_%,100_% \n") oFileWriter.close() del oFileWriter while True: ALAPI.createCredentials( utils.getAttribute('common', 'currentEnvironment')) session = ALAPI.sessionObject() strParameterValue = "" intCntr = intCntr + 1 strParameterValue = str(intCntr) boolPass = True context.reporter.HTML_TC_BusFlowKeyword_Initialize( 'Active Light Brightness validation Counter: ' + str(intCntr)) if "TWBULB" in ActiveLightDevice.upper(): intTempCntr = intCntr % 5 print(intTempCntr) myColourTemp = oColorTempList[ oColorTempPercentageList[intTempCntr]] ALAPI.setActiveLightColourTemperature(session, strLightNodeID, myColourTemp) context.reporter.ReportEvent( 'Test Validation', "Active light is set to Color Temperature : <B>" + str(myColourTemp) + "</B>", "Done") strParameterValue = strParameterValue + "," + myColourTemp #Set Light ON ALAPI.setActiveLightState(session, strLightNodeID, "ON") context.reporter.ReportEvent('Test Validation', "Active light is switched <B>ON</B>", "PASS") time.sleep(5) oBrightnessList = [] #ChangeBrightness for oRow in context.table: intBrightness = int(oRow['BrightnessValue']) #print("intBrightness", intBrightness) ALAPI.setActiveLightBrightness(session, strLightNodeID, intBrightness) context.reporter.ReportEvent( 'Test Validation', "Active light Brightness is set to : <B>" + str(intBrightness) + "</B>", "Done") time.sleep(5) if intBrightness in lightSensorCalibration: intLowLimit = lightSensorCalibration[intBrightness][0] intHighLimit = lightSensorCalibration[intBrightness][1] sensorValue, _, _ = utils.get_lux_value() if intLowLimit < sensorValue and intHighLimit > sensorValue: context.reporter.ReportEvent( 'Test Validation', "The measured LUX value for Active light Brightness is: <B>" + str(sensorValue) + "</B>. Which is within the calibration limit: " + str(intLowLimit) + " - " + str(intHighLimit), "PASS") else: context.reporter.ReportEvent( 'Test Validation', "The measured LUX value for Active light Brightness is: <B>" + str(sensorValue) + "</B>. Which is <B>NOT</B> the calibration limit: " + str(intLowLimit) + " - " + str(intHighLimit), "FAIL") boolPass = False if not intBrightness in oBrightnessList: oBrightnessList.append(intBrightness) strParameterValue = str(intBrightness) + "," + str( sensorValue) else: context.reporter.ReportEvent( 'Test Validation', "The Brightness values should be in multiples of 20", "FAIL") #Update Text file oFileWriter = open( context.reporter.strCurrentTXTFolder + "LUXvsTEMP.txt", 'a') oFileWriter.write(strParameterValue + "\n") oFileWriter.close() del oFileWriter #Update the Pass and Fail counters context.reporter.intIterationCntr = intCntr if boolPass: context.reporter.intIterationPassCntr = context.reporter.intIterationPassCntr + 1 else: context.reporter.intIterationFailCntr = context.reporter.intIterationFailCntr + 1 #Set Light OFF ALAPI.setActiveLightState(session, strLightNodeID, "OFF") context.reporter.ReportEvent('Test Validation', "Active Plug is switched <B>OFF</B>", "PASS") time.sleep(5) ALAPI.deleteSessionV6(session)
def get_response(self): ALAPI.createCredentials(self.Environment.get()) self.session = ALAPI.sessionObject() if self.session.latestSupportedApiVersion != '6': self.platformVersion = 'V5' print("hello") self.Response.insert(1.0, 'User is V5. Retry with V6 User') return False else: self.platformVersion = 'V6' if self.Node.get() == 'Notifications': respRules = ALAPI.getRulesV6(self.session) return respRules resp = ALAPI.getNodesV6(self.session) if 'HEAT' in self.EndPoint.get().upper(): boolWater = False else: boolWater = True if self.Node.get() == 'Holiday Mode': oHolDict = {} for oNode in resp['nodes']: if 'holidayMode' in oNode['attributes']: oHolDict['holidayMode'] = oNode['attributes'][ 'holidayMode'] if 'holidayModeEnabled' in oNode['attributes']: oHolDict['holidayModeEnabled'] = oNode['attributes'][ 'holidayModeEnabled'] if 'holidayModeActive' in oNode['attributes']: oHolDict['holidayModeActive'] = oNode['attributes'][ 'holidayModeActive'] return oHolDict if self.Node.get() == 'All': return resp if self.Node.get() == 'Kit Versions': print(self.getNodeID(resp)) print(self.getFWversion(resp)) oDeviceVersionDict = {} strSLTMacID = "" strSLRMacID = "" for oNode in resp['nodes']: if not 'supportsHotWater' in oNode['attributes']: if 'hardwareVersion' in oNode['attributes']: intHardwareVersion = oNode['attributes'][ 'hardwareVersion']['reportedValue'] intSoftwareVersion = oNode['attributes'][ 'softwareVersion']['reportedValue'] if 'NANO' in intHardwareVersion: #oDeviceVersionDict['HUB'] = intHardwareVersion + '$$' + intSoftwareVersion #strHubMacId = oNode['attributes']['zigBeeNeighbourTable']['reportedValue'][0]['neighbourAddress'] oDeviceVersionDict['HUB'] = { "model": intHardwareVersion, "version": intSoftwareVersion } #, 'mac_id': strHubMacId} if 'zigBeeNeighbourTable' in oNode['attributes']: for oDevice in json.loads( oNode['attributes']['zigBeeNeighbourTable'] ['reportedValue']): if oDevice['relationship'] == 'CHILD': strSLTMacID = oDevice['neighbourAddress'] elif oDevice['relationship'] == 'NONE': strSLRMacID = oDevice['neighbourAddress'] for oNode in resp['nodes']: if not 'supportsHotWater' in oNode['attributes']: if 'model' in oNode['attributes']: strModel = oNode['attributes']['model'][ 'reportedValue'] intSoftwareVersion = oNode['attributes'][ 'softwareVersion']['reportedValue'] if 'SLT' in strModel: #oDeviceVersionDict['Thermostat'] = strModel + '$$' + intSoftwareVersion oDeviceVersionDict['Thermostat'] = { "model": strModel, "version": intSoftwareVersion, 'mac_id': strSLTMacID } elif 'SLR' in strModel: #oDeviceVersionDict['Boiler Module'] = strModel + '$$' + intSoftwareVersion oDeviceVersionDict['Boiler Module'] = { "model": strModel, "version": intSoftwareVersion, 'mac_id': strSLRMacID } return oDeviceVersionDict for oNode in resp['nodes']: if 'supportsHotWater' in oNode['attributes']: if oNode['attributes']['supportsHotWater'][ 'reportedValue'] == True and 'stateHotWaterRelay' in oNode[ 'attributes']: if boolWater: print("water") oAttributeList = oNode['attributes'] if self.Node.get() == 'Schedule': oSchedDict = {} oJsonAll = oAttributeList['schedule'] for oKey in oJsonAll: oJson = oJsonAll[oKey] if oKey == 'targetValue' or oKey == 'reportedValue': if isinstance(oJson, str): oJson = json.loads(oJson) oSchedDict[oKey] = oJson return {"schedule": oSchedDict} elif self.Node.get() == 'Running State': return { "stateHotWaterRelay": oAttributeList['stateHotWaterRelay'] } elif self.Node.get() == 'Mode': strActiveHeatCoolMode = self.getAttribute( oAttributeList, 'activeHeatCoolMode') boolActiveScheduleLock = self.getAttribute( oAttributeList, 'activeScheduleLock') print(boolActiveScheduleLock, 'boolActiveScheduleLock') lstActiveOverrides = self.getAttribute( oAttributeList, 'activeOverrides') if strActiveHeatCoolMode == 'OFF': self.mode = 'OFF' elif strActiveHeatCoolMode == 'HEAT' and boolActiveScheduleLock: self.mode = 'MANUAL' elif len(lstActiveOverrides ) > 0 and lstActiveOverrides[ 0] == "TARGET_HEAT_TEMPERATURE": self.mode = 'OVERRIDE' elif strActiveHeatCoolMode == 'HEAT' and not boolActiveScheduleLock: self.mode = 'AUTO' elif strActiveHeatCoolMode == 'BOOST': self.mode = 'BOOST' return { "currentMode": self.mode, "activeHeatCoolMode": oAttributeList['activeHeatCoolMode'], "activeScheduleLock": oAttributeList['activeScheduleLock'], "activeOverrides": oAttributeList['activeOverrides'], "scheduleLockDuration": oAttributeList["scheduleLockDuration"], "stateHotWaterRelay": oAttributeList['stateHotWaterRelay'] } else: if not boolWater and 'stateHeatingRelay' in oNode[ 'attributes']: print('Heat') oAttributeList = oNode['attributes'] if self.Node.get() == 'Schedule': oSchedDict = {} oJsonAll = oAttributeList['schedule'] for oKey in oJsonAll: oJson = oJsonAll[oKey] if oKey == 'targetValue' or oKey == 'reportedValue': if isinstance(oJson, str): oJson = json.loads(oJson) oSchedDict[oKey] = oJson return {"schedule": oSchedDict} elif self.Node.get() == 'Running State': return { "stateHeatingRelay": oAttributeList['stateHeatingRelay'] } elif self.Node.get() == 'Target Temperature': return { "targetHeatTemperature": oAttributeList['targetHeatTemperature'] } elif self.Node.get() == 'Local Temperature': return { "temperature": oAttributeList['temperature'] } elif self.Node.get() == 'Mode': strActiveHeatCoolMode = self.getAttribute( oAttributeList, 'activeHeatCoolMode') boolActiveScheduleLock = self.getAttribute( oAttributeList, 'activeScheduleLock') lstActiveOverrides = self.getAttribute( oAttributeList, 'activeOverrides') if strActiveHeatCoolMode == 'OFF': self.mode = 'OFF' elif strActiveHeatCoolMode == 'HEAT' and boolActiveScheduleLock: self.mode = 'MANUAL' elif strActiveHeatCoolMode == 'HEAT' and not boolActiveScheduleLock: self.mode = 'AUTO' elif strActiveHeatCoolMode == 'BOOST': self.mode = 'BOOST' elif len(lstActiveOverrides ) > 0 and lstActiveOverrides[ 0] == "TARGET_HEAT_TEMPERATURE": self.mode = 'OVERRIDE' return { "currentMode": self.mode, "activeHeatCoolMode": oAttributeList['activeHeatCoolMode'], "activeScheduleLock": oAttributeList['activeScheduleLock'], "activeOverrides": oAttributeList['activeOverrides'], "scheduleLockDuration": oAttributeList["scheduleLockDuration"], "stateHeatingRelay": oAttributeList['stateHeatingRelay'] }
def pair_unpair_devices_via_hub(context, HubType): HubType = HubType.upper().strip() intModeListCntr = 0 intCntr = 0 intPassCntr = 0 intFailCntr = 0 while True: intCntr = intCntr + 1 context.reporter.HTML_TC_BusFlowKeyword_Initialize( 'Pair-Unpair Counter : ' + str(intCntr)) for oRow in context.table: DeviceName = oRow['DeviceName'] DeviceType = oRow['DeviceType'] #HubType = oRow['HubType'] #get node lists ALAPI.createCredentials( utils.getAttribute('common', 'currentEnvironment')) session = ALAPI.sessionObject() #nodeIdList = context.oThermostatEP.getNodeID(resp) nodeIdList = SP.getNodeAndDeviceVersionID() if DeviceType in nodeIdList: NodeID = nodeIdList[DeviceType]["nodeID"] print(DeviceName, DeviceType, NodeID, "\n") #Unpair the Device from Telegesis context.reporter.HTML_TC_BusFlowKeyword_Initialize( 'Unpair the Device ' + DeviceType + ' from HUb: ') context.reporter.ReportEvent("Test Validation", "NodeID : <B>" + NodeID + "</B>", "Done") print(utils.getTimeStamp(False), "Sending Leave request for device") ALAPI.deleteDeviceV6(session, NodeID) print(utils.getTimeStamp(False), "Wait for 40 seconds") time.sleep(90) '''time.sleep(5) utils.setSPOnOff("DAF8", "OFF") time.sleep(2) utils.setSPOnOff("DAF8", "ON") time.sleep(5)''' #Pair the Device via Hub context.reporter.HTML_TC_BusFlowKeyword_Initialize( 'Pair the Device ' + DeviceType + ' to Hub: ') print(utils.getTimeStamp(False), "Join Device to the network") ALAPI.setHubStateV6(session, nodeIdList[HubType]["nodeID"], "DISCOVERING") intStartTime = time.time() intTCStartTime = time.monotonic() boolPairStatus = False sleepTime = 0 while True: #Validate if node is added the network nodeIdList = SP.getNodeAndDeviceVersionID() if DeviceType in nodeIdList: boolPairStatus = True break elif sleepTime > 250: break time.sleep(30) sleepTime = sleepTime + 30 ALAPI.setHubStateV6(session, nodeIdList[HubType]["nodeID"], "UP") ALAPI.deleteSessionV6(session) print("boolPairStatus", boolPairStatus) if boolPairStatus: intPassCntr = intPassCntr + 1 myNodeID = nodeIdList[DeviceType]["nodeID"] context.reporter.ReportEvent( "Test Validation", "Device " + DeviceType + " Joined the network with Node ID : <B>" + myNodeID + "</B>", "PASS") print("Device Joined the network with Node ID : ", myNodeID) else: intFailCntr = intFailCntr + 1 context.reporter.ReportEvent("Test Validation", "Join is unsuccessfull", "FAIL") print("join is unsuccessfull") return False '''print("Restarting the Smart Plug") utils.setSPOnOff(NodeID, 'OFF') time.sleep(5) utils.setSPOnOff(NodeID, 'ON') time.sleep(5)''' intTCEndTime = time.monotonic() strTCDuration = str( timedelta(seconds=intTCEndTime - intTCStartTime)) strTCDuration = utils.getDuration(strTCDuration) intSeconds = int(strTCDuration.split(",")[1].strip().split(" ")[0]) intMin = int(strTCDuration.split(",")[0].strip().split(" ")[0]) intSeconds = intMin * 60 + intSeconds if intSeconds > 60: strStatus = "FAIL" else: strStatus = "PASS" context.reporter.ReportEvent("Test Validation", "Time taken: " + strTCDuration, strStatus) print("Time taken: ", strTCDuration) print('intCntr', intCntr, 'intPassCntr', intPassCntr, 'intFailCntr', intFailCntr) print( "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$" ) print() time.sleep(180) print( "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$" )
def instaliOSAPP(context): intIterCntr = 1 while True: context.reporter.HTML_TC_BusFlowKeyword_Initialize('App Installation Verification counter: ' + str(intIterCntr)) print('App Installation Verification counter: ' + str(intIterCntr)) intIterCntr = intIterCntr + 1 strNewAppFilePath = os.path.abspath(__file__ + "/../../../../") + "/02_Manager_Tier/EnviromentFile/Apps/iOS/isopBeta/Hive_new.ipa" strOldAppFilePath = os.path.abspath(__file__ + "/../../../../") + "/02_Manager_Tier/EnviromentFile/Apps/iOS/isopBeta/Hive_old.ipa" '''print(striOSAppiumConnectionString) subprocess.call('killall node', shell=True) subprocess.Popen(striOSAppiumConnectionString, shell=True)''' for strAppPath in [strOldAppFilePath, strNewAppFilePath]: print('Uninstalling the APP') context.reporter.ReportEvent('Test Validation', 'Uninstalling the APP', "PASS") strCmd = "ideviceinstaller -U uk.co.britishgas.hive" getShellCommandOutput(strCmd, 'Uninstall APP', boolPrintOutput = True) time.sleep(5) print('Installing the APP') context.reporter.ReportEvent('Test Validation', 'Installing the APP', "PASS") strCmd = "ideviceinstaller -i " + strAppPath getShellCommandOutput(strCmd, 'Install APP', boolPrintOutput = True) context.reporter.ReportEvent('Test Validation', 'Launching the APP', "PASS") strDeviceName = utils.getAttribute('iOS', 'deviceName') oBasePage = paygeiOS.BasePage(None, context.reporter) iOSDriver = oBasePage.setup_ios_driver(strDeviceName, strAppPath) oHomePage = paygeiOS.HomePage(iOSDriver, context.reporter) time.sleep(5) context.reporter.ReportEvent('Test Validation', 'Swipe the APP to go to Heating Control Page', "PASS") iOSDriver.swipe(50, 500, 300, 500, 500) time.sleep(5) fltCurrentTargTemp = 0.0 try: oScrolElement = iOSDriver.find_element(*HeatingControlPageLocators.TARGET_TEMPERATURE_SCROLL) oScrolElementVAlue = oScrolElement.get_attribute('value') if 'point' in oScrolElementVAlue: fltCurrentTargTemp = float(oScrolElementVAlue.split(' ')[0] + '.' + oScrolElementVAlue.split(' ')[2]) else: fltCurrentTargTemp = float(oScrolElementVAlue.split(' ')[0]) except: context.reporter.ReportEvent('Test Validation','IOS App : NoSuchElementException: in navigate_to_change_password_screen\n {0}'.format(traceback.format_exc().replace('File', '$~File')), "FAIL") fltAPITargetTemp = 0.0 ALAPI.createCredentials(utils.getAttribute('common', 'currentEnvironment')) session = ALAPI.sessionObject() resp = ALAPI.getNodesV6(session) for oNode in resp['nodes']: if 'supportsHotWater' in oNode['attributes']: if 'stateHeatingRelay' in oNode['attributes']: oAttributeList = oNode['attributes'] fltAPITargetTemp = float('{:.1f}'.format(oAttributeList['targetHeatTemperature']['reportedValue'])) if fltAPITargetTemp ==1.0: fltAPITargetTemp = 7.0 ALAPI.deleteSessionV6(session) if fltAPITargetTemp == 32.0 or fltAPITargetTemp != fltCurrentTargTemp: context.reporter.ReportEvent('Test Validation', 'App Display Target Temperature: ' + str(fltCurrentTargTemp) + '\nReported API Target Temperature: ' + str(fltAPITargetTemp), "FAIL", driver = iOSDriver) else: context.reporter.ReportEvent('Test Validation', 'App Display Target Temperature: ' + str(fltCurrentTargTemp) + '\nReported API Target Temperature: ' + str(fltAPITargetTemp), "PASS", driver = iOSDriver) iOSDriver.quit() '''
def getNodeByID(nodeID): ALAPI.createCredentials(utils.getAttribute('common', 'currentEnvironment')) session = ALAPI.sessionObject() nodes = ALAPI.getNodesByIDV6(session, nodeID) ALAPI.deleteSessionV6(session) return nodes
def updateGlobalVarJson(self): #Reading all data from GlobalVar.Json if 'APP' in self.MainClient.get().upper(): ALAPI.createCredentials(self.Environment.get(), username=self.UserName.get(), password=self.Password.get()) self.session = ALAPI.sessionObject() if self.session.statusCode != 200: resp = self.session.response if isinstance(resp, str): resp = json.loads(resp) showinfo('ERROR', resp) return strEnvironmentFolderPAth = os.path.abspath( __file__ + "/../../../") + "/02_Manager_Tier/EnviromentFile/" strGlobVarFilePath = strEnvironmentFolderPAth + '/GlobalVar.json' strJson = open(strGlobVarFilePath, mode='r') oJsonDict = json.loads(strJson.read()) strJson.close() oGlobalDict = oJsonDict['globalVariables'] #updating the json Dictionary based on the the input parameter selected on the GUI oGlobalDict['currentEnvironment'] = self.Environment.get() oGlobalDict['apiValidationType'] = self.APIValidation.get() oGlobalDict['mainClient'] = self.MainClient.get() oCurrentEnvDict = oGlobalDict['listOfEnvironments'][ self.Environment.get()] if 'ZIGBEE' in self.APIValidation.get().upper(): oGlobalDict['atZigbeeNode'] = self.ATNode.get() else: strAppVer = self.AppVersion.get() oGlobalDict['currentAppVersion'] = self.AppVersion.get() oGlobalDict['userName'] = self.UserName.get() oGlobalDict['password'] = self.Password.get() if 'IOS' in self.MainClient.get().upper(): oCurrentEnvDict[ 'iOS' + strAppVer]['appFileName'] = self.AppFilePath.get() oCurrentEnvDict[ 'iOS' + strAppVer]['platformVersion'] = self.OSVersion.get() oCurrentEnvDict[ 'iOS' + strAppVer]['deviceName'] = self.DeviceName.get() oCurrentEnvDict['iOS' + strAppVer]['udid'] = self.UDID.get() elif 'ANDROID' in self.MainClient.get().upper(): oCurrentEnvDict[ 'android' + strAppVer]['appFileName'] = self.AppFilePath.get() oCurrentEnvDict[ 'android' + strAppVer]['platformVersion'] = self.OSVersion.get() oCurrentEnvDict[ 'android' + strAppVer]['deviceName'] = self.DeviceName.get() elif 'WEB' in self.MainClient.get().upper(): oCurrentEnvDict[ 'web' + strAppVer]['browserName'] = self.BrowserName.get() oCurrentEnvDict['web' + strAppVer]['loginURL'] = self.URL.get() oGlobalDict['listOfEnvironments'][ self.Environment.get()] = oCurrentEnvDict oJsonDict['globalVariables'] = oGlobalDict #Write back the JSON to the GlobalVar.JSON strJson = open(strGlobVarFilePath, mode='w+') #strDict = json.dumps(oJsonDict, indent=4, sort_keys=True) #print(str(strDict)) strJson.write(json.dumps(oJsonDict, indent=4, sort_keys=True)) strJson.close() if not ('ZIGBEE' in self.APIValidation.get().upper() or 'WEB' in self.MainClient.get().upper()): subprocess.call('killall node', shell=True) subprocess.Popen(striOSAppiumConnectionString, shell=True) if 'ANDROID' in self.MainClient.get().upper(): #subprocess.call('adb kill-server', shell=True) #subprocess.call('adb start-server', shell=True) print() time.sleep(5) if self.TestSuite.get() == 'BasicSmokeTest_Dual': subprocess.Popen("behave --tags=BasicSmokeTest", shell=True) elif self.TestSuite.get() == 'BasicSmokeTest_Heating': subprocess.Popen("behave --tags=BasicSmokeTest --tags=Heating", shell=True) elif self.TestSuite.get() == 'BasicSmokeTest_HotWater': subprocess.Popen("behave --tags=BasicSmokeTest --tags=HotWater", shell=True) elif self.TestSuite.get() == 'ScheduleTest_Dual': subprocess.Popen("behave --tags=ScheduleTest --tags=Verify", shell=True) elif self.TestSuite.get() == 'ScheduleTest_Heating': subprocess.Popen( "behave --tags=ScheduleTest --tags=Verify --tags=Heating", shell=True) elif self.TestSuite.get() == 'ScheduleTest_HotWater': subprocess.Popen( "behave --tags=ScheduleTest --tags=Verify --tags=HotWater", shell=True) elif self.TestSuite.get() == 'Kings': subprocess.Popen("behave --tags=Kings", shell=True) elif self.TestSuite.get() == 'SP_AllTest': subprocess.Popen("behave --tags=Generic", shell=True) elif self.TestSuite.get() == 'SP_AllChannelPairingTest': subprocess.Popen("behave --tags=SC-GT-SC01-01", shell=True) elif self.TestSuite.get() == 'SP_PairingTest': subprocess.Popen("behave --tags=SC-GT-SC01-02", shell=True) elif self.TestSuite.get() == 'SP_ZigbeeDumpTest': subprocess.Popen("behave --tags=SC-GT-SC02-01", shell=True) elif self.TestSuite.get() == 'SP_On-OffTest': subprocess.Popen("behave --tags=SC-GT-SC03-01", shell=True) elif self.TestSuite.get() == 'SP_Upgrade-Downgrade': subprocess.Popen("behave --tags=SC-GT-SC04-01", shell=True) print('Test suite Triggered')