Skip to content

Commit

Permalink
Fixed #54 and #44: Now, you can collect debug logs directly from the …
Browse files Browse the repository at this point in the history
…page Manage your physical devices
  • Loading branch information
Baldhor committed Oct 10, 2023
1 parent 2a909f5 commit ad7bd7a
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 5 deletions.
12 changes: 9 additions & 3 deletions consolere/ConsoleReService.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,8 @@ class ConsoleReService {
// Get instance handle
let instance = this.getInstance();

// We should stop the queue
instance.queue && instance.queue.pause();
// We should stop and clear the queue
instance.queue && instance.queue.pause() && instance.queue.clear();

instance.disconnecting = true;
if (instance.socket == null)
Expand Down Expand Up @@ -385,6 +385,11 @@ class ConsoleReService {

(async () => {
instance.queue.add(() => {
// console.re may have been disabled in the meantime
if (!instance.consolereEnabled) {
return;
}

try {
this.socket.emit("toServerRe", {
// command: null,
Expand All @@ -406,7 +411,8 @@ class ConsoleReService {
}
});
} catch (e) {
this.error('ConsoleRe emit error:', e);
// This is causing an infinite loop ...
// this.error('ConsoleRe emit error:', e);
}
});
})();
Expand Down
6 changes: 4 additions & 2 deletions drivers/esphome-wizard/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ class Driver extends Homey.Driver {
port: physicalDevice.port,
encryptionKey: physicalDevice.encryptionKey,
password: physicalDevice.password,
nativeCapabilities: []
nativeCapabilities: [],
rawData: realPhysicalDevice.getRawData()
};

Object.values(realPhysicalDevice.nativeCapabilities).forEach(nativeCapability => {
Expand Down Expand Up @@ -259,7 +260,8 @@ class Driver extends Homey.Driver {
port: data.port,
encryptionKey: data.encryptionKey,
password: data.password,
nativeCapabilities: []
nativeCapabilities: [],
rawData: realPhysicalDevice.getRawData()
};

Object.values(realPhysicalDevice.nativeCapabilities).forEach(nativeCapability => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
:key='physicalDevice.physicalDeviceId' class='list'>
<p>
<span>{{ physicalDevice.name }}</span>
<span class='edit' style="position: initial;" @click='copyToClipboard(physicalDevice.physicalDeviceId)'>{{
Homey.__('wizard2.list-physical-devices.copyToClipboard') }}</span>
<span></span>
<span class='edit' v-if='physicalDevice.status !== "new"'
@click='pageHandler.setPage("edit-physical-device-page", { physicalDeviceId: physicalDevice.physicalDeviceId })'>{{
Homey.__('wizard2.list-physical-devices.edit') }}</span>
Expand Down Expand Up @@ -40,5 +43,17 @@

<p v-if='physicalDevice.status === "new"'>{{ Homey.__('wizard2.list-physical-devices.cannot-modify') }}</p>
</div>

<div v-show='_clipboard !== null'>
<p>
<span>{{ Homey.__('wizard2.list-physical-devices.clipboard-title') }}</span>
</p>

<ul>
<li>
<textarea readonly wrap="off" rows="5" cols="33">{{ _clipboard }}</textarea>
</li>
</ul>
</div>
</div>
</template>
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const ListPhysicalDevicesPage = function () {
_initValues: null,
_modified: null,

_clipboard: null,

mounted() {
wizardlog('[' + this.componentName + '] ' + 'mounted');

Expand Down Expand Up @@ -33,6 +35,40 @@ const ListPhysicalDevicesPage = function () {
wizardlog('[' + this.componentName + '] ' + 'checkModified');

this._modified = Object.keys(this._initValues).find(key => this._initValues[key] !== this[key]) !== undefined;
},
copyToClipboard(physicalDeviceId) {
wizardlog('[' + this.componentName + '] ' + 'copyToClipboard:', ...arguments);

const stringifyCircularJSON = obj => {
const seen = new WeakSet();
const filterList = ['encryptionKey', 'newEncryptionKey', 'password', 'newPassword', 'bearer-token'];

return JSON.stringify(obj, (k, v) => {
if (v !== null && typeof v === 'object') {
if (seen.has(v)) return;
seen.add(v);

//if (util.types.isNativeError(v)) {
// return instance.serializeError(v);
//}
}

if (filterList.includes(k)) {
if (v === null || v === '') {
return '<no value>';
} else {
return '<hidden value>';
}
}

return v;
}, 2);
};

this._clipboard = stringifyCircularJSON({
"physicalDeviceId": physicalDeviceId,
"physicalDevice": configuration.physicalDevices.find(physicalDevice => physicalDevice.physicalDeviceId === physicalDeviceId)
});
}
};
};
19 changes: 19 additions & 0 deletions drivers/esphome-wizard/physical-device.js
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,25 @@ class PhysicalDevice extends EventEmitter {
this.client.sendCommand(nativeCapability.entityId, nativeCapability.attribut, newValue);
}

getRawData() {
this.log('getRawData');

let result = [];

Object.keys(this.client.nativeApiClient.entities).forEach(entityId => {
let tmpRawData = {
id: this.client.nativeApiClient.entities[entityId].id,
type: this.client.nativeApiClient.entities[entityId].type,
name: this.client.nativeApiClient.entities[entityId].name,
config: this.client.nativeApiClient.entities[entityId].config
};

result.push(tmpRawData);
});

return result;
}

log(...args) {
this.driver.log('[PhysicalDevice:' + this.name + ']', ...args);
}
Expand Down
2 changes: 2 additions & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@
"back": "back",
"title": "Manage your physical devices",
"edit": "edit",
"copyToClipboard": "collect debug info",
"clipboard-title": "Collected debug info",
"status": "Status",
"used": "Used",
"ipAddress": "IP Address",
Expand Down

0 comments on commit ad7bd7a

Please sign in to comment.