UNPKG

hap-nodejs

Version:

HAP-NodeJS is a Node.js implementation of HomeKit Accessory Server.

44 lines 2.23 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const __1 = require(".."); const speakerUUID = __1.uuid.generate("hap-nodejs:accessories:smart-speaker"); const speaker = exports.accessory = new __1.Accessory("SmartSpeaker", speakerUUID); // @ts-expect-error: Core/BridgeCore API speaker.username = "89:A8:E4:1E:95:EE"; // @ts-expect-error: Core/BridgeCore API speaker.pincode = "676-54-344"; speaker.category = 26 /* Categories.SPEAKER */; const service = new __1.Service.SmartSpeaker("Smart Speaker", ""); let currentMediaState = __1.Characteristic.CurrentMediaState.PAUSE; let targetMediaState = __1.Characteristic.TargetMediaState.PAUSE; // ConfigureName is used to listen for Name changes inside the Home App. // A device manufacturer would probably need to adjust the name of the device in the AirPlay 2 protocol (or something) service.setCharacteristic(__1.Characteristic.ConfiguredName, "Smart Speaker"); service.setCharacteristic(__1.Characteristic.Mute, false); service.setCharacteristic(__1.Characteristic.Volume, 100); service.getCharacteristic(__1.Characteristic.CurrentMediaState) .on("get" /* CharacteristicEventTypes.GET */, (callback) => { console.log("Reading CurrentMediaState: " + currentMediaState); callback(undefined, currentMediaState); }) .updateValue(currentMediaState); // init value service.getCharacteristic(__1.Characteristic.TargetMediaState) .on("set" /* CharacteristicEventTypes.SET */, (value, callback) => { console.log("Setting TargetMediaState to: " + value); targetMediaState = value; currentMediaState = targetMediaState; callback(); service.setCharacteristic(__1.Characteristic.CurrentMediaState, targetMediaState); }) .on("get" /* CharacteristicEventTypes.GET */, (callback) => { console.log("Reading TargetMediaState: " + targetMediaState); callback(undefined, targetMediaState); }) .updateValue(targetMediaState); service.getCharacteristic(__1.Characteristic.ConfiguredName) .on("set" /* CharacteristicEventTypes.SET */, (value, callback) => { console.log(`Name was changed to: '${value}'`); callback(); }); speaker.addService(service); //# sourceMappingURL=SmartSpeaker_accessory.js.map