Skip to content

Commit 1d48e6c

Browse files
authored
Merge pull request #41 from Fabrizz/dev-features
🔇Added device filtering (actually added heh)
2 parents d065971 + 54af706 commit 1d48e6c

8 files changed

Lines changed: 64 additions & 7 deletions

File tree

MMM-OnSpotify.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ Module.register("MMM-OnSpotify", {
3232
// state, as user data does not change that much, this prevents unnecessary api calls.
3333
userDataMaxAge: 14400,
3434
userAffinityMaxAge: 36000,
35+
// Filter which devices show up in the module
36+
deviceFilter: [],
37+
deviceFilterExclude: false,
38+
filterNoticeSubtitle: true,
3539

3640
updateInterval: {
3741
isPlaying: 1,
@@ -137,7 +141,7 @@ Module.register("MMM-OnSpotify", {
137141
typeof this.config.theming.experimentalCSSOverridesForMM2 === "object";
138142

139143
////////////////////////////////////////////////////////////////////////////////////////////
140-
this.version = "3.1.0";
144+
this.version = "3.2.0";
141145
////////////////////////////////////////////////////////////////////////////////////////////
142146

143147
this.displayUser =
@@ -190,6 +194,8 @@ Module.register("MMM-OnSpotify", {
190194
this.sendSocketNotification("SET_CREDENTIALS_REFRESH", {
191195
preferences: {
192196
userAffinityUseTracks: this.config.userAffinityUseTracks,
197+
deviceFilter: this.config.deviceFilter,
198+
deviceFilterExclude: this.config.deviceFilterExclude,
193199
},
194200
credentials: {
195201
clientId: this.config.clientID,
@@ -352,7 +358,12 @@ Module.register("MMM-OnSpotify", {
352358
});
353359
break;
354360
case "USER_DATA":
355-
this.userData = payload;
361+
this.userData = {
362+
...payload,
363+
subtitleOverride:
364+
this.playerData && this.config.filteredDeviceNotice ?
365+
this.playerData.notAllowedDevice : false,
366+
};
356367
this.userData.age = Date.now();
357368
this.requestUserData = false;
358369
this.smartUpdate("USER_DATA");

README.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,12 @@ Once you finish, you are all set with the basic configuration. Scroll down to se
6060
userAffinityUseTracks: false,
6161
prefersLargeImageSize: false,
6262
hideTrackLenghtAndAnimateProgress: false,
63-
showDebugPalette: true,
63+
showDebugPalette: false,
6464
userDataMaxAge: 14400,
6565
userAffinityMaxAge: 36000,
66+
deviceFilter: [],
67+
deviceFilterExclude: false,
68+
filterNoticeSubtitle: true,
6669
// Update intervals [SEE BELOW]
6770
isPlaying: 1,
6871
isEmpty: 2,
@@ -87,9 +90,9 @@ Once you finish, you are all set with the basic configuration. Scroll down to se
8790
useColorInTitle: true,
8891
useColorInUserData: true,
8992
showBlurBackground: true,
90-
blurCorrectionInFrameSide: true,
91-
blurCorrectionInAllSides: true,
92-
alwaysUseDefaultDeviceIcon: true,
93+
blurCorrectionInFrameSide: false,
94+
blurCorrectionInAllSides: false,
95+
alwaysUseDefaultDeviceIcon: false,
9396
experimentalCSSOverridesForMM2: false, // [SEE BELOW]
9497
},
9598
},
@@ -123,6 +126,9 @@ experimentalCSSOverridesForMM2: [
123126
| showDebugPalette <br> `false` | Shows the Vibrant output as a palette in the web console. <br /><br /> <img alt="Debug palette" src=".github/content/readme/image-debugpalette.png" width="80%"> |
124127
| userDataMaxAge <br> `14400` | (Seconds) The time in seconds of user data TTL. If set to 0, its updated everytime that the player goes to idle, as user data rarely changes, this allows a middle ground between updating always and only on boot |
125128
| userAffinityMaxAge <br> `36000` | (Seconds) The time in seconds of affinity data TTL. If set to 0, its updated everytime that the player goes to idle, as user data rarely changes, this allows a middle ground between updating always and only on boot |
129+
| deviceFilter <br> `list[]` | List of device names to filter from the module, by default, its an inclusion list, you can change this using `deviceFilterExclude` (making it an exclusion list). When a filtered device plays `displayWhenEmpty` shows. Example: `["Sonos Bedroom", "DESKTOP-ABCD123"]` |
130+
| deviceFilterExclude <br> `false` | Inverts the `deviceFilter` list, making it exclude devices |
131+
| filterNoticeSubtitle <br> `true`| Changes the subtitle of `displayWhenEmpty`, to not show a false status if the `deviceFilter` is set |
126132

127133
### Polling Intervals:
128134
| Key | Description |

node_helper.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,16 @@ module.exports = NodeHelper.create({
2121
this.lastDeviceName = null;
2222
// The times that an available (but empty) player has been returned by the api
2323
this.isPlayerInTransit = 0;
24+
// Configuration sent to the helper
25+
this.preferences = null;
2426
},
2527

2628
socketNotificationReceived: function (notification, payload) {
2729
switch (notification) {
2830
case "SET_CREDENTIALS_REFRESH":
2931
this.fetcher = new SpotifyFetcher(payload);
3032
this.fetchSpotifyData("PLAYER");
33+
this.preferences = payload.preferences
3134
break;
3235
case "REFRESH_PLAYER":
3336
this.fetchSpotifyData("PLAYER");
@@ -57,6 +60,24 @@ module.exports = NodeHelper.create({
5760
);
5861
switch (type) {
5962
case "PLAYER":
63+
// CASE S1 The data is OK and the target is a filtered device
64+
if (data && data.device && data.device.name && !this.isAllowedDevice(data.device.name)) {
65+
this.sendSocketNotification("PLAYER_DATA", {
66+
statusIsPlayerEmpty: true,
67+
statusIsNewSong: false,
68+
statusIsChangeToEmptyPlayer: this.lastPlayerStatus,
69+
statusIsChangeToMediaPlayer: false,
70+
statusPlayerUpdating: false,
71+
statusIsDeviceChange: false,
72+
notAllowedDevice: data.device.name
73+
});
74+
this.lastMediaUri = "empty";
75+
this.lastPlayerStatus = false;
76+
this.lastPlayerStatusCount = 0;
77+
this.lastDeviceName = "unknown";
78+
break
79+
}
80+
// CASE S2 The data is OK and the target is in a private session
6081
if (data && data.device && data.device.is_private_session) {
6182
let payload = {
6283
/* Player data */
@@ -76,6 +97,7 @@ module.exports = NodeHelper.create({
7697
statusPlayerUpdating: false,
7798
statusIsDeviceChange:
7899
this.lastDeviceName !== data.device.name ? true : false,
100+
notAllowedDevice: false
79101
};
80102
this.sendSocketNotification("PLAYER_DATA", payload);
81103
this.lastMediaUri = "privatesession";
@@ -84,6 +106,7 @@ module.exports = NodeHelper.create({
84106
this.lastPlayerStatusCount = 0;
85107
break;
86108
}
109+
87110
if (data && data.item) {
88111
// CASE 1 The data is OK and there is an ITEM in the player
89112
let isTrack =
@@ -127,6 +150,7 @@ module.exports = NodeHelper.create({
127150
statusPlayerUpdating: false,
128151
statusIsDeviceChange:
129152
this.lastDeviceName !== data.device.name ? true : false,
153+
notAllowedDevice: false
130154
};
131155
this.sendSocketNotification("PLAYER_DATA", payload);
132156
this.lastMediaUri = data.item.uri;
@@ -145,6 +169,7 @@ module.exports = NodeHelper.create({
145169
statusIsChangeToMediaPlayer: false,
146170
statusPlayerUpdating: true,
147171
statusIsDeviceChange: false,
172+
notAllowedDevice: false
148173
});
149174
this.lastPlayerStatusCount = this.lastPlayerStatusCount + 1;
150175
this.lastPlayerStatus = true;
@@ -157,6 +182,7 @@ module.exports = NodeHelper.create({
157182
statusIsChangeToMediaPlayer: false,
158183
statusPlayerUpdating: false,
159184
statusIsDeviceChange: false,
185+
notAllowedDevice: false
160186
});
161187
this.lastMediaUri = "empty";
162188
this.lastPlayerStatus = false;
@@ -171,6 +197,7 @@ module.exports = NodeHelper.create({
171197
statusIsChangeToMediaPlayer: false,
172198
statusPlayerUpdating: false,
173199
statusIsDeviceChange: false,
200+
notAllowedDevice: false
174201
});
175202
this.lastMediaUri = "empty";
176203
this.lastPlayerStatus = false;
@@ -226,6 +253,12 @@ module.exports = NodeHelper.create({
226253
}
227254
},
228255

256+
isAllowedDevice: function (currentDevice) {
257+
if (!this.preferences.deviceFilter || this.preferences.deviceFilter.length < 1) return true
258+
return this.preferences.deviceFilterExclude ?
259+
!this.preferences.deviceFilter.includes(currentDevice) :
260+
this.preferences.deviceFilter.includes(currentDevice)
261+
},
229262
processArtists: (artists) => artists.map((artist) => artist.name).join(", "),
230263
processImages: (images) => {
231264
return {

translations/de.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"DISPLAY_PRIVATE": "Private Spotify-Sitzung",
3+
"FILTERED_PLAYING": "Nothing is playing in this room.",
34
"PRODUCT_WARNING": "Das aktuelle Konto hat kein Spotify Premium. Dieses Modul erfordert ein Premium-Konto!",
45
"CONNECTION_WARNING": "Es gab einen Verbindungsfehler. Verlangsamung des Abfragezyklus von api.spotify/...",
56
"CONNECTION_ERROR": "Verbindungsfehler bestehen weiterhin. Weitere Verlangsamung des Abfragezyklus. Alte Player-Daten werden ausgeblendet.",

translations/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"DISPLAY_PRIVATE": "Private Spotify session",
3+
"FILTERED_PLAYING": "Nothing is playing in this room.",
34
"PRODUCT_WARNING": "The current account is not using Spotify Premium. This module requieres a Premium account.",
45
"CONNECTION_WARNING": "There was a connection error. Slowing the polling of api.spotify/...",
56
"CONNECTION_ERROR": "Connection errors persists. Slowing the polling more. Hiding old player data.",

translations/es.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"DISPLAY_PRIVATE": "Sesión de Spotify privada",
3+
"FILTERED_PLAYING": "Nada en reprocucción en este disp.",
34
"PRODUCT_WARNING": "La cuenta actual de Spotify no es Premium. Este modulo requiere de una cuenta Premium para funcionar.",
45
"CONNECTION_WARNING": "Hubo un problema de conexión. Ralentizando el polling a api.spotify/...",
56
"CONNECTION_ERROR": "Los problemas de conexión persisten. Ralentizando más el polling. Ocultando la reprocucción antigua.",

translations/yourlanguaje.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"DISPLAY_PRIVATE": "Private Spotify session",
3+
"FILTERED_PLAYING": "Nothing is playing in this room.",
34
"PRODUCT_WARNING": "The current account is not using Spotify Premium. This module requieres a Premium account.",
45
"CONNECTION_WARNING": "There was a connection error. Slowing the polling of api.spotify/...",
56
"CONNECTION_ERROR": "Connection errors persists. Slowing the polling more. Hiding old player data.",

utils/SpotifyDomBuilder.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ class SpotifyDomBuilder {
4242
palette_muteddark: "--ONSP-VIBRANT-DARKMUTED",
4343
brand_spotify: "--ONSP-BRANDCOLOR-SPOTIFY",
4444
};
45+
this.changeSubtitleForNotice =
46+
this.config.deviceFilter.length > 0 && this.config.filterNoticeSubtitle ?
47+
"FILTERED_PLAYING" : "NOTHING_PLAYING"
4548
try {
4649
this.animationDefaultDelayFromCSS = Number(
4750
getComputedStyle(this.root)
@@ -665,7 +668,7 @@ class SpotifyDomBuilder {
665668
);
666669
this.root.style.setProperty(
667670
"--ONSP-INTERNAL-USER-SUBTITLE",
668-
`'${this.translate("NOTHING_PLAYING")}'`,
671+
`'${this.translate(this.changeSubtitleForNotice)}'`,
669672
);
670673
if (!data.image) {
671674
this.root.style.setProperty(

0 commit comments

Comments
 (0)