From 8ecc915f597ab8d9f2d25b9a9fffd5fd2a7d2f6b Mon Sep 17 00:00:00 2001 From: Grzegorz Date: Sat, 3 Aug 2024 20:17:14 +0200 Subject: [PATCH] refactor iset nput name and target visibility --- package.json | 2 +- src/lgwebosdevice.js | 21 ++++++++++----------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index 7f5dfd9..bc9f4ce 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "displayName": "LG webOS TV", "name": "homebridge-lgwebos-tv", - "version": "2.19.21", + "version": "2.19.22", "description": "Homebridge plugin to control LG webOS TV.", "license": "MIT", "author": "grzegorz914", diff --git a/src/lgwebosdevice.js b/src/lgwebosdevice.js index c128642..90f527c 100644 --- a/src/lgwebosdevice.js +++ b/src/lgwebosdevice.js @@ -1266,10 +1266,8 @@ class LgWebOsDevice extends EventEmitter { const inputReference = input.reference; //get input name - const name = input.name; const savedInputsNames = this.savedInputsNames[inputReference] ?? false; - const inputName = savedInputsNames ? savedInputsNames : name; - input.name = inputName; + input.name = savedInputsNames ? savedInputsNames : input.name; //input mode const inputMode = input.mode; @@ -1281,24 +1279,23 @@ class LgWebOsDevice extends EventEmitter { const isConfigured = 1; //get visibility - const currentVisibility = this.savedInputsTargetVisibility[inputReference] ?? 0; - input.visibility = currentVisibility; + input.visibility = this.savedInputsTargetVisibility[inputReference] ?? 0; //add identifier to the input input.identifier = inputIdentifier; //input service - const inputService = accessory.addService(Service.InputSource, inputName, `Input ${inputIdentifier}`); + const inputService = accessory.addService(Service.InputSource, input.name, `Input ${inputIdentifier}`); inputService .setCharacteristic(Characteristic.Identifier, inputIdentifier) - .setCharacteristic(Characteristic.Name, inputName) + .setCharacteristic(Characteristic.Name, input.name) .setCharacteristic(Characteristic.IsConfigured, isConfigured) .setCharacteristic(Characteristic.InputSourceType, inputSourceType) - .setCharacteristic(Characteristic.CurrentVisibilityState, currentVisibility) + .setCharacteristic(Characteristic.CurrentVisibilityState, input.visibility) inputService.getCharacteristic(Characteristic.ConfiguredName) .onGet(async () => { - return inputName; + return input.name; }) .onSet(async (value) => { if (value === this.savedInputsNames[inputReference]) { @@ -1306,6 +1303,7 @@ class LgWebOsDevice extends EventEmitter { } try { + input.name = value; this.savedInputsNames[inputReference] = value; await this.saveData(this.inputsNamesFile, this.savedInputsNames); const debug = this.enableDebugMode ? this.emit('debug', `Saved ${inputMode === 0 ? 'Input' : 'Channel'} Name: ${value}, Reference: ${inputReference}`) : false; @@ -1321,7 +1319,7 @@ class LgWebOsDevice extends EventEmitter { inputService.getCharacteristic(Characteristic.TargetVisibilityState) .onGet(async () => { - return currentVisibility; + return input.visibility; }) .onSet(async (state) => { if (state === this.savedInputsTargetVisibility[inputReference]) { @@ -1329,9 +1327,10 @@ class LgWebOsDevice extends EventEmitter { } try { + input.visibility = state; this.savedInputsTargetVisibility[inputReference] = state; await this.saveData(this.inputsTargetVisibilityFile, this.savedInputsTargetVisibility); - const debug = this.enableDebugMode ? this.emit('debug', `Saved ${inputMode === 0 ? 'Input' : 'Channel'}: ${inputName}, Target Visibility: ${state ? 'HIDEN' : 'SHOWN'}`) : false; + const debug = this.enableDebugMode ? this.emit('debug', `Saved ${inputMode === 0 ? 'Input' : 'Channel'}: ${input.name}, Target Visibility: ${state ? 'HIDEN' : 'SHOWN'}`) : false; } catch (error) { this.emit('error', `save Target Visibility error: ${error}`); }