Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Set up NodeJS
uses: actions/setup-node@v2
uses: actions/setup-node@v4
with:
node-version: 22.12.0
node-version: 22.16.0
cache: 'npm'
- name: Install dependencies
run: npm install
Expand Down
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
22.16.0
10 changes: 10 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export default {
transform: {},
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
},
testEnvironment: 'node',
transformIgnorePatterns: [
'node_modules/(?!good-env|@inquirer/prompts|cli-table|got|jshue|sonos|terminal-image)'
]
};
3,814 changes: 3,240 additions & 574 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"name": "groove-sensor",
"version": "0.0.1",
"type": "module",
"main": "src/index.js",
"scripts": {
"test": "echo \"Coming soon\" && exit 0",
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
"lint": "semistandard src/**/*.js",
"format": "semistandard --fix src/**/*.js",
"start": "node src/index.js"
Expand All @@ -21,6 +22,7 @@
"terminal-image": "^3.1.1"
},
"devDependencies": {
"jest": "^29.7.0",
"nyc": "15.1.0",
"semistandard": "*",
"tape": "5.5.3"
Expand Down
19 changes: 10 additions & 9 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
const process = require('node:process');
const { isIP } = require('net');
const env = require('good-env');
const Sonos = require('./lib/sonos');
const Sensor = require('./lib/sensor');
const { hue } = require('./lib/config');
const log = require('./lib/log');
const {
import process from 'node:process';
import { isIP } from 'net';
import env from 'good-env';
import Sonos from './lib/sonos.js';
import Sensor from './lib/sensor.js';
import { hue } from './lib/config.js';
import log from './lib/log.js';
import {
buildPlayQueue,
chooseSystemNode,
chooseVibe,
printNowPlaying,
randomTrack
} = require('./lib/utils');
} from './lib/utils.js';

const ipOk = str => isIP(str) === 4 || isIP(str) === 6;

// Ensure all the required environemnt variables are present
Expand Down
190 changes: 95 additions & 95 deletions src/lib/config.js
Original file line number Diff line number Diff line change
@@ -1,97 +1,97 @@
const env = require('good-env');
import env from 'good-env';

module.exports = {
hue: {
username: env.get('HUE_USERNAME'),
bridgeIp: env.get('HUE_BRIDGE_IP'),
sensorId: env.get('HUE_SENSOR_ID')
},
// @TODO: Consider just making these playlists
eightiesTrackIds: [
{
// "Dirty Diana" - Michael Jackson
uri: 'spotify:track:3yBlJtq86wROQpHi1goEKT',
bestVolume: '25',
start: 15
},
{
// "Human" - The Human League
uri: 'spotify:track:537yo062QIz16oQOgxmul3',
bestVolume: '25'
},
{
// "Everybody Wants to Rule The World" - Tears for Fears
uri: 'spotify:track:4RvWPyQ5RL0ao9LPZeSouE',
bestVolume: '25'
},
{
// "Holding Out for a Hero" - Bonnie Tyler
uri: 'spotify:track:5Hyr47BBGpvOfcykSCcaw9',
bestVolume: '25'
},
{
// "The Glow" - Willie Hutch
uri: 'spotify:track:7nQ7iZ4FdjaIPEtEKvvzbc',
bestVolume: '25'
},
{
// "On Our Own" - Bobby Brown
uri: 'spotify:track:0cAiOfc6uxr6NCyQ80ZigK',
bestVolume: '25'
},
{
// "Just Got Paid" - Johnny Kemp
uri: 'spotify:track:1OK4hVcucqYKMU9Ipb3dtx',
bestVolume: '25'
},
{
// "Rock Steady" - The Whispers
uri: 'spotify:track:4RRs6lOD5L1KbQ56rp61RM',
bestVolume: '25'
},
{
// "Purple Rain" - Prince
uri: 'spotify:track:3FnP3j1TyiTwbJb5AR2ynT',
bestVolume: '25'
}
],
jazzTrackIds: [
{
// "Misty" - Ella Fitzgerald
uri: 'spotify:track:4kF394GKEnI13QdZBM9mxM',
bestVolume: 30
},
{
// "Flamenco Sketches" - Miles Davis
uri: 'spotify:track:6dRx7OUXfvosnXG3g9lWGi',
bestVolume: '30',
start: 20
},
{
// "You Are Too Beautiful" - Thelonious Monk
uri: 'spotify:track:1fYal59goMHv8Uq9sfNU8k',
bestVolume: '30'
},
{
// "When Sunny Gets Blue" - McCoy Tyner
uri: 'spotify:track:1J9iVCaEriyoMXpj2XszhU',
bestVolume: '30'
},
{
// "Stockholm Love" - Malthilda June
uri: 'spotify:track:3tNuzvJ5z4rN7GPZoWxQdk',
bestVolume: '25'
},
{
// "Thanks, But I Don't Dance" - Rene Marie
uri: 'spotify:track:0yrwVkQZorFkCICB4jjU3p',
bestVolume: '25',
start: 16
},
{
// "Smooth Talking" - Nocturnal Spirits
uri: 'spotify:track:2pQ7tvFq7DgkQnJgU2eKia',
bestVolume: '25'
}
]
export const hue = {
username: env.get('HUE_USERNAME'),
bridgeIp: env.get('HUE_BRIDGE_IP'),
sensorId: env.get('HUE_SENSOR_ID')
};

// @TODO: Consider just making these playlists
export const eightiesTrackIds = [
{
// "Dirty Diana" - Michael Jackson
uri: 'spotify:track:3yBlJtq86wROQpHi1goEKT',
bestVolume: '25',
start: 15
},
{
// "Human" - The Human League
uri: 'spotify:track:537yo062QIz16oQOgxmul3',
bestVolume: '25'
},
{
// "Everybody Wants to Rule The World" - Tears for Fears
uri: 'spotify:track:4RvWPyQ5RL0ao9LPZeSouE',
bestVolume: '25'
},
{
// "Holding Out for a Hero" - Bonnie Tyler
uri: 'spotify:track:5Hyr47BBGpvOfcykSCcaw9',
bestVolume: '25'
},
{
// "The Glow" - Willie Hutch
uri: 'spotify:track:7nQ7iZ4FdjaIPEtEKvvzbc',
bestVolume: '25'
},
{
// "On Our Own" - Bobby Brown
uri: 'spotify:track:0cAiOfc6uxr6NCyQ80ZigK',
bestVolume: '25'
},
{
// "Just Got Paid" - Johnny Kemp
uri: 'spotify:track:1OK4hVcucqYKMU9Ipb3dtx',
bestVolume: '25'
},
{
// "Rock Steady" - The Whispers
uri: 'spotify:track:4RRs6lOD5L1KbQ56rp61RM',
bestVolume: '25'
},
{
// "Purple Rain" - Prince
uri: 'spotify:track:3FnP3j1TyiTwbJb5AR2ynT',
bestVolume: '25'
}
];

export const jazzTrackIds = [
{
// "Misty" - Ella Fitzgerald
uri: 'spotify:track:4kF394GKEnI13QdZBM9mxM',
bestVolume: 30
},
{
// "Flamenco Sketches" - Miles Davis
uri: 'spotify:track:6dRx7OUXfvosnXG3g9lWGi',
bestVolume: '30',
start: 20
},
{
// "You Are Too Beautiful" - Thelonious Monk
uri: 'spotify:track:1fYal59goMHv8Uq9sfNU8k',
bestVolume: '30'
},
{
// "When Sunny Gets Blue" - McCoy Tyner
uri: 'spotify:track:1J9iVCaEriyoMXpj2XszhU',
bestVolume: '30'
},
{
// "Stockholm Love" - Malthilda June
uri: 'spotify:track:3tNuzvJ5z4rN7GPZoWxQdk',
bestVolume: '25'
},
{
// "Thanks, But I Don't Dance" - Rene Marie
uri: 'spotify:track:0yrwVkQZorFkCICB4jjU3p',
bestVolume: '25',
start: 16
},
{
// "Smooth Talking" - Nocturnal Spirits
uri: 'spotify:track:2pQ7tvFq7DgkQnJgU2eKia',
bestVolume: '25'
}
];
5 changes: 3 additions & 2 deletions src/lib/log.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const env = require('good-env');
import env from 'good-env';

const isProd = env.get('NODE_ENV') === 'PRODUCTION';
const noOp = function () {};

module.exports = {
export default {
info: console.log,
debug: (isProd ? noOp : console.debug),
warn: console.warn,
Expand Down
13 changes: 7 additions & 6 deletions src/lib/sensor.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const EventEmitter = require('node:events');
const env = require('good-env');
const jsHue = require('jshue');
const { debug } = require('./log');
import EventEmitter from 'node:events';
import env from 'good-env';
import jsHue from 'jshue';
import log from './log.js';

const { debug } = log;
const hue = jsHue();
const hueMotionStopBuff = env.num('HUE_MOTION_STOP_BUFFER', 90) * 1000;
const hueMotionPollingInterval = env.num('HUE_MOTION_POLLING_INTERVAL', 2) * 1000;
Expand All @@ -10,7 +12,7 @@ const hueMotionPollingInterval = env.num('HUE_MOTION_POLLING_INTERVAL', 2) * 100
* @description Detect a Hue motion sensor, poll it for chances in presence state and emit motion start or stop
* accordingly. Return an EventEmitter which will be the channel over which the client is notifed of state changes.
*/
class Sensor extends EventEmitter {
export default class Sensor extends EventEmitter {
constructor ({ bridgeIp, sensorId, username }) {
super();
EventEmitter.call(this);
Expand Down Expand Up @@ -60,4 +62,3 @@ class Sensor extends EventEmitter {
return this;
}
}
module.exports = Sensor;
15 changes: 7 additions & 8 deletions src/lib/sonos.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const { Sonos, AsyncDeviceDiscovery } = require('sonos');
const env = require('good-env');
const log = require('./log');
const { camelize } = require('./utils');
const discovery = new AsyncDeviceDiscovery();
import { Sonos, AsyncDeviceDiscovery } from 'sonos';
import env from 'good-env';
import log from './log.js';
import { camelize } from './utils.js';

const sonosDiscoveryTimeout = env.num('SONOS_DISCOVERY_TIMEOUT', 5) * 1000;

function init () {
export default function () {
let _nodes = {};
let _targetDevice;

Expand Down Expand Up @@ -42,6 +42,7 @@ function init () {

async discoverNodes () {
log.info('\n---------- Hold tight, finding your Sonos devices... -------------\n');
const discovery = new AsyncDeviceDiscovery();
const sonosDevices = await discovery.discoverMultiple({ timeout: sonosDiscoveryTimeout });
const nodesArr = await Promise.all(sonosDevices.map(async (device) => {
const name = await device.getName();
Expand Down Expand Up @@ -106,5 +107,3 @@ function init () {

return _instance;
}

module.exports = init;
Loading