Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add MQTT support for Home Assistant, upgrade to electron 31 #954

Open
wants to merge 32 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
fbc3704
Merge pull request #942 from evancohen/dev
sdetweil Nov 22, 2021
f03b59a
upgrade to electron 17.2, handle errors from unconfigured plugins gra…
sdetweil May 20, 2022
4db9f46
fix package.json for jsonform url
sdetweil May 20, 2022
1821ac5
fix formatting of new pm2 check code
sdetweil May 20, 2022
06615b2
add test for online status for PM2 process detection
sdetweil May 21, 2022
d9e6915
fix giphy and xkcd for api changes
sdetweil May 24, 2022
3d0dd29
add services and notifications from calednar, weather, clock
sdetweil Sep 29, 2022
06e9c8c
fixup services for broadcast status or data
sdetweil Oct 15, 2022
6ee7004
fix for server broadcasts
sdetweil Oct 15, 2022
5622dc3
sync to vnext and electron 17
sdetweil Oct 15, 2022
6710123
bring up to node 18
sdetweil Jan 6, 2024
120fc2d
move some dev dependencies to regular dependencies
sdetweil Jan 6, 2024
50da7f9
Merge branch 'n-w-electron' into dev
sdetweil Jan 6, 2024
6cf8f5d
add support for connecting thru mqtt to home assistant
sdetweil Mar 6, 2024
a1293ec
change version number
sdetweil Apr 6, 2024
4db1364
update mqtt to use ip address and machine name
sdetweil Apr 10, 2024
be98b97
clear scope for rss to prevent error if none
sdetweil Apr 10, 2024
dca9403
add recovery when mqtt broker dies
sdetweil Apr 14, 2024
f2dca12
Merge remote-tracking branch 'refs/remotes/origin/w_mqtt' into w_mqtt
sdetweil Apr 14, 2024
18f7c5f
pass any commandline parms, fix mqtt reconnect if broker dies
sdetweil Apr 14, 2024
81d9ab2
fix missing ip (network address) lib
sdetweil Apr 14, 2024
5bce7d0
fix summary formatting with embedded new lines
sdetweil Apr 21, 2024
5f9f975
fix mqtt broker failure reconnect
sdetweil Apr 28, 2024
62e6b77
fix subscribe recovery and subscribe topic by machine name
sdetweil Apr 30, 2024
089c52e
fix cal entry formatting with \; and mqtt recovery if broker goes down
sdetweil May 3, 2024
ea82d8b
force openweather to v3 api key as only choice in may 2024
sdetweil May 5, 2024
dcf67f4
upgrade to electron 31, disable gpu
sdetweil Jul 2, 2024
4d7075e
add github workflow
sdetweil Nov 12, 2024
7e7c49e
add the package.lock required by github actions
sdetweil Nov 27, 2024
1f2a9d5
add stuff for github workflow
sdetweil Nov 27, 2024
093950b
Merge remote-tracking branch 'refs/remotes/origin/w_mqtt' into w_mqtt
sdetweil Nov 27, 2024
c067727
Update node.js.yml
sdetweil Nov 27, 2024
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
43 changes: 43 additions & 0 deletions .github/workflows/automated-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: "Run Automated Tests"

on:
push:
branches: [master, dev]
pull_request:
branches: [dev]

permissions:
contents: read

jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 30
strategy:
matrix:
node-version: [20.9.0, 20.x, 22.x, 23.x]
steps:
- name: "Checkout code"
uses: actions/checkout@v4
- name: "Use Node.js ${{ matrix.node-version }}"
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
check-latest: true
cache: "npm"
#cache-dependency-path: "./smart-mirror/package-lock.json"
- name: "Install dependencies"
run: |
npm run install --omit=dev
- name: "Run tests"
run: |
Xvfb :99 -screen 0 1024x768x16 &
export DISPLAY=:99
touch app/css/local.css
#npm run test:prettier
#npm run test:js
#npm run test:css
#npm run test
30 changes: 30 additions & 0 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs

name: Node.js CI

on:
push:
branches: [ "w_mqtt" ]
pull_request:
branches: [ "w_mqtt" ]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [18.x, 20.x, 22.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
- run: npm test
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ jsonform
spotify-token.json
main_index.html
motion
package-lock.json
#package-lock.json
app/locales/??c.json
app/css/local.css
.gitignore
.prettierrc
.editorconfig
plugins/
!.gitkeep
32 changes: 32 additions & 0 deletions .gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
plugins/autosleep
plugins/calendar
plugins/commands
plugins/commitstrip
plugins/datetime
plugins/dilbert
plugins/fitbit
plugins/_general
plugins/geolocation
plugins/giphy
plugins/greeting
plugins/ha-display
plugins/light
plugins/maker
plugins/map
plugins/pluginconfig
plugins/reminder
plugins/remote
plugins/rss
plugins/scrobbler
plugins/search
plugins/soundcloud
plugins/speech
plugins/spotify
plugins/stock
plugins/timebox
plugins/timer
plugins/todoist
plugins/traffic
plugins/tvshows
plugins/weather
plugins/xkcd
19 changes: 13 additions & 6 deletions app/css/newfile.css
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
:root{
--scale-factor: 1; /* set default scaling in case we have partial window, debug or in vm terminal window */
--design-width: 1920px;
--design-height: 1080px;
}

@media screen and (width:1920px) and (orientation: landscape) {
@media screen and (orientation: landscape) {
:root{
--scale-factor: 1920/1920;
--scale-factor: var(width) / var(--design-width);
};
}
@media screen and (orientation: portrait) {
:root{
--scale-factor: var(width) / var(--design-height);
};
}

@media screen and (width:3840px) and (orientation: landscape) {
/*@media screen and (width:3840px) and (orientation: landscape) {
:root{
--scale-factor: 3840/1920;
--scale-factor: width/var(--design-width);

};
}
@media screen and (width:1080px) {
:root{
--scale-factor: 1920/1920;
--scale-factor: width/var(--design-width);
};
}
}*/



Expand Down
2 changes: 1 addition & 1 deletion app/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
.config(function (tmhDynamicLocaleProvider) {
console.log(config);
tmhDynamicLocaleProvider.localeLocationPattern(
"bower_components/angular-i18n/angular-locale_" +
"node_modules/angular-i18n/angular-locale_" +
language +
".js"
);
Expand Down
13 changes: 4 additions & 9 deletions app/js/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
function MirrorCtrl(
Focus,
SpeechService,
MQTTService,
AutoSleepService,
// LightService,
$rootScope,
$scope,
$timeout,
Expand Down Expand Up @@ -48,6 +48,7 @@

var resetCommandTimeout;
var listeningTimeout;
MQTTService.start();
SpeechService.init({
listening: function (listening) {
$scope.listening = listening;
Expand Down Expand Up @@ -93,6 +94,7 @@
$scope.focus = AutoSleepService.scope;
AutoSleepService.startAutoSleepTimer();
}
$rootScope.$broadcast("clock-tick",$scope.date)
}
var clearListening = function(){
$scope.listening = false;
Expand Down Expand Up @@ -183,17 +185,10 @@
console.debug("It is", moment().format("h:mm:ss a"));
});

// Control light
/* SpeechService.addCommand("light_action", function (
state,
target,
action
) {
LightService.performUpdate([state, target, action].join(" "));
}); */
};

_this.init();

}

angular.module("SmartMirror").controller("MirrorCtrl", MirrorCtrl);
Expand Down
62 changes: 53 additions & 9 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ const remote = require("./remote.js");
const app = electron.app;
// Module to create native browser window.
const BrowserWindow = electron.BrowserWindow;

//const { BrowserWindow } = require('@electron/remote/main')

// In the main process:
require('@electron/remote/main').initialize()
// Prevent the monitor from going to sleep.
const powerSaveBlocker = electron.powerSaveBlocker;
powerSaveBlocker.start("prevent-display-sleep");
Expand All @@ -17,7 +22,34 @@ const getPort = require("get-port");

// Launching the mirror in dev mode
const DevelopmentMode = process.argv.includes("dev");
const usepm2 = process.argv.includes("usepm2");
let usepm2 = false;
// Replace with:
const debug =DevelopmentMode?true:false;


//if (debug) console.log("getting pm2 process list");
exec("pm2 jlist", (error, stdout) => {
if (!error) {
let output = JSON.parse(stdout);
if (debug)
console.log(
"processing pm2 jlist output, " + output.length + " entries"
);
output.forEach((managed_process) => {
if(debug)
console.log("comparing "+__dirname +" with "+ managed_process.pm2_env.pm_cwd )
// if we find a pm2 process matching our location
// and that process is online, then it is us
if (managed_process.pm2_env.pm_cwd.startsWith(__dirname) && managed_process.pm2_env.status ==="online") {
if (debug)
console.log(
"found our pm2 entry, id=" + managed_process.pm_id
);
usepm2 = true;
}
});
}
});
//var atomScreen = null;
// Load the smart mirror config
let config;
Expand Down Expand Up @@ -47,10 +79,11 @@ try {
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let mainWindow;

app.disableHardwareAcceleration();
function createWindow() {
app.commandLine.appendSwitch("autoplay-policy", "no-user-gesture-required");
app.commandLine.appendSwitch("disable-http-cache");

// Get the displays and render the mirror on a secondary screen if it exists
var atomScreen = null;
if (electron.screen == undefined) {
Expand All @@ -67,6 +100,7 @@ function createWindow() {
break;
}
}

const { width, height } = atomScreen.getPrimaryDisplay().workAreaSize;
var browserWindowOptions = {
width: width,
Expand All @@ -80,14 +114,16 @@ function createWindow() {
nodeIntegration: true,
enableRemoteModule: true,
contextIsolation: false,
additionalArguments:["sonusPort:"+global.sonusSocket]
},
};
if (externalDisplay) {
browserWindowOptions.x = width; //+ 2; //externalDisplay.bounds.x + 50
browserWindowOptions.y = height; //externalDisplay.bounds.y + 50
console.log(
"display size=" + browserWindowOptions.x + "+" + browserWindowOptions.y
);
if(debug)
console.log(
"display size=" + browserWindowOptions.x + "+" + browserWindowOptions.y
);
}

// Create the browser window.
Expand Down Expand Up @@ -148,6 +184,9 @@ function startSonus(port) {
if (config && config.speech && !firstRun) {
// get the sonus communications socket port
getPort({ port: getPort.makeRange(9000, 9500) }).then((port) => {
if(debug)
console.log("found port="+port)
//console.log("global="+JSON.stringify(global,null,2))
global.sonusSocket = port;
config.communications_port = port;
startSonus(config.communications_port);
Expand Down Expand Up @@ -216,10 +255,14 @@ if ((config.remote && config.remote.enabled) || firstRun) {
remote.on("relaunch", function (newConfig) {
console.log("Relaunching...");
// rebuild the html file plugin position info, from the NEW config data
// if pm2 is not being used for this process control
if (!usepm2) {
// recalc plugin info since something changed
loader.loadPluginInfo(__dirname + "/index.html", newConfig);
// force reload
app.relaunch();
}
// else die and pm2 will restart us
app.quit();
});
}
Expand All @@ -241,17 +284,18 @@ if (config.motion && config.motion.enabled) {

mtnProcess.stdout.on("data", function (data) {
var message = data.toString();
//console.log("motion message="+message)
if (message.startsWith("!s:")) {
console.log(message.substring(3));
//console.log(message.substring(3));
mainWindow.webContents.send("motionstart", true);
} else if (message.startsWith("!e:")) {
console.log(message.substring(3));
//console.log(message.substring(3));
mainWindow.webContents.send("motionend", true);
} else if (message.startsWith("!c:")) {
console.log(message.substring(3));
//console.log(message.substring(3));
mainWindow.webContents.send("calibrated", true);
} else if (message.startsWith("!E:")) {
console.log(message.substring(3));
//console.log(message.substring(3));
mainWindow.webContents.send("Error", message.substring(3));
mtnProcess.kill();
} else {
Expand Down
Loading