From 05a84ed115b7ab80be2cb9f142aeccf5ee9d23ad Mon Sep 17 00:00:00 2001 From: SeydX Date: Fri, 8 Oct 2021 12:45:16 +0200 Subject: [PATCH] v5.0.8 --- .gitignore | 3 +- .npmignore | 3 +- Changelog.md | 11 ++ README.md | 2 +- config.schema.json | 4 + homebridge-ui/server.js | 28 +++-- .../ui/src/mixins/homebridge.mixin.js | 4 + package-lock.json | 112 ++++++++++-------- package.json | 8 +- src/accessories/accessory.config.js | 2 +- src/accessories/accessory.setup.js | 32 +++-- src/accessories/accessory.utils.js | 40 ++++++- src/utils/utils.js | 14 +++ 13 files changed, 179 insertions(+), 84 deletions(-) diff --git a/.gitignore b/.gitignore index 6083f13..801e738 100644 --- a/.gitignore +++ b/.gitignore @@ -56,4 +56,5 @@ typings/ # dotenv environment variables file .env -homebridge-ui/public \ No newline at end of file +homebridge-ui/public +test.js \ No newline at end of file diff --git a/.npmignore b/.npmignore index e7ca88f..76ffd07 100644 --- a/.npmignore +++ b/.npmignore @@ -62,4 +62,5 @@ example-config.json .prettierrc.json .eslintrc.js images/hb_braviatvos_ui_final.gif -homebridge-ui/ui \ No newline at end of file +homebridge-ui/ui +test.js diff --git a/Changelog.md b/Changelog.md index 82b7961..d5f913c 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,5 +1,16 @@ # Changelog +# v5.0.8 - 2021-10-08 + +## Breaking Changes +- Commands with the same values are now merged. If you have used commands as inputs, please remove the TV cache and create a new one by clicking the "refresh" button in the UI and revise your config + +## Notable Changes +- Added new tv channel source: `ATSCT` + +## Bugfixes +- Minor Bugfixes + # v5.0.7 - 2021-10-02 ## Bugfixes diff --git a/README.md b/README.md index ca2a22c..b008e62 100644 --- a/README.md +++ b/README.md @@ -242,7 +242,7 @@ You need to put the PSK entered in your tv also in your config.json. |----------------|--------------|-----------|-------------|-------------| | channels.name | **X** | Name for the channel to display in the tv inputs list | channels.channel | **X** | Number of the channel as seen on the TV. -| channels.source | **X** | Source of the channel. | | `dvbt`, `dvbc`, `dvbs`, `isdbt`, `isdbc`, `isdbs`, `analog` +| channels.source | **X** | Source of the channel. | | `dvbt`, `dvbc`, `dvbs`, `isdbt`, `isdbc`, `atsct`, `isdbs`, `analog` ## Options TV Commands diff --git a/config.schema.json b/config.schema.json index f681898..1402ca6 100644 --- a/config.schema.json +++ b/config.schema.json @@ -276,6 +276,10 @@ "title": "ISDBC", "enum": ["isdbc"] }, + { + "title": "ATSCT", + "enum": ["atsct"] + }, { "title": "Analog", "enum": ["analog"] diff --git a/homebridge-ui/server.js b/homebridge-ui/server.js index 9bdd0e5..3dd008a 100644 --- a/homebridge-ui/server.js +++ b/homebridge-ui/server.js @@ -202,7 +202,7 @@ class UiServer extends HomebridgePluginUiServer { //REFRESH APPS apps.forEach((app) => { - const cachedApp = tvCache.apps.find((cachedApp) => cachedApp.name === app.name); + const cachedApp = tvCache.apps.find((cachedApp) => cachedApp && cachedApp.name === app.name); if (!cachedApp) { tvCache.apps.push(app); @@ -210,11 +210,13 @@ class UiServer extends HomebridgePluginUiServer { }); //REMOVE NOT EXISTING APPS - tvCache.apps = tvCache.apps.filter((cachedApp) => apps.find((app) => app.name === cachedApp.name)); + tvCache.apps = tvCache.apps.filter((cachedApp) => cachedApp && apps.find((app) => app.name === cachedApp.name)); //REFRESH CHANNELS channels.forEach((channel) => { - const cachedChannel = tvCache.channels.find((cachedChannel) => cachedChannel.uri === channel.uri); + const cachedChannel = tvCache.channels.find( + (cachedChannel) => cachedChannel && cachedChannel.uri === channel.uri + ); if (!cachedChannel) { tvCache.channels.push(channel); @@ -222,26 +224,30 @@ class UiServer extends HomebridgePluginUiServer { }); //REMOVE NOT EXISTING APPS - tvCache.channels = tvCache.channels.filter((cachedChannel) => - channels.find((channel) => channel.uri === cachedChannel.uri) + tvCache.channels = tvCache.channels.filter( + (cachedChannel) => cachedChannel && channels.find((channel) => channel.uri === cachedChannel.uri) ); //REFRESH COMMANDS commands.forEach((command) => { - const cachedCommand = tvCache.commands.find((cachedCommand) => cachedCommand.value === command.value); + const cachedCommand = tvCache.commands.find( + (cachedCommand) => cachedCommand && cachedCommand.value === command.value + ); if (!cachedCommand) { tvCache.commands.push(command); } }); - /*tvCache.commands = tvCache.commands.filter((cachedCommand) => - commands.find((command) => command.value === cachedCommand.value) - );*/ + tvCache.commands = tvCache.commands.filter( + (cachedCommand) => cachedCommand && commands.find((command) => command.value === cachedCommand.value) + ); //REFRESH INPUTS inputs.forEach((exInput) => { - const cachedExInput = tvCache.inputs.find((cachedExInput) => cachedExInput.uri === exInput.uri); + const cachedExInput = tvCache.inputs.find( + (cachedExInput) => cachedExInput && cachedExInput.uri === exInput.uri + ); if (!cachedExInput) { tvCache.inputs.push(exInput); @@ -249,7 +255,7 @@ class UiServer extends HomebridgePluginUiServer { }); /*tvCache.inputs = tvCache.inputs.filter((cachedExInput) => - inputs.find((exInput) => exInput.uri === cachedExInput.uri) + inputs.find((exInput) => exInput && exInput.uri === cachedExInput.uri) );*/ await this.storeTV(tvCache, television.name); diff --git a/homebridge-ui/ui/src/mixins/homebridge.mixin.js b/homebridge-ui/ui/src/mixins/homebridge.mixin.js index e3cc1e5..a26342c 100644 --- a/homebridge-ui/ui/src/mixins/homebridge.mixin.js +++ b/homebridge-ui/ui/src/mixins/homebridge.mixin.js @@ -105,6 +105,10 @@ export default { title: 'ISDBC', enum: ['isdbc'], }, + { + title: 'ATSCT', + enum: ['atsct'], + }, { title: 'Analog', enum: ['analog'], diff --git a/package-lock.json b/package-lock.json index 2f77138..63a511f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,13 +1,13 @@ { "name": "homebridge-bravia-tvos", - "version": "5.0.7", + "version": "5.0.8", "lockfileVersion": 1, "requires": true, "dependencies": { "@babel/code-frame": { - "version": "7.14.5", - "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.14.5.tgz", - "integrity": "sha512-9pzDqyc6OLDaqe+zbACgFkb6fKMNG6CObKpnYXChRsvYGyEdc7CA2BaqeOM+vOtCS5ndmJicPJhKAwYRI6UfFw==", + "version": "7.15.8", + "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.15.8.tgz", + "integrity": "sha512-2IAnmn8zbvC/jKYhq5Ki9I+DwjlrtMPUCH/CpHvqI4dNnlwHwsxoIhlc8WcYY5LSYknXQtAlFYuHfqAFCvQ4Wg==", "dev": true, "requires": { "@babel/highlight": "^7.14.5" @@ -20,20 +20,20 @@ "dev": true }, "@babel/core": { - "version": "7.15.5", - "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.15.5.tgz", - "integrity": "sha512-pYgXxiwAgQpgM1bNkZsDEq85f0ggXMA5L7c+o3tskGMh2BunCI9QUwB9Z4jpvXUOuMdyGKiGKQiRe11VS6Jzvg==", + "version": "7.15.8", + "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.15.8.tgz", + "integrity": "sha512-3UG9dsxvYBMYwRv+gS41WKHno4K60/9GPy1CJaH6xy3Elq8CTtvtjT5R5jmNhXfCYLX2mTw+7/aq5ak/gOE0og==", "dev": true, "requires": { - "@babel/code-frame": "^7.14.5", - "@babel/generator": "^7.15.4", + "@babel/code-frame": "^7.15.8", + "@babel/generator": "^7.15.8", "@babel/helper-compilation-targets": "^7.15.4", - "@babel/helper-module-transforms": "^7.15.4", + "@babel/helper-module-transforms": "^7.15.8", "@babel/helpers": "^7.15.4", - "@babel/parser": "^7.15.5", + "@babel/parser": "^7.15.8", "@babel/template": "^7.15.4", "@babel/traverse": "^7.15.4", - "@babel/types": "^7.15.4", + "@babel/types": "^7.15.6", "convert-source-map": "^1.7.0", "debug": "^4.1.0", "gensync": "^1.0.0-beta.2", @@ -43,9 +43,9 @@ } }, "@babel/eslint-parser": { - "version": "7.15.7", - "resolved": "https://registry.npmjs.org/@babel/eslint-parser/-/eslint-parser-7.15.7.tgz", - "integrity": "sha512-yJkHyomClm6A2Xzb8pdAo4HzYMSXFn1O5zrCYvbFP0yQFvHueLedV8WiEno8yJOKStjUXzBZzJFeWQ7b3YMsqQ==", + "version": "7.15.8", + "resolved": "https://registry.npmjs.org/@babel/eslint-parser/-/eslint-parser-7.15.8.tgz", + "integrity": "sha512-fYP7QFngCvgxjUuw8O057SVH5jCXsbFFOoE77CFDcvzwBVgTOkMD/L4mIC5Ud1xf8chK/no2fRbSSn1wvNmKuQ==", "dev": true, "requires": { "eslint-scope": "^5.1.1", @@ -63,12 +63,12 @@ } }, "@babel/generator": { - "version": "7.15.4", - "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.15.4.tgz", - "integrity": "sha512-d3itta0tu+UayjEORPNz6e1T3FtvWlP5N4V5M+lhp/CxT4oAA7/NcScnpRyspUMLK6tu9MNHmQHxRykuN2R7hw==", + "version": "7.15.8", + "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.15.8.tgz", + "integrity": "sha512-ECmAKstXbp1cvpTTZciZCgfOt6iN64lR0d+euv3UZisU5awfRawOvg07Utn/qBGuH4bRIEZKrA/4LzZyXhZr8g==", "dev": true, "requires": { - "@babel/types": "^7.15.4", + "@babel/types": "^7.15.6", "jsesc": "^2.5.1", "source-map": "^0.5.0" } @@ -133,19 +133,27 @@ } }, "@babel/helper-module-transforms": { - "version": "7.15.4", - "resolved": "https://registry.npmjs.org/@babel/helper-module-transforms/-/helper-module-transforms-7.15.4.tgz", - "integrity": "sha512-9fHHSGE9zTC++KuXLZcB5FKgvlV83Ox+NLUmQTawovwlJ85+QMhk1CnVk406CQVj97LaWod6KVjl2Sfgw9Aktw==", + "version": "7.15.8", + "resolved": "https://registry.npmjs.org/@babel/helper-module-transforms/-/helper-module-transforms-7.15.8.tgz", + "integrity": "sha512-DfAfA6PfpG8t4S6npwzLvTUpp0sS7JrcuaMiy1Y5645laRJIp/LiLGIBbQKaXSInK8tiGNI7FL7L8UvB8gdUZg==", "dev": true, "requires": { "@babel/helper-module-imports": "^7.15.4", "@babel/helper-replace-supers": "^7.15.4", "@babel/helper-simple-access": "^7.15.4", "@babel/helper-split-export-declaration": "^7.15.4", - "@babel/helper-validator-identifier": "^7.14.9", + "@babel/helper-validator-identifier": "^7.15.7", "@babel/template": "^7.15.4", "@babel/traverse": "^7.15.4", - "@babel/types": "^7.15.4" + "@babel/types": "^7.15.6" + }, + "dependencies": { + "@babel/helper-validator-identifier": { + "version": "7.15.7", + "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.15.7.tgz", + "integrity": "sha512-K4JvCtQqad9OY2+yTU8w+E82ywk/fe+ELNlt1G8z3bVGlZfn/hOcQQsUhGhW/N+tb3fxK800wLtKOE/aM0m72w==", + "dev": true + } } }, "@babel/helper-optimise-call-expression": { @@ -222,9 +230,9 @@ } }, "@babel/parser": { - "version": "7.15.6", - "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.15.6.tgz", - "integrity": "sha512-S/TSCcsRuCkmpUuoWijua0Snt+f3ewU/8spLo+4AXJCZfT0bVCzLD5MuOKdrx0mlAptbKzn5AdgEIIKXxXkz9Q==", + "version": "7.15.8", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.15.8.tgz", + "integrity": "sha512-BRYa3wcQnjS/nqI8Ac94pYYpJfojHVvVXJ97+IDCImX4Jc8W8Xv1+47enbruk+q1etOpsQNwnfFcNGw+gtPGxA==", "dev": true }, "@babel/template": { @@ -520,16 +528,16 @@ } }, "browserslist": { - "version": "4.17.0", - "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.17.0.tgz", - "integrity": "sha512-g2BJ2a0nEYvEFQC208q8mVAhfNwpZ5Mu8BwgtCdZKO3qx98HChmeg448fPdUzld8aFmfLgVh7yymqV+q1lJZ5g==", + "version": "4.17.3", + "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.17.3.tgz", + "integrity": "sha512-59IqHJV5VGdcJZ+GZ2hU5n4Kv3YiASzW6Xk5g9tf5a/MAzGeFwgGWU39fVzNIOVcgB3+Gp+kiQu0HEfTVU/3VQ==", "dev": true, "requires": { - "caniuse-lite": "^1.0.30001254", - "colorette": "^1.3.0", - "electron-to-chromium": "^1.3.830", + "caniuse-lite": "^1.0.30001264", + "electron-to-chromium": "^1.3.857", "escalade": "^3.1.1", - "node-releases": "^1.1.75" + "node-releases": "^1.1.77", + "picocolors": "^0.2.1" } }, "buffer-from": { @@ -573,9 +581,9 @@ "dev": true }, "caniuse-lite": { - "version": "1.0.30001258", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001258.tgz", - "integrity": "sha512-RBByOG6xWXUp0CR2/WU2amXz3stjKpSl5J1xU49F1n2OxD//uBZO4wCKUiG+QMGf7CHGfDDcqoKriomoGVxTeA==", + "version": "1.0.30001265", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001265.tgz", + "integrity": "sha512-YzBnspggWV5hep1m9Z6sZVLOt7vrju8xWooFAgN6BA5qvy98qPAPb7vNUzypFaoh2pb3vlfzbDO8tB57UPGbtw==", "dev": true }, "caporal": { @@ -725,9 +733,9 @@ } }, "concurrently": { - "version": "6.2.2", - "resolved": "https://registry.npmjs.org/concurrently/-/concurrently-6.2.2.tgz", - "integrity": "sha512-7a45BjVakAl3pprLOeqaOoZfIWZRmdC68NkjyzPbKu0/pE6CRmqS3l8RG7Q2cX9LnRHkB0oPM6af8PS7NEQvYQ==", + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/concurrently/-/concurrently-6.3.0.tgz", + "integrity": "sha512-k4k1jQGHHKsfbqzkUszVf29qECBrkvBKkcPJEUDTyVR7tZd1G/JOfnst4g1sYbFvJ4UjHZisj1aWQR8yLKpGPw==", "dev": true, "requires": { "chalk": "^4.1.0", @@ -833,9 +841,9 @@ "integrity": "sha1-IegLK+hYD5i0aPN5QwZisEbDStI=" }, "date-fns": { - "version": "2.24.0", - "resolved": "https://registry.npmjs.org/date-fns/-/date-fns-2.24.0.tgz", - "integrity": "sha512-6ujwvwgPID6zbI0o7UbURi2vlLDR9uP26+tW6Lg+Ji3w7dd0i3DOcjcClLjLPranT60SSEFBwdSyYwn/ZkPIuw==", + "version": "2.25.0", + "resolved": "https://registry.npmjs.org/date-fns/-/date-fns-2.25.0.tgz", + "integrity": "sha512-ovYRFnTrbGPD4nqaEqescPEv1mNwvt+UTqI3Ay9SzNtey9NZnYu6E2qCcBBgJ6/2VF1zGGygpyTDITqpQQ5e+w==", "dev": true }, "debug": { @@ -903,9 +911,9 @@ } }, "electron-to-chromium": { - "version": "1.3.842", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.842.tgz", - "integrity": "sha512-P/nDMPIYdb2PyqCQwhTXNi5JFjX1AsDVR0y6FrHw752izJIAJ+Pn5lugqyBq4tXeRSZBMBb2ZGvRGB1djtELEQ==", + "version": "1.3.861", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.861.tgz", + "integrity": "sha512-GZyflmpMnZRdZ1e2yAyvuFwz1MPSVQelwHX4TJZyXypB8NcxdPvPNwy5lOTxnlkrK13EiQzyTPugRSnj6cBgKg==", "dev": true }, "emoji-regex": { @@ -2138,9 +2146,9 @@ "dev": true }, "node-releases": { - "version": "1.1.75", - "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-1.1.75.tgz", - "integrity": "sha512-Qe5OUajvqrqDSy6wrWFmMwfJ0jVgwiw4T3KqmbTcZ62qW0gQkheXYhcFM1+lOVcGUoRxcEcfyvFMAnDgaF1VWw==", + "version": "1.1.77", + "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-1.1.77.tgz", + "integrity": "sha512-rB1DUFUNAN4Gn9keO2K1efO35IDK7yKHCdCaIMvFO7yUYmmZYeDjnGKle26G4rwj+LKRQpjyUUvMkPglwGCYNQ==", "dev": true }, "node-ssdp": { @@ -2366,6 +2374,12 @@ "pify": "^3.0.0" } }, + "picocolors": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-0.2.1.tgz", + "integrity": "sha512-cMlDqaLEqfSaW8Z7N5Jw+lyIW869EzT73/F5lhtY9cLGoVxSXznfgfXMO0Z5K0o0Q2TkTXq+0KFsdnSe3jDViA==", + "dev": true + }, "pify": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/pify/-/pify-3.0.0.tgz", diff --git a/package.json b/package.json index 54df924..d6a79be 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "homebridge-bravia-tvos", - "version": "5.0.7", + "version": "5.0.8", "description": "Homebridge plugin for Sony Bravia Android TVs", "main": "index.js", "repository": { @@ -54,10 +54,10 @@ "fs-extra": "^10.0.0" }, "devDependencies": { - "@babel/core": "7.15.5", - "@babel/eslint-parser": "7.15.7", + "@babel/core": "7.15.8", + "@babel/eslint-parser": "7.15.8", "@babel/eslint-plugin": "7.14.5", - "concurrently": "^6.2.2", + "concurrently": "^6.3.0", "eslint": "^7.32.0", "eslint-config-prettier": "^8.3.0", "eslint-plugin-import": "^2.24.2", diff --git a/src/accessories/accessory.config.js b/src/accessories/accessory.config.js index 9fb0bdb..84e2441 100644 --- a/src/accessories/accessory.config.js +++ b/src/accessories/accessory.config.js @@ -6,7 +6,7 @@ const Config = (tvConfig) => { const validDisplayCatagories = ['apps', 'channels', 'commands', 'inputs', 'macros']; const validSpeakerOutput = ['speaker', 'headphone', 'other']; const validSpeakerAccTypes = ['lightbulb', 'switch', 'fan']; - const validChannelSources = ['dvbt', 'dvbc', 'dvbs', 'isdbt', 'isdbs', 'isdbc', 'analog']; + const validChannelSources = ['dvbt', 'dvbc', 'dvbs', 'isdbt', 'isdbs', 'isdbc', 'atsct', 'analog']; const validInputSources = ['cec', 'component', 'composite', 'hdmi', 'scart', 'widi']; tvConfig.speaker = tvConfig.speaker || {}; diff --git a/src/accessories/accessory.setup.js b/src/accessories/accessory.setup.js index 6ac9836..a83453b 100644 --- a/src/accessories/accessory.setup.js +++ b/src/accessories/accessory.setup.js @@ -71,9 +71,9 @@ const refreshCache = async (device, bravia, storagePath) => { } }); - /*tvCache.commands = tvCache.commands.filter( + tvCache.commands = tvCache.commands.filter( (cachedCommand) => cachedCommand && commands.find((command) => command && command.value === cachedCommand.value) - );*/ + ); //REFRESH INPUTS inputs.forEach((exInput) => { @@ -168,48 +168,54 @@ const Setup = async (devices, tvConfigs, storagePath) => { //REFRESH APPS apps.forEach((app) => { - const cachedApp = tvCache.apps.find((cachedApp) => cachedApp.name === app.name); + const cachedApp = tvCache.apps.find((cachedApp) => cachedApp && cachedApp.name === app.name); if (!cachedApp) { tvCache.apps.push(app); } }); - tvCache.apps = tvCache.apps.filter((cachedApp) => apps.find((app) => app.name === cachedApp.name)); + tvCache.apps = tvCache.apps.filter((cachedApp) => apps.find((app) => app && app.name === cachedApp.name)); //REFRESH CHANNELS channels.forEach((channel) => { - const cachedChannel = tvCache.channels.find((cachedChannel) => cachedChannel.uri === channel.uri); + const cachedChannel = tvCache.channels.find( + (cachedChannel) => cachedChannel && cachedChannel.uri === channel.uri + ); if (!cachedChannel) { tvCache.channels.push(channel); } }); - tvCache.channels = tvCache.channels.filter((cachedChannel) => - channels.find((channel) => channel.uri === cachedChannel.uri) + tvCache.channels = tvCache.channels.filter( + (cachedChannel) => cachedChannel && channels.find((channel) => channel.uri === cachedChannel.uri) ); //REFRESH COMMANDS commands.forEach((command) => { - const cachedCommand = tvCache.commands.find((cachedCommand) => cachedCommand.value === command.value); + const cachedCommand = tvCache.commands.find( + (cachedCommand) => cachedCommand && cachedCommand.value === command.value + ); if (!cachedCommand) { tvCache.commands.push(command); } }); - /*tvCache.commands = tvCache.commands.filter((cachedCommand) => - commands.find((command) => command.value === cachedCommand.value) - );*/ + tvCache.commands = tvCache.commands.filter( + (cachedCommand) => cachedCommand && commands.find((command) => command.value === cachedCommand.value) + ); //REFRESH INPUTS inputs.forEach((exInput) => { - const cachedExInput = tvCache.inputs.find((cachedExInput) => cachedExInput.uri === exInput.uri); + const cachedExInput = tvCache.inputs.find( + (cachedExInput) => cachedExInput && cachedExInput.uri === exInput.uri + ); if (!cachedExInput) { tvCache.inputs.push(exInput); } }); /*tvCache.inputs = tvCache.inputs.filter((cachedExInput) => - inputs.find((exInput) => exInput.uri === cachedExInput.uri) + inputs.find((exInput) => exInput && exInput.uri === cachedExInput.uri) );*/ } else { //NEW diff --git a/src/accessories/accessory.utils.js b/src/accessories/accessory.utils.js index 9873653..85a800e 100644 --- a/src/accessories/accessory.utils.js +++ b/src/accessories/accessory.utils.js @@ -2,7 +2,7 @@ const fs = require('fs-extra'); const logger = require('../utils/logger'); -const { setTimeoutAsync } = require('../utils/utils'); +const { countValues, setTimeoutAsync } = require('../utils/utils'); exports.fetchApps = async (deviceName, bravia) => { let apps = []; @@ -60,7 +60,16 @@ exports.fetchInputs = async (deviceName, bravia, wakeUp) => { exports.fetchChannels = async (deviceName, bravia) => { let channels = []; - let validChannelSources = ['tv:dvbt', 'tv:dvbc', 'tv:dvbs', 'tv:isdbt', 'tv:isdbs', 'tv:isdbc', 'tv:analog']; + let validChannelSources = [ + 'tv:dvbt', + 'tv:dvbc', + 'tv:dvbs', + 'tv:isdbt', + 'tv:isdbs', + 'tv:isdbc', + 'tv:atsct', + 'tv:analog', + ]; try { logger.debug('Fetching channels', deviceName); @@ -117,17 +126,42 @@ exports.fetchChannels = async (deviceName, bravia) => { exports.fetchCommands = async (deviceName, bravia) => { let commands = []; + let mergedCommands = []; try { logger.debug('Fetching commands', deviceName); commands = await bravia.getIRCCCodes(); + + //merge duplicated ircc codes with different name + const countList = countValues(commands); + const duplicateCmds = Object.keys(countList).filter((cmd) => countList[cmd] > 1); + + let cmdDups = commands.filter((cmd) => duplicateCmds.includes(cmd.value)); + let cmdWithoutDups = commands.filter((cmd) => !duplicateCmds.includes(cmd.value)); + + let cmdMergedDups = []; + + cmdDups.forEach((cmd) => { + const cmdExist = cmdMergedDups.find((cmd2) => cmd2.value === cmd.value); + + if (!cmdExist) { + const duplicate = cmdDups.find((cmd2) => cmd2.value === cmd.value && cmd2.name !== cmd.name); + + cmdMergedDups.push({ + name: `${cmd.name} / ${duplicate.name}`, + value: cmd.value, + }); + } + }); + + mergedCommands = cmdWithoutDups.concat(cmdMergedDups); } catch (err) { logger.warn('An error occured during fetching applications!', deviceName); logger.error(err, deviceName); } - return commands; + return mergedCommands; }; exports.getTvFromCache = async (deviceName, storagePath) => { diff --git a/src/utils/utils.js b/src/utils/utils.js index 9ecf808..9506fdb 100644 --- a/src/utils/utils.js +++ b/src/utils/utils.js @@ -48,4 +48,18 @@ exports.validMAC = (mac) => { } }; +exports.countValues = (arr = []) => { + const res = {}; + for (let i = 0; i < arr.length; i++) { + const { value } = arr[i]; + // eslint-disable-next-line no-prototype-builtins + if (res.hasOwnProperty(value)) { + res[value]++; + } else { + res[value] = 1; + } + } + return res; +}; + exports.setTimeoutAsync = (ms) => new Promise((res) => setTimeout(res, ms));