node-red-contrib-smartnora
Version:
Google Smart Home integration via Smart Nora https://smart-nora.eu/
51 lines (50 loc) • 1.93 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const util_1 = require("./util");
module.exports = function (RED) {
RED.nodes.registerType('noraf-speaker', function (config) {
RED.nodes.createNode(this, config);
const noraConfig = RED.nodes.getNode(config.nora);
if (!(noraConfig === null || noraConfig === void 0 ? void 0 : noraConfig.valid)) {
return;
}
(0, util_1.registerNoraDevice)(this, RED, config, {
deviceConfig: {
type: 'action.devices.types.SPEAKER',
traits: ['action.devices.traits.Volume', 'action.devices.traits.OnOff'],
name: {
name: config.devicename,
},
roomHint: config.roomhint,
willReportState: true,
state: {
on: false,
online: true,
currentVolume: 50,
isMuted: false,
},
noraSpecific: {},
attributes: {
volumeCanMuteAndUnmute: false,
volumeMaxLevel: 100,
levelStepSize: parseInt(config.step, 10) || 1,
},
},
updateStatus: ({ state, update }) => {
update(`${state.on ? 'on' : 'off'}:${state.isMuted ? 'mute' : state.currentVolume}`);
},
mapStateToOutput: state => ({
payload: {
on: state.on,
volume: state.currentVolume,
},
}),
handleNodeInput: async ({ msg, updateState }) => {
await updateState(msg === null || msg === void 0 ? void 0 : msg.payload, [{
from: 'volume',
to: 'currentVolume',
}]);
},
});
});
};