Skip to content

Commit

Permalink
release 3.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
grzegorz914 committed Oct 26, 2024
1 parent 7922527 commit 40e861c
Show file tree
Hide file tree
Showing 7 changed files with 204 additions and 125 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

### After update to v3.0.0 RESTFull and MQTT config settings need to be updated

## [3.2.0] - (26.10.2024)

## Changes

- add config validation
- add reconnect if fail on first run
- fix start external integrations
- config schema updated
- cleanup

## [3.1.1] - (25.08.2024)

## Changes
Expand Down
12 changes: 8 additions & 4 deletions config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"pluginType": "platform",
"singular": true,
"fixArrays": true,
"strictValidation": true,
"headerDisplay": "This plugin works with webOS based TV and are exposed to HomeKit as separate accessories and each needs to be manually paired.",
"footerDisplay": "For documentation please see [GitHub repository](https://github.com/grzegorz914/homebridge-lgwebos-tv).",
"schema": {
Expand Down Expand Up @@ -59,7 +60,7 @@
"condition": {
"functionBody": "return model.devices[arrayIndices].getInputsFromDevice === true"
},
"required": true
"required": false
},
"inputsDisplayOrder": {
"title": "Inputs Display Order",
Expand Down Expand Up @@ -196,6 +197,7 @@
"command": {
"title": "RC Command",
"type": "string",
"default": "POWER",
"oneOf": [
{
"title": "0",
Expand Down Expand Up @@ -535,7 +537,7 @@
}
],
"description": "Here select the remote control command.",
"required": false
"required": true
},
"displayType": {
"title": "Display Type",
Expand Down Expand Up @@ -1044,6 +1046,7 @@
"reference": {
"title": "Mode",
"type": "string",
"default": "standard",
"description": "Here choice the Sound Mode.",
"oneOf": [
{
Expand Down Expand Up @@ -1095,7 +1098,7 @@
]
}
],
"required": false
"required": true
},
"displayType": {
"title": "Display Type",
Expand Down Expand Up @@ -1157,6 +1160,7 @@
"reference": {
"title": "Output",
"type": "string",
"default": "tv_speaker",
"description": "Here choice the Sound Output.",
"oneOf": [
{
Expand Down Expand Up @@ -1220,7 +1224,7 @@
]
}
],
"required": false
"required": true
},
"displayType": {
"title": "Display Type",
Expand Down
30 changes: 23 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
const path = require('path');
const fs = require('fs');
const LgWebOsDevice = require('./src/lgwebosdevice.js');
const ImpulseGenerator = require('./src/impulsegenerator.js');
const CONSTANTS = require('./src/constants.json');

class LgWebOsPlatform {
Expand Down Expand Up @@ -36,7 +37,7 @@ class LgWebOsPlatform {

//debug config
const enableDebugMode = device.enableDebugMode || false;
const debug = enableDebugMode ? log.info(`Device: ${host} ${deviceName}, did finish launching.`) : false;
const debug = enableDebugMode ? log.info(`Device: ${host} ${deviceName}, Did finish launching.`) : false;
const config = {
...device,
mqtt: {
Expand Down Expand Up @@ -71,16 +72,16 @@ class LgWebOsPlatform {
}
});
} catch (error) {
log.error(`Device: ${host} ${deviceName}, prepare files error: ${error}`);
log.error(`Device: ${host} ${deviceName}, Prepare files error: ${error}`);
return;
}

//webos device
try {
this.lgWebOsDevice = new LgWebOsDevice(api, device, keyFile, devInfoFile, inputsFile, channelsFile, inputsNamesFile, inputsTargetVisibilityFile);
this.lgWebOsDevice.on('publishAccessory', (accessory) => {
const lgWebOsDevice = new LgWebOsDevice(api, device, keyFile, devInfoFile, inputsFile, channelsFile, inputsNamesFile, inputsTargetVisibilityFile);
lgWebOsDevice.on('publishAccessory', (accessory) => {
api.publishExternalAccessories(CONSTANTS.PluginName, [accessory]);
log.success(`Device: ${host} ${deviceName}, published as external accessory.`);
log.success(`Device: ${host} ${deviceName}, Published as external accessory.`);
})
.on('devInfo', (devInfo) => {
log.info(devInfo);
Expand All @@ -101,10 +102,25 @@ class LgWebOsPlatform {
log.error(`Device: ${host} ${deviceName}, ${error}`);
});

await this.lgWebOsDevice.start();
//create impulse generator
const impulseGenerator = new ImpulseGenerator();
impulseGenerator.on('start', async () => {
try {
await lgWebOsDevice.start();
impulseGenerator.stop();
} catch (error) {
log.error(`Device: ${host} ${deviceName}, ${error}, trying again.`);
};
}).on('state', (state) => {
const debug = enableDebugMode ? state ? log.info(`Device: ${host} ${deviceName}, Start impulse generator started.`) : log.info(`Device: ${host} ${deviceName}, Start impulse generator stopped.`) : false;
});

//start impulse generator
impulseGenerator.start([{ name: 'start', sampling: 45000 }]);
} catch (error) {
log.error(`Device: ${host} ${deviceName}, did finish launching error: ${error}`);
log.error(`Device: ${host} ${deviceName}, Did finish launching error: ${error}`);
}
await new Promise(resolve => setTimeout(resolve, 250));
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"displayName": "LG webOS TV",
"name": "homebridge-lgwebos-tv",
"version": "3.1.11",
"version": "3.2.0",
"description": "Homebridge plugin to control LG webOS TV.",
"license": "MIT",
"author": "grzegorz914",
Expand Down
50 changes: 50 additions & 0 deletions src/impulsegenerator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
"use strict";
const EventEmitter = require('events');

class ImpulseGenerator extends EventEmitter {
constructor() {
super();
this.timersState = false;
}

async start(timers) {
if (this.timersState) {
await this.stop();
}

this.timers = [];
for (const timer of timers) {
this.emit(timer.name);

const newTimer = setInterval(() => {
this.emit(timer.name);
}, timer.sampling);
this.timers.push(newTimer);
};

//update state
this.timersState = true;
this.state();

return true;
}

async stop() {
if (this.timersState) {
this.timers.forEach(timer => clearInterval(timer));
}

//update state
this.timers = [];
this.timersState = false;
this.state();

return true;
}

state() {
this.emit('state', this.timersState);
return this.timersState;
}
}
module.exports = ImpulseGenerator;
Loading

0 comments on commit 40e861c

Please sign in to comment.