generated from homebridge/homebridge-plugin-template
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from baranwang/feat/hot-water
feat: 新增热水器类型设备支持
- Loading branch information
Showing
8 changed files
with
1,058 additions
and
1,253 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
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
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,95 @@ | ||
import { CharacteristicProps, CharacteristicValue } from 'homebridge'; | ||
import { BaseAccessory } from './base'; | ||
|
||
export class HotWaterAccessory extends BaseAccessory { | ||
constructor(platform, accessory) { | ||
super(platform, accessory); | ||
this.init(); | ||
} | ||
|
||
async init() { | ||
this.generateServices([this.platform.Service.Thermostat]); | ||
|
||
await this.getDevDigitalModel(); | ||
|
||
//#region Thermostat | ||
this.services[0] | ||
.getCharacteristic(this.Characteristic.CurrentHeatingCoolingState) | ||
.onGet(this.getCurrentHeatingCoolingState.bind(this)); | ||
|
||
this.services[0] | ||
.getCharacteristic(this.Characteristic.TargetHeatingCoolingState) | ||
.onGet(this.getCurrentHeatingCoolingState.bind(this)) // 与 CurrentHeatingCoolingState 保持一致 | ||
.onSet(this.setTargetHeatingCoolingState.bind(this)) | ||
.setProps({ | ||
validValues: [ | ||
this.Characteristic.TargetHeatingCoolingState.OFF, | ||
this.Characteristic.TargetHeatingCoolingState.HEAT, | ||
], | ||
}); | ||
|
||
this.services[0] | ||
.getCharacteristic(this.Characteristic.CurrentTemperature) | ||
.onGet(this.getTargetTemperature.bind(this)); // 与 TargetTemperature 保持一致 | ||
|
||
this.services[0] | ||
.getCharacteristic(this.Characteristic.TargetTemperature) | ||
.onGet(this.getTargetTemperature.bind(this)) | ||
.onSet(this.setTargetTemperature.bind(this)) | ||
.setProps(this.targetTemperatureProps); | ||
|
||
this.services[0] | ||
.getCharacteristic(this.Characteristic.TemperatureDisplayUnits) | ||
.onGet(() => this.Characteristic.TemperatureDisplayUnits.CELSIUS); | ||
//#endregion | ||
} | ||
|
||
private get onOffStatus() { | ||
const onOffStatus: boolean = JSON.parse(this.devDigitalModelPropertiesMap.onOffStatus.value); | ||
return onOffStatus; | ||
} | ||
|
||
private get targetTemperature() { | ||
return this.devDigitalModelPropertiesMap.targetTemp.value; | ||
} | ||
|
||
private set targetTemperature(value: string) { | ||
this.devDigitalModelPropertiesMap.targetTemp.value = value; | ||
} | ||
|
||
private get targetTemperatureProps() { | ||
const { dataStep } = this.devDigitalModelPropertiesMap.targetTemp.valueRange; | ||
const minValue = Number(dataStep.minValue); | ||
const maxValue = Number(dataStep.maxValue); | ||
const minStep = Number(dataStep.step); | ||
return { | ||
minValue, | ||
maxValue, | ||
minStep, | ||
validValueRanges: [minValue, maxValue] as CharacteristicProps['validValueRanges'], | ||
}; | ||
} | ||
|
||
getCurrentHeatingCoolingState() { | ||
return this.onOffStatus | ||
? this.Characteristic.CurrentHeatingCoolingState.HEAT | ||
: this.Characteristic.CurrentHeatingCoolingState.OFF; | ||
} | ||
|
||
async setTargetHeatingCoolingState(value: CharacteristicValue) { | ||
await this.sendCommands({ onOffStatus: (!!value).toString() }); | ||
} | ||
|
||
getTargetTemperature() { | ||
return Number(this.targetTemperature); | ||
} | ||
|
||
async setTargetTemperature(value: CharacteristicValue) { | ||
const { minValue, maxValue } = this.targetTemperatureProps; | ||
const targetTemp = Math.min(Math.max(value as number, minValue), maxValue).toString(); | ||
try { | ||
await this.sendCommands({ targetTemp }); | ||
this.targetTemperature = targetTemp; | ||
} catch (error) {} | ||
} | ||
} |
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,2 @@ | ||
export * from './air-conditioner'; | ||
export * from './hot-water'; |
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