ice987987/ioBroker.husqvarna-automower

Statistics im Adapter integrieren

ArnoD15 opened this issue · 3 comments

The problem

Kann man die Statistics Werte von der Husqvarna API in diesem Adapter integrieren?

Habe es bei mir getestet und es werden alle Werte bis auf cuttingBladeUsageTime übertragen.
Habe dazu die main.js folgendermaßen ergänzt:
createObjects(mowerData):

// create channel "statistics"
await this.setObjectNotExistsAsync(mowerData[i].id + '.statistics', {
        type: 'channel',
	common: {
		name: 'statistics',
		desc: 'statistics',
	},
	native: {}
});
					await this.setObjectNotExistsAsync(mowerData[i].id + '.statistics.cuttingBladeUsageTime', {
						type: 'value',
						common: {
							name: 'Nutzungsdauer der Schneidklinge',
							desc: 'Nutzungsdauer der Schneidklinge',
							type: 'number',
							role: 'value',
							min: 0,
							unit: 'ms',
							read: true,
							write: false
						},
						native: {}
					});
					await this.setObjectNotExistsAsync(mowerData[i].id + '.statistics.numberOfChargingCycles', {
						type: 'value',
						common: {
							name: 'Anzahl der Ladezyklen',
							desc: 'Anzahl der Ladezyklen',
							type: 'number',
							role: 'value',
							min: 0,
							read: true,
							write: false
						},
						native: {}
					});
					await this.setObjectNotExistsAsync(mowerData[i].id + '.statistics.numberOfCollisions', {
						type: 'value',
						common: {
							name: 'Anzahl der Kollisionen',
							desc: 'Anzahl der Kollisionen',
							type: 'number',
							role: 'value',
							min: 0,
							read: true,
							write: false
						},
						native: {}
					});
					await this.setObjectNotExistsAsync(mowerData[i].id + '.statistics.totalChargingTime', {
						type: 'value',
						common: {
							name: 'Gesamtladezeit',
							desc: 'Gesamtladezeit',
							type: 'number',
							role: 'value',
							min: 0,
							unit: 'ms',
							read: true,
							write: false
						},
						native: {}
					});
					await this.setObjectNotExistsAsync(mowerData[i].id + '.statistics.totalCuttingTime', {
						type: 'value',
						common: {
							name: 'Gesamt Maehzeit',
							desc: 'Gesamt Maehzeit',
							type: 'number',
							role: 'value',
							min: 0,
							unit: 'ms',
							read: true,
							write: false
						},
						native: {}
					});
					await this.setObjectNotExistsAsync(mowerData[i].id + '.statistics.totalRunningTime', {
						type: 'value',
						common: {
							name: 'Gesamtlaufzeit',
							desc: 'Gesamtlaufzeit',
							type: 'number',
							role: 'value',
							min: 0,
							unit: 'ms',
							read: true,
							write: false
						},
						native: {}
					});
					await this.setObjectNotExistsAsync(mowerData[i].id + '.statistics.totalSearchingTime', {
						type: 'value',
						common: {
							name: 'Gesamtsuchzeit',
							desc: 'Gesamtsuchzeit',
							type: 'number',
							role: 'value',
							min: 0,
							unit: 'ms',
							read: true,
							write: false
						},
						native: {}
					});

und in async fillObjects(mowerData) {

			this.setStateAsync(mowerData[i].id + '.statistics.cuttingBladeUsageTime', {val: mowerData[i].attributes.statistics.cuttingBladeUsageTime, ack: true});
			this.setStateAsync(mowerData[i].id + '.statistics.numberOfChargingCycles', {val: mowerData[i].attributes.statistics.numberOfChargingCycles, ack: true});
			this.setStateAsync(mowerData[i].id + '.statistics.numberOfCollisions', {val: mowerData[i].attributes.statistics.numberOfCollisions, ack: true});
			this.setStateAsync(mowerData[i].id + '.statistics.totalChargingTime', {val: mowerData[i].attributes.statistics.totalChargingTime, ack: true});
			this.setStateAsync(mowerData[i].id + '.statistics.totalCuttingTime', {val: mowerData[i].attributes.statistics.totalCuttingTime, ack: true});
			this.setStateAsync(mowerData[i].id + '.statistics.totalRunningTime', {val: mowerData[i].attributes.statistics.totalRunningTime, ack: true});
			this.setStateAsync(mowerData[i].id + '.statistics.totalSearchingTime', {val: mowerData[i].attributes.statistics.totalSearchingTime, ack: true});

und in async connectToWS() {

					if ('statistics' in jsonMessage.attributes) {
						this.setStateAsync(jsonMessage.id + '.statistics.cuttingBladeUsageTime', {val: jsonMessage.attributes.statistics.cuttingBladeUsageTime, ack: true});
						this.setStateAsync(jsonMessage.id + '.statistics.numberOfChargingCycles', {val: jsonMessage.attributes.statistics.numberOfChargingCycles, ack: true});
						this.setStateAsync(jsonMessage.id + '.statistics.numberOfCollisions', {val: jsonMessage.attributes.statistics.numberOfCollisions, ack: true});
						this.setStateAsync(jsonMessage.id + '.statistics.totalChargingTime', {val: jsonMessage.attributes.statistics.totalChargingTime, ack: true});
						this.setStateAsync(jsonMessage.id + '.statistics.totalCuttingTime', {val: jsonMessage.attributes.statistics.totalCuttingTime, ack: true});
						this.setStateAsync(jsonMessage.id + '.statistics.totalRunningTime', {val: jsonMessage.attributes.statistics.totalRunningTime, ack: true});
						this.setStateAsync(jsonMessage.id + '.statistics.totalSearchingTime', {val: jsonMessage.attributes.statistics.totalSearchingTime, ack: true});
						// this.log.debug(`[wss.on - message]: jsonMessage.attributes.statistics: ${JSON.stringify(jsonMessage.attributes.statistics)}`);
					}

Version of Node.js

16.16.0

Version of ioBroker js-controller

4.0.23

Version of "husqvarna-automower"-adapter

0.2.0

Version of "admin"-adapter

6.2.13

Operating system incl. version running ioBroker

Linux (Docker)

Checklist of files to include below

  • iobroker.current.log (Please share the logs in debug mode and check that there are no personal information)
  • Contents of the JavaScript browser console (always include in cases of issues with the user interface)

Additional information & file uploads

main.txt

Hallo @ArnoD15
Vielen Dank für die Info und die Vorarbeit! Diese Werte wurden demnach erst kürzlich von Husqvarna der API hinzugefügt. Ich werde den Adapter entsprechend ergänzen.
Grüsse

Der Adapter wurde entsprechend aktualisiert. Über eine Rückmeldung eurer Tests würde ich mich freuen.

Soeben getestet und funktioniert.
Die Umrechnung in Stunden wäre noch schön, kann man aber auch mit bindings in Vis machen.

Danke für den Adapter und deine Bemühungen.