UNPKG

@mathquis/node-assistant-protocol

Version:
23 lines 610 B
module.exports = (hermes, logger) => { return (topic, object) => { return { ...object, state: async (online = false, attributes = {}, state = {}) => { logger.debug('%s state (online: %s)', object.name, online) const payload = {online, attributes, state} const options = {retain: true} await hermes.publish(topic, hermes.serialize(payload), options) }, onState: handler => { return hermes.on(topic, handler) }, getLastWill: () => { return { topic, payload: hermes.serialize({online: false, attributes: {}, state: {}}), retain: true } } } } }