@mathquis/node-assistant-protocol
Version:
Assistant protocol decorator for Hermes protocol
19 lines • 541 B
JavaScript
module.exports = (hermes, logger) => {
return (topic, object) => {
return {
...object,
setVolume: async (siteId, volume) => {
volume = parseInt(volume)
if ( isNaN(volume) ) throw new Error('Invalid volume "' + volume + '"')
volume = Math.max(0, Math.min(100, volume))
logger.debug('Setting %s volume on site "%s" to %d', object.name, siteId, volume)
await hermes.publish(topic, hermes.serialize({
siteId, volume
}))
},
onSetVolume: (handler) => {
return hermes.on(topic, handler)
}
}
}
}