Skip to content

Commit

Permalink
feat(hot-water): 新增浴缸注水开关
Browse files Browse the repository at this point in the history
  • Loading branch information
baranwang authored May 6, 2024
2 parents 4f5036f + de553c4 commit 6e4b2fd
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@
],
"url": "../node_modules/lerna/schemas/lerna-schema.json"
}
]
],
"i18n-ally.localesPaths": [
"packages/ui-renderer/src/lang"
],
}
8 changes: 4 additions & 4 deletions packages/plugin/src/accessories/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ type GenerateServicesParams =
| typeof Service
| {
service: typeof Service;
displayName: string;
subName: string;
};

export class BaseAccessory {
Expand All @@ -31,9 +31,9 @@ export class BaseAccessory {
const existingService = this.accessory.getService(key);
if (existingService) {
acc[key] = existingService;
} else if ('displayName' in params) {
const { displayName, service } = params;
acc[key] = this.accessory.addService(service, displayName, key);
} else if ('subName' in params) {
const { subName, service } = params;
acc[key] = this.accessory.addService(service, `${this.accessory.displayName} - ${subName}`, key);
} else {
acc[key] = this.accessory.addService(params, this.accessory.displayName, key);
}
Expand Down
28 changes: 28 additions & 0 deletions packages/plugin/src/accessories/hot-water.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ export class HotWaterAccessory extends BaseAccessory {
CurrentTemperature,
TargetTemperature,
TemperatureDisplayUnits,
Active,
InUse,
ValveType,
Name,
} = this.Characteristic;

//#region Thermostat
Expand All @@ -41,6 +45,30 @@ export class HotWaterAccessory extends BaseAccessory {

this.services.thermostat.getCharacteristic(TemperatureDisplayUnits).onGet(() => TemperatureDisplayUnits.CELSIUS);
//#endregion

if (this.devProps.tankWateringStatus) {
this.generateServices({
valve: {
service: this.platform.Service.Valve,
subName: '浴缸注水',
},
});

this.services.valve
.getCharacteristic(Active)
.onGet(() => (this.devProps.tankWateringStatus === 'true' ? Active.ACTIVE : Active.INACTIVE))
.onSet(value => {
this.devProps.tankWateringStatus = (!!value).toString();
});

this.services.valve
.getCharacteristic(InUse)
.onGet(() => (this.devProps.tankWaterLevel === 'false' ? InUse.NOT_IN_USE : InUse.IN_USE));

this.services.valve.getCharacteristic(ValveType).onGet(() => ValveType.WATER_FAUCET);

this.services.valve.getCharacteristic(Name).onGet(() => '浴缸注水');
}
}

private get targetTemperatureProps() {
Expand Down

0 comments on commit 6e4b2fd

Please sign in to comment.