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 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'] }