generated from homebridge/homebridge-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
baran.wang
committed
May 15, 2024
1 parent
e0537a2
commit b81860f
Showing
13 changed files
with
435 additions
and
548 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"homebridge-plugin-aqara": minor | ||
--- | ||
|
||
红外模拟电视遥控器 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"homebridge-plugin-aqara": minor | ||
--- | ||
|
||
新增智能晾衣机 H1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
export * from './lumi.airer.acn02'; | ||
export * from './lumi.airer.acn02'; | ||
export * from './lumi.airer.acn001'; | ||
export * from './virtual.ir.tv'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import { BaseAccessory } from './base'; | ||
|
||
enum Operation { | ||
Lightbulb = '4.21.85', | ||
/** 风干 */ | ||
AirDry = '4.66.85', | ||
/** 烘干 */ | ||
Dry = '4.67.85', | ||
/** 消毒 */ | ||
Disinfection = '4.22.85', | ||
/** 运动控制 */ | ||
Control = '14.1.85', | ||
} | ||
|
||
enum OpenClose { | ||
Close = '0', | ||
Open = '1', | ||
} | ||
|
||
export class LumiAirerAcn001 extends BaseAccessory { | ||
init() { | ||
const { Lightbulb, WindowCovering, Fanv2, Switch } = this.platform.Service; | ||
this.generateServices({ | ||
lightbulb: Lightbulb, | ||
airer: WindowCovering, | ||
fan: { | ||
service: Fanv2, | ||
subName: '风干/烘干', | ||
}, | ||
disinfection: { | ||
service: Switch, | ||
subName: '消毒', | ||
}, | ||
}); | ||
|
||
this.services.lightbulb | ||
.getCharacteristic(this.platform.Characteristic.On) | ||
.onGet(this.getLightbulbOn.bind(this)) | ||
.onSet(this.setLightbulbOn.bind(this)); | ||
|
||
this.services.airer.getCharacteristic(this.platform.Characteristic.CurrentPosition).onGet(() => 50); | ||
|
||
this.services.airer | ||
.getCharacteristic(this.platform.Characteristic.TargetPosition) | ||
.onGet(() => 50) | ||
.onSet((value) => { | ||
this.setResourceValue(Operation.Control, (value as number) > 50 ? '2' : '1'); | ||
}); | ||
|
||
this.services.airer | ||
.getCharacteristic(this.platform.Characteristic.PositionState) | ||
.onGet(() => this.getResourceValue(Operation.Control).then(({ value }) => this.positionStateMap[value])); | ||
|
||
this.services.fan | ||
.getCharacteristic(this.platform.Characteristic.Active) | ||
.onGet(() => | ||
Promise.allSettled([this.getResourceValue(Operation.AirDry), this.getResourceValue(Operation.Dry)]).then( | ||
([airDry, dry]) => { | ||
return ( | ||
(airDry.status === 'fulfilled' && airDry.value.value === OpenClose.Open) || | ||
(dry.status === 'fulfilled' && dry.value.value === OpenClose.Open) | ||
); | ||
}, | ||
), | ||
) | ||
.onSet((value) => { | ||
if (value) { | ||
this.setResourceValue(Operation.AirDry, OpenClose.Open); | ||
} else { | ||
Promise.allSettled([ | ||
this.setResourceValue(Operation.AirDry, OpenClose.Close), | ||
this.setResourceValue(Operation.Dry, OpenClose.Close), | ||
]); | ||
} | ||
}); | ||
|
||
this.services.disinfection | ||
.getCharacteristic(this.platform.Characteristic.On) | ||
.onGet(() => this.getResourceValue(Operation.Disinfection).then(({ value }) => value === OpenClose.Open)) | ||
.onSet((value) => { | ||
this.setResourceValue(Operation.Disinfection, value ? OpenClose.Open : OpenClose.Close); | ||
}); | ||
} | ||
|
||
async getLightbulbOn() { | ||
return this.getResourceValue(Operation.Lightbulb).then(({ value }) => value === OpenClose.Open); | ||
} | ||
|
||
async setLightbulbOn(value) { | ||
this.setResourceValue(Operation.Lightbulb, value ? OpenClose.Open : OpenClose.Close); | ||
} | ||
|
||
private positionStateMap = { | ||
'1': this.platform.Characteristic.PositionState.DECREASING, | ||
'2': this.platform.Characteristic.PositionState.INCREASING, | ||
'0': this.platform.Characteristic.PositionState.STOPPED, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import { BaseAccessory } from './base'; | ||
|
||
export class VirtualIrTv extends BaseAccessory { | ||
get did() { | ||
return this.accessory.context.deviceInfo.did; | ||
} | ||
|
||
info?: Aqara.QueryIrInfoResponse; | ||
|
||
keys: Aqara.QueryIrKeysResponse['keys'] = []; | ||
|
||
get keyMap() { | ||
const keyMap = new Map<string, Aqara.QueryIrKeysResponse['keys'][number]>(); | ||
this.keys.forEach((key) => { | ||
keyMap.set(key.keyName, key); | ||
}); | ||
return keyMap; | ||
} | ||
|
||
async init() { | ||
const { Characteristic, Service } = this.platform; | ||
|
||
await Promise.allSettled([ | ||
this.platform.aqaraApi.queryIrInfo(this.did), | ||
this.platform.aqaraApi.queryIrKeys(this.did), | ||
]).then(([info, keys]) => { | ||
if (info.status === 'fulfilled') { | ||
this.accessory | ||
.getService(Service.AccessoryInformation)! | ||
.setCharacteristic(Characteristic.Manufacturer, info.value.brandName); | ||
this.info = info.value; | ||
} | ||
if (keys.status === 'fulfilled') { | ||
this.keys = keys.value.keys; | ||
} | ||
}); | ||
|
||
this.generateServices({ | ||
tv: Service.Television, | ||
}); | ||
|
||
this.services.tv.getCharacteristic(Characteristic.Active).onSet(this.setActive.bind(this)); | ||
|
||
this.services.tv.getCharacteristic(Characteristic.RemoteKey).onSet(this.setRemoteKey.bind(this)); | ||
} | ||
|
||
setActive() { | ||
this.writeIrClick('POWER'); | ||
} | ||
|
||
setRemoteKey(value) { | ||
const { RemoteKey } = this.platform.Characteristic; | ||
const keyMap = { | ||
[RemoteKey.REWIND]: 'REWIND', | ||
[RemoteKey.FAST_FORWARD]: 'FAST_FORWARD', | ||
[RemoteKey.NEXT_TRACK]: 'NEXT', | ||
[RemoteKey.PREVIOUS_TRACK]: 'PREVIOUS', | ||
[RemoteKey.ARROW_UP]: 'NAVIGATE_UP', | ||
[RemoteKey.ARROW_DOWN]: 'NAVIGATE_DOWN', | ||
[RemoteKey.ARROW_LEFT]: 'NAVIGATE_LEFT', | ||
[RemoteKey.ARROW_RIGHT]: 'NAVIGATE_RIGHT', | ||
[RemoteKey.SELECT]: 'OK', | ||
[RemoteKey.BACK]: 'BACK', | ||
[RemoteKey.EXIT]: 'BACK', | ||
[RemoteKey.PLAY_PAUSE]: 'PAUSE', | ||
[RemoteKey.INFORMATION]: 'DISPLAY', | ||
}; | ||
const keyName = keyMap[value]; | ||
if (keyName) { | ||
this.writeIrClick(keyName); | ||
} | ||
} | ||
|
||
private writeIrClick(keyName: string) { | ||
const keyInfo = this.keyMap.get(keyName); | ||
if (!keyInfo) { | ||
this.platform.log.error(`Key ${keyName} not found`); | ||
return; | ||
} | ||
const { controllerId, keyId } = keyInfo; | ||
const { did, brandId } = this.info!; | ||
return this.platform.aqaraApi.request('write.ir.click', { | ||
did, | ||
brandId, | ||
controllerId, | ||
keyId, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.