Skip to content

Commit

Permalink
Add hasLights topic
Browse files Browse the repository at this point in the history
  • Loading branch information
C-D-Lewis committed Nov 19, 2024
1 parent 2865826 commit 4b041e9
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
20 changes: 20 additions & 0 deletions apps/visuals/src/api/hasLights.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const { log, conduit, config } = require('../node-common')(['log', 'conduit', 'config']);

/**
* Handle a 'hasLights' topic packet.
*
* @param {object} packet - The conduit packet request.
* @param {object} res - Express response object.
*/
const handleHasLightsPacket = async (packet, res) => {
try {
const { LEDS } = config.get(['LEDS']);
const hasLights = LEDS.USE_HARDWARE === true;
conduit.respond(res, { status: 200, message: { hasLights } });
} catch (e) {
log.error(e);
conduit.respond(res, { status: 500, error: e.message });
}
};

module.exports = handleHasLightsPacket;
1 change: 1 addition & 0 deletions apps/visuals/src/modules/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const setup = async () => {
conduit.on('off', require('../api/off'), EMPTY_PACKET_SCHEMA);
conduit.on('demo', require('../api/demo'), EMPTY_PACKET_SCHEMA);
conduit.on('spotify', require('../api/spotify'), EMPTY_PACKET_SCHEMA);
conduit.on('hasLights', require('../api/hasLights'), EMPTY_PACKET_SCHEMA);
};

module.exports = {
Expand Down
11 changes: 11 additions & 0 deletions apps/visuals/tests/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,17 @@ describe('API', () => {
});
});

describe('Conduit topic: hasLights', () => {
it('should return 200 / OK', async () => {
const response = await testing.sendConduitPacket({
to: 'visuals', topic: 'hasLights',
});

expect(response.status).to.equal(200);
expect(response.message.hasLights).to.not.equal(undefined);
});
});

if (!process.env.DOCKER_TEST) {
// Requires pre-authorization with remote concierge, and something playing
describe('Conduit topic: spotify', () => {
Expand Down

0 comments on commit 4b041e9

Please sign in to comment.