Skip to content

Commit

Permalink
Awtrix led matrix support added
Browse files Browse the repository at this point in the history
  • Loading branch information
petersem committed Feb 10, 2024
1 parent 0592861 commit a51b039
Show file tree
Hide file tree
Showing 8 changed files with 255 additions and 70 deletions.
1 change: 1 addition & 0 deletions classes/cards/MediaCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class MediaCard {
this.rating = "";
this.summary = "";
this.tagLine = "";
this.episodeName = "";
this.runTime = "";
this.pageCount = "";
this.resCodec = "";
Expand Down
12 changes: 9 additions & 3 deletions classes/core/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ class Settings {
this.hideUser = DEFAULT_SETTINGS.hideUser;
this.contentRatings = DEFAULT_SETTINGS.contentRatings;
this.links = DEFAULT_SETTINGS.links;
this.enableLinks = DEFAULT_SETTINGS.enableLinks;
this.linkFrequency = DEFAULT_SETTINGS.linkFrequency;
this.enableAwtrix = DEFAULT_SETTINGS.enableAwtrix;
this.awtrixIP = DEFAULT_SETTINGS.awtrixIP;
return;
}

Expand Down Expand Up @@ -142,6 +142,7 @@ class Settings {
if(readSettings.enableTrivia==undefined) readSettings.enableTrivia = 'false';
if(readSettings.enableLinks==undefined) readSettings.enableLinks = 'false';
if(readSettings.recentlyAddedDays==undefined) readSettings.recentlyAddedDays = 0;
if(readSettings.enableAwtrix==undefined) readSettings.enableAwtrix = 'false';
} catch (ex) {
// do nothing if error as it reads ok anyhow
let d = new Date();
Expand Down Expand Up @@ -173,6 +174,7 @@ class Settings {
this.enableReadarr = 'false';
this.enableTrivia = 'false';
this.enableLinks = 'false';
this.enableAwtrix = 'false';

const data = JSON.stringify(this, null, 4);

Expand Down Expand Up @@ -367,9 +369,13 @@ class Settings {
else this.enableLinks = cs.enableLinks;
if (jsonObject.linkFrequency) this.linkFrequency = jsonObject.linkFrequency;
else this.linkFrequency = cs.linkFrequency;
if (jsonObject.enableAwtrix) this.enableAwtrix = jsonObject.enableAwtrix;
else this.enableAwtrix = cs.enableAwtrix;
if (jsonObject.awtrixIP) this.awtrixIP = jsonObject.awtrixIP;
else this.awtrixIP = cs.awtrixIP;

// convert JSON object to string (pretty format)
const data = JSON.stringify(this, null, 4);


// write JSON string to a file
fs.writeFileSync("config/settings.json", data, (err) => {
Expand Down
78 changes: 61 additions & 17 deletions classes/custom/awtrix.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,83 @@
const mediaCard = require("../cards/MediaCard");
const cType = require("../cards/CardType");
const util = require('util');
const util = require("util");
const axios = require("axios");
const { CardTypeEnum } = require("../cards/CardType");
var playing = null;

/**
/**
* @desc Used to get a list of custom pictures
*/
class Awtrix {
constructor() { }
constructor() {}

/**
* @desc Custom link slide array
*/
async post(ip,payload) {
try{
await axios.post(
ip + "/api/custom?name=posterr", null
)

await axios.post(
ip + "/api/custom?name=posterr", payload
)

return 0;
async post(ip, payload) {
if (payload !== null) {
try {
await axios.post(ip + "/api/custom?name=" + payload.unique, payload);

return 0;
} catch (ex) {
let now = new Date();
throw "Awtrix add failed - " + ex;
}
}
catch(ex){
}

async delete(ip, appName) {
try {
await axios.post(ip + "/api/custom?name=" + appName, null);

return 0;
} catch (ex) {
let now = new Date();
console.log(now.toLocaleString() + " * Awtrix post failed - " + ex);
}
throw "Awtrix delete failed - " + ex;
}
}

async clear(ip) {
try {
await axios.get(ip + "/api/loop").then(function (response) {
if (Object.keys(response.data).length > 0) {
Object.keys(response.data).forEach((app) => {
if (app.search(/posterr/i) !== -1) {
axios.post(ip + "/api/custom?name=" + app, null);
let now = new Date();
console.log(now.toLocaleString() + " Awtrix Clearing " + app);
}
});
}
});
} catch (ex) {
throw " Awtrix initialisation failed";
console.log('throw');
}
}

async rtttl(ip,tune) {
try {
await axios.post(ip + "/api/rtttl",tune);
return 0;
} catch (ex) {
throw "Awtrix greeting failed - " + ex;
}

}

async appFind(oldApps, uniqueValue) {
const result = oldApps.find(({ unique }) => unique === uniqueValue);

return result;
}

async appFindID(appsArray, value) {
const result = oldApps.find((element) => element === value);

return result;
}
}

module.exports = Awtrix;
1 change: 1 addition & 0 deletions classes/mediaservers/plex.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ class Plex {
" - '" +
md.title +
"'";
medCard.episodeName = md.title;
result = md.guid.split("/");

// Use TVDB ID if available, otherwise use GUID
Expand Down
4 changes: 3 additions & 1 deletion consts.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ const DEFAULT_SETTINGS = {
triviaCategories: "",
enableTrivia: "false",
triviaNumber: "",
contentRatings: ""
contentRatings: "",
enableAwtrix: "false",
awtrixIP: ""
};

module.exports = DEFAULT_SETTINGS;
Loading

0 comments on commit a51b039

Please sign in to comment.