def getMessageBody(self, inviteCode): body = {'id': inviteCode} hardware = Hardware() if hardware.Serial and hardware.isRaspberryPi(): body['type'] = 'rpi' body['hardware_id'] = hardware.Serial else: hardware_id = hardware.getMac() if hardware_id: body['type'] = 'mac' body['hardware_id'] = hardware_id try: system_data = [] cayennemqtt.DataChannel.add(system_data, cayennemqtt.SYS_HARDWARE_MAKE, value=hardware.getManufacturer(), type='string', unit='utf8') cayennemqtt.DataChannel.add(system_data, cayennemqtt.SYS_HARDWARE_MODEL, value=hardware.getModel(), type='string', unit='utf8') system_info = SystemInfo() capacity_data = system_info.getMemoryInfo((cayennemqtt.CAPACITY, )) capacity_data += system_info.getDiskInfo((cayennemqtt.CAPACITY, )) for item in capacity_data: system_data.append(item) body['properties'] = {} body['properties']['pinmap'] = NativeGPIO().MAPPING if system_data: body['properties']['sysinfo'] = system_data except: exception('Error getting system info') return json.dumps(body)
class HarwareTest(unittest.TestCase): def setUp(self): setInfo() self.hardware = Hardware() def testGetManufacturer(self): manufacturer = self.hardware.getManufacturer() info(manufacturer) self.assertNotEqual(manufacturer, '') def testGetModel(self): model = self.hardware.getModel() info(model) self.assertNotEqual(model, 'Unknown') def testGetMac(self): mac = self.hardware.getMac() info(mac) self.assertRegex(mac, '^([0-9a-fA-F]{2}[:-]){5}([0-9a-fA-F]{2})$') def testBoardRevision(self): info(BOARD_REVISION) self.assertGreaterEqual(BOARD_REVISION, 0) self.assertLessEqual(BOARD_REVISION, 3) def testCpuRevision(self): info(CPU_REVISION) self.assertNotEqual(CPU_REVISION, '0') def testCpuHardware(self): info(CPU_HARDWARE) self.assertNotEqual(CPU_HARDWARE, '') def testDeviceVerification(self): device_checks = (self.hardware.isRaspberryPi(), self.hardware.isTinkerBoard(), self.hardware.isBeagleBone()) self.assertEqual(device_checks.count(True), 1)