Skip to content

Commit

Permalink
set volume
Browse files Browse the repository at this point in the history
  • Loading branch information
gtalusan committed Sep 6, 2024
1 parent 7ac93d1 commit 44431d4
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/defaultAccessory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,38 @@ export class DefaultPlatformAccessory {
}
});

const speakerService: Service = this.accessory.getService(`${displayName} Speaker`) ||
this.accessory.addService(this.platform.Service.Speaker, `${displayName} Speaker`);
speakerService.getCharacteristic(this.platform.Characteristic.Volume)
.onSet(async (value: CharacteristicValue) => {
try {
if (!this.connected()) {
return;
}
await this.platform.robovac.setVolume(value as Number);

Check failure on line 69 in src/defaultAccessory.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Prefer using the primitive `number` as a type name, rather than the upper-cased `Number`

Check failure on line 69 in src/defaultAccessory.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Prefer using the primitive `number` as a type name, rather than the upper-cased `Number`

Check failure on line 69 in src/defaultAccessory.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

Prefer using the primitive `number` as a type name, rather than the upper-cased `Number`
} catch (error: unknown) {
this.platform.log.error(error as string);
}
});

const updateVolumeLevel = () => {
if (!this.connected()) {
return;
}
try {
speakerService.updateCharacteristic(this.platform.Characteristic.Volume, this.platform.robovac.volume());
} catch (error: unknown) {
this.platform.log.error(error as string);
}
};

this.platform.robovac.on('tuya.data', updateVolumeLevel);

this.platform.robovac.on('event', (event: RobovacEvent) => {
if (event.command === 'battery') {
updateBatteryLevel();
} else if (event.command === 'volume') {
updateVolumeLevel();
} else if (event.command === 'locate') {
findMyRobot.updateCharacteristic(this.platform.Characteristic.On, event.value as boolean);
}
Expand Down

0 comments on commit 44431d4

Please sign in to comment.