Skip to content

Commit

Permalink
feat: control idle state to set min temperature
Browse files Browse the repository at this point in the history
  • Loading branch information
kyle-seongwoo-jun committed Feb 21, 2024
1 parent 7d08393 commit d752249
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 33 deletions.
16 changes: 8 additions & 8 deletions src/homebridge/electric-mat.device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ export default class ElectricMat {
.onGet(this.getTemperature.bind(this));

// target temperature
const { heat } = device.functions;
const { heatRange } = device.functions;
heater.getCharacteristic(HeatingThresholdTemperature)
.setProps({
minValue: heat.min,
maxValue: heat.max,
minStep: heat.step,
minValue: heatRange.min,
maxValue: heatRange.max,
minStep: heatRange.step,
})
.onGet(this.getTemperature.bind(this))
.onSet(this.setTemperature.bind(this));
Expand Down Expand Up @@ -164,12 +164,12 @@ export default class ElectricMat {
.onSet(this.setHeatingState.bind(this));

// target temperature
const { heat } = device.functions;
const { heatRange } = device.functions;
thermostat.getCharacteristic(TargetTemperature)
.setProps({
minValue: heat.min,
maxValue: heat.max,
minStep: heat.step,
minValue: heatRange.min,
maxValue: heatRange.max,
minStep: heatRange.step,
})
.onGet(this.getTemperature.bind(this))
.onSet(this.setTemperature.bind(this));
Expand Down
28 changes: 8 additions & 20 deletions src/navien/navien.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,38 +158,26 @@ export class NavienApi {
});
}

public setTemperature(device: Device, temperature: number) {
const {
Properties: {
registry: {
attributes: {
functions: {
heatControl,
},
},
},
},
} = device;

public setTemperature(device: Device, temperature: number, range: { min: number; max: number; step: number }) {
// validate temperature
const { rangeMin, rangeMax, unit } = heatControl;
if (temperature < rangeMin || temperature > rangeMax) {
throw new Error(`Temperature must be between ${rangeMin} and ${rangeMax}. current: ${temperature}`);
const { min, max, step } = range;
if (temperature < min || temperature > max) {
throw new Error(`Temperature must be between ${min} and ${max}. current: ${temperature}`);
}
if (temperature % parseFloat(unit) !== 0) {
throw new Error(`Temperature must be multiple of ${unit}. current: ${temperature}`);
if (temperature % step !== 0) {
throw new Error(`Temperature must be multiple of ${step}. current: ${temperature}`);
}

return this.controlDevice(device, {
heater: {
left: {
enable: true,
enable: temperature > min,
temperature: {
set: temperature,
},
},
right: {
enable: true,
enable: temperature > min,
temperature: {
set: temperature,
},
Expand Down
10 changes: 5 additions & 5 deletions src/navien/navien.device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ export class NavienDevice {
const { heatControl } = functions;

const step = parseFloat(heatControl.unit);
const heat = {
const heatRange = {
min: heatControl.rangeMin - step,
max: heatControl.rangeMax,
step: step,
};

return {
heat,
heatRange,
};
}

Expand All @@ -81,8 +81,8 @@ export class NavienDevice {
}

get isIdle() {
const { heat } = this.functions;
return this._power && this._temperature === heat.min;
const { heatRange } = this.functions;
return this._power && this._temperature === heatRange.min;
}

get temperature() {
Expand Down Expand Up @@ -114,7 +114,7 @@ export class NavienDevice {
}

setTemperature(temperature: number) {
return this.api.setTemperature(this.json, temperature);
return this.api.setTemperature(this.json, temperature, this.functions.heatRange);
}

dispose() {
Expand Down

0 comments on commit d752249

Please sign in to comment.