| 67 | } |
| 68 | |
| 69 | export async function printDeviceTable( |
| 70 | deviceInformation: Record<string, any>, |
| 71 | deviceAbility?: Record<string, any>, |
| 72 | devicePassword?: string |
| 73 | ): Promise<void> { |
| 74 | const { |
| 75 | system: { hardware: hw, firmware: fw }, |
| 76 | } = deviceInformation; |
| 77 | |
| 78 | const rows = [ |
| 79 | [ |
| 80 | 'Device', |
| 81 | `${hw.type} ${hw.subType} ${hw.chipType} (hardware:${hw.version} firmware:${fw.version})`, |
| 82 | ], |
| 83 | ['UUID', hw.uuid], |
| 84 | ['Mac address', hw.macAddress], |
| 85 | ['IP address', fw.innerIp], |
| 86 | ]; |
| 87 | |
| 88 | if (fw.server) { |
| 89 | rows.push(['Current MQTT broker', `${fw.server}:${fw.port}`]); |
| 90 | } |
| 91 | |
| 92 | rows.push( |
| 93 | ['Credentials', `User: ^C${hw.macAddress}\nPassword: ^C${devicePassword}`], |
| 94 | [ |
| 95 | 'MQTT topics', |
| 96 | `Publishes to: ^C/appliance/${hw.uuid}/publish\nSubscribes to: ^C/appliance/${hw.uuid}/subscribe`, |
| 97 | ] |
| 98 | ); |
| 99 | |
| 100 | if (deviceAbility) { |
| 101 | const abilityRows = []; |
| 102 | for (const [ability, params] of Object.entries(deviceAbility)) { |
| 103 | abilityRows.push(`${ability.padEnd(38)}\t${JSON.stringify(params)}`); |
| 104 | } |
| 105 | |
| 106 | rows.push(['Ability', abilityRows.join('\n')]); |
| 107 | } |
| 108 | |
| 109 | terminal.table(rows, tableOptions); |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Displays a list of WIFI Access Points |