def testCanBrightenNotCLR(self): self.assertFalse(deviceAPIUtils.canBrighten(10)) self.assertFalse(deviceAPIUtils.canBrighten('a string')) somePythonTypeObject = [ 'this is', 'a list of python strings', 'not a .NET class' ] self.assertFalse(deviceAPIUtils.canBrighten(somePythonTypeObject))
def command(self, message): output = StringIO.StringIO() output.write('Command Decision ' + str(self.commandCount) + ':\n') self.commandCount += 1 try: if (str(message["command-string"]) == 'manualDeviceUpdate'): #Set up connection to persistent storage conn = httplib.HTTPConnection(self.storageAddress[0], self.storageAddress[1]) #change the format to the format required by persistent storage payload = json.dumps({"action-type":"device state change","action-data":message}) requestPath = 'PATCH', 'A/' + message['userID'] + '/' + message["time"] + '/' + message["houseID"]+ '/' + message["roomID"] + '/' + message["deviceID"] + '/' + message["deviceType"] conn.request('PATCH', 'A/' + message['userID'] + '/' + message["time"] + '/' + message["houseID"]+ '/' + message["roomID"] + '/' + message["deviceID"] + '/' + message["deviceType"], payload) response = conn.getresponse() print response.status print response.read() line = "Location Decision " + str(self.locationDecisionCount) + ":\n" + "Data sent to persistent storage: " + str(payload) + "\nRequest Path: " + str(requestPath) + "\nRequest Response: " + str(response.status) + "\n" self.locationDecisionCount += 1 self.logger.debug(line) else: matchRoom = None try: matchRoom = self.findMatchingRoom(message['userID'], message['lat'], message['lon'], message['alt']) except KeyError as ke: if ke.args[0] == 'That userID does not exist.': output.write('nonexistent user\n') self.logger.warning(output.getvalue()) return else: raise if matchRoom is None: output.write('no matching room\n') self.logger.warning(output.getvalue()) return #Now, request all devices in that house. output.write('matched room ' + str(matchRoom) + '\n') output.write('requesting devices\n') devinterface = devapi.Interfaces(System.Uri(self.deviceBaseAdd)) devices = devinterface.getDevices(matchRoom[0], matchRoom[1]) print 'Debug:' print devices for oneDevice in devices: if devapiu.canBrighten(oneDevice): print 'found a brightenable' oneDevice.Enabled = True print output.getvalue() self.logger.info(output.getvalue()) except: output.write('Error when trying to make a command decision!\n') output.write('Request body being handled:\n') output.write(str(message) + '\n') traceback.print_exc(None, output) self.logger.error(output.getvalue())
def testCanBrightenIsLight(self): lightswitch = devapi.LightSwitch(None, None) lightswitch.Enabled = True self.assertTrue(deviceAPIUtils.canBrighten(lightswitch))
def testCanBrightenWrongIReadable(self): wrongGenericIReadable = devapi.Thermostat(None, None) self.assertFalse(deviceAPIUtils.canBrighten(wrongGenericIReadable))
def testCanBrightenIsEnableable(self): someIEnableable = devapi.CeilingFan(None, None) self.assertFalse(deviceAPIUtils.canBrighten(someIEnableable))