Skip to content

Commit

Permalink
refactor iset nput name and target visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
grzegorz914 committed Aug 3, 2024
1 parent 9025d1c commit 8ecc915
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
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": "2.19.21",
"version": "2.19.22",
"description": "Homebridge plugin to control LG webOS TV.",
"license": "MIT",
"author": "grzegorz914",
Expand Down
21 changes: 10 additions & 11 deletions src/lgwebosdevice.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -1281,31 +1279,31 @@ 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]) {
return;
}

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;
Expand All @@ -1321,17 +1319,18 @@ class LgWebOsDevice extends EventEmitter {

inputService.getCharacteristic(Characteristic.TargetVisibilityState)
.onGet(async () => {
return currentVisibility;
return input.visibility;
})
.onSet(async (state) => {
if (state === this.savedInputsTargetVisibility[inputReference]) {
return;
}

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}`);
}
Expand Down

0 comments on commit 8ecc915

Please sign in to comment.