@nzws/homebridge-mlru1-light
Advanced tools
Comparing version 1.1.3 to 1.1.4
@@ -73,2 +73,3 @@ "use strict"; | ||
.setCharacteristic(this.Characteristic.SerialNumber, 'ho-me-br-id-ge'); | ||
void this.initializeQueue(); | ||
} | ||
@@ -82,2 +83,6 @@ /** | ||
} | ||
async initializeQueue() { | ||
const PQueue = await Promise.resolve().then(() => __importStar(require('p-queue'))); | ||
this.queue = new PQueue.default({ concurrency: 1 }); | ||
} | ||
handleOnGet() { | ||
@@ -88,28 +93,35 @@ this.log.debug('handleOnGet'); | ||
async handleOnSet(value) { | ||
if (value === this.updatingStatus) { | ||
if (!this.queue) { | ||
this.log.error('queue is not initialized'); | ||
return; | ||
} | ||
this.updatingStatus = value; | ||
this.log.debug('handleOnSet:', value); | ||
const signalId = this._getSignalId('ico_on'); | ||
let isOutdated = false; | ||
try { | ||
if (this.natureClient) { | ||
if (!value) { | ||
return this.queue.add(async () => { | ||
if (value === this.updatingStatus) { | ||
return; | ||
} | ||
this.updatingStatus = value; | ||
this.log.debug('handleOnSet:', value); | ||
const signalId = this._getSignalId('ico_on'); | ||
let isOutdated = false; | ||
try { | ||
if (this.natureClient) { | ||
if (!value) { | ||
await this.natureClient.sendSignal(signalId); | ||
} | ||
await this.natureClient.sendSignal(signalId); | ||
} | ||
await this.natureClient.sendSignal(signalId); | ||
isOutdated = value !== this.updatingStatus; | ||
if (!isOutdated) { | ||
this.currentStatus = value; | ||
this.OnCharacteristic.updateValue(this.currentStatus); | ||
return value; | ||
} | ||
} | ||
isOutdated = value !== this.updatingStatus; | ||
if (!isOutdated) { | ||
this.currentStatus = value; | ||
this.OnCharacteristic.updateValue(this.currentStatus); | ||
catch (e) { | ||
if (!isOutdated) { | ||
this.updatingStatus = !value; | ||
} | ||
throw e; | ||
} | ||
} | ||
catch (e) { | ||
if (!isOutdated) { | ||
this.updatingStatus = !value; | ||
} | ||
throw e; | ||
} | ||
}); | ||
} | ||
@@ -121,46 +133,52 @@ handleBrightnessGet() { | ||
async handleBrightnessSet(value) { | ||
const prevPercent = this.updatingBrightness; | ||
const newPercent = value; | ||
const prevCount = this._percentToBrightness(prevPercent); | ||
const newCount = this._percentToBrightness(newPercent); | ||
const diff = Math.abs(newCount - prevCount); | ||
const isBright = newCount > prevCount; | ||
this.log.debug('handleBrightnessSet', { | ||
value, | ||
prevCount, | ||
newCount, | ||
diff, | ||
isBright, | ||
}); | ||
if (diff < 0) { | ||
if (!this.queue) { | ||
this.log.error('queue is not initialized'); | ||
return; | ||
} | ||
this.updatingBrightness = newPercent; | ||
const signalUp = this._getSignalId('ico_arrow_top'); | ||
const signalDown = this._getSignalId('ico_arrow_bottom'); | ||
let isOutdated = false; | ||
try { | ||
if (this.natureClient) { | ||
for (let i = 0; i < diff; i++) { | ||
if (isBright) { | ||
await this.natureClient.sendSignal(signalUp); | ||
return this.queue.add(async () => { | ||
const prevPercent = this.updatingBrightness; | ||
const newPercent = value; | ||
const prevCount = this._percentToBrightness(prevPercent); | ||
const newCount = this._percentToBrightness(newPercent); | ||
const diff = Math.abs(newCount - prevCount); | ||
const isBright = newCount > prevCount; | ||
this.log.debug('handleBrightnessSet', { | ||
value, | ||
prevCount, | ||
newCount, | ||
diff, | ||
isBright, | ||
}); | ||
if (diff < 0) { | ||
return; | ||
} | ||
this.updatingBrightness = newPercent; | ||
const signalUp = this._getSignalId('ico_arrow_top'); | ||
const signalDown = this._getSignalId('ico_arrow_bottom'); | ||
let isOutdated = false; | ||
try { | ||
if (this.natureClient) { | ||
for (let i = 0; i < diff; i++) { | ||
if (isBright) { | ||
await this.natureClient.sendSignal(signalUp); | ||
} | ||
else { | ||
await this.natureClient.sendSignal(signalDown); | ||
} | ||
} | ||
else { | ||
await this.natureClient.sendSignal(signalDown); | ||
} | ||
} | ||
isOutdated = newPercent !== this.updatingBrightness; | ||
if (!isOutdated) { | ||
this.currentBrightness = newPercent; | ||
this.BrightnessCharacteristic.updateValue(this.currentBrightness); | ||
return value; | ||
} | ||
} | ||
isOutdated = newPercent !== this.updatingBrightness; | ||
if (!isOutdated) { | ||
this.currentBrightness = newPercent; | ||
// todo: 複数回投げると前の値が反映される? | ||
// this.BrightnessCharacteristic.updateValue(this.currentBrightness); | ||
catch (e) { | ||
if (!isOutdated) { | ||
this.updatingBrightness = prevPercent; | ||
} | ||
throw e; | ||
} | ||
} | ||
catch (e) { | ||
if (!isOutdated) { | ||
this.updatingBrightness = prevPercent; | ||
} | ||
throw e; | ||
} | ||
}); | ||
} | ||
@@ -167,0 +185,0 @@ _percentToBrightness(percent) { |
{ | ||
"displayName": "MLRU1 Light with Nature Remo", | ||
"name": "@nzws/homebridge-mlru1-light", | ||
"version": "1.1.3", | ||
"version": "1.1.4", | ||
"description": "アイリスオーヤマ製「ML-RU1」リモコンを使用する照明を操作するプラグイン", | ||
@@ -27,3 +27,4 @@ "license": "Apache-2.0", | ||
"dependencies": { | ||
"nature-remo": "^2.0.0" | ||
"nature-remo": "^2.0.0", | ||
"p-queue": "8.0.1" | ||
}, | ||
@@ -30,0 +31,0 @@ "devDependencies": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
19797
201
2
+ Addedp-queue@8.0.1
+ Addedeventemitter3@5.0.1(transitive)
+ Addedp-queue@8.0.1(transitive)
+ Addedp-timeout@6.1.3(transitive)