Skip to content

Commit

Permalink
fix(hot-water): fix check if hot water is heating
Browse files Browse the repository at this point in the history
  • Loading branch information
hpruszyn committed Oct 21, 2024
1 parent 89ea55a commit 7495f2b
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 33 deletions.
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,6 @@ However, you can also make changes directly in the Homebridge config.json file.
<td></td>
<td>If set to `true` response from Nibe myUplink API will be displayed in logs.</td>
</tr>
<tr>
<td>hotwaterHeatingTemp</td>
<td>No</td>
<td>40</td>
<td>Min heating temperature for hot water. Used to determine if hot water is active.</td>
</tr>
</tbody>
</table>

Expand Down
10 changes: 1 addition & 9 deletions config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,6 @@
"showApiResponse": {
"title": "Show Nibe MyUplink API response",
"type": "boolean"
},
"hotwaterHeatingTemp": {
"title": "Min heating temperature for hot water",
"type": "integer",
"minimum": 30,
"maximum": 70,
"placeholder": 40
}
}
},
Expand Down Expand Up @@ -107,8 +100,7 @@
"expanded": false,
"items": [
"showApiResponse",
"pollingPeriod",
"hotwaterHeatingTemp"
"pollingPeriod"
]
}
]
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "homebridge-nibe",
"displayName": "Homebridge Nibe",
"version": "2.1.1",
"version": "2.1.2",
"description": "Homebridge plugin for Nibe services",
"author": "Hubert Pruszynski <[email protected]>",
"license": "MIT",
Expand Down
15 changes: 15 additions & 0 deletions src/platform/AccessoryDomain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export interface AccessoryContext {
systemName: string
deviceId: string
deviceName: string
data: string[]
}

export abstract class AccessoryDefinition {
Expand Down Expand Up @@ -148,4 +149,18 @@ export abstract class AccessoryDefinition {
protected isManageEnabled(data: Data): boolean {
return data.system.premiumSubscriptions?.includes('manage') || false;
}

protected putData(platformAccessory: AccessoryInstance, key: string, data: any): void {
if (!platformAccessory.context.data) {
platformAccessory.context.data = [];
}
platformAccessory.context.data[key] = data;
}

protected getData(platformAccessory: AccessoryInstance, key: string): any | undefined {
if (!platformAccessory.context.data) {
return undefined;
}
return platformAccessory.context.data[key];
}
}
8 changes: 1 addition & 7 deletions src/platform/NibePlatform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,7 @@ export class NibePlatform implements DynamicPlatformPlugin {
new TemperatureSensorAccessory('40075', 'ventilation-supply-air-40075', 1, this.locale, this.serviceResolver, this.log),
new TemperatureSensorAccessory('40183', 'ventilation-outdoor-40183', 1, this.locale, this.serviceResolver, this.log),
new TemperatureSensorAccessory('40013', 'hot-water-top-40013', 1, this.locale, this.serviceResolver, this.log),
new HotWaterAccessory(
'hot-water',
3,
this.locale,
this.serviceResolver,
this.log,
{ hotWaterHeatingTemp: config.hotwaterHeatingTemp || 40 },
new HotWaterAccessory('hot-water', 3, this.locale, this.serviceResolver, this.log,
async (deviceId: string, paramId: string, value: any) => {
return await this.dataFetcher.setValue(deviceId, paramId, value);
},
Expand Down
18 changes: 9 additions & 9 deletions src/platform/nibeaccessory/HotWaterAccessory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export class HotWaterAccessory extends AccessoryDefinition {
protected readonly locale: Locale,
protected readonly serviceResolver: ServiceResolver,
protected readonly log: Logger,
protected readonly config: { hotWaterHeatingTemp: number },
protected readonly setValue: (deviceId: string, paramId: string, value: any) => Promise<void>,
) {
super(name, version, locale, serviceResolver, log);
Expand Down Expand Up @@ -87,23 +86,24 @@ export class HotWaterAccessory extends AccessoryDefinition {

updateThermostat(platformAccessory: AccessoryInstance, data: Data) {
const service = this.getOrCreateService('Thermostat', platformAccessory);
const pCurrentTemperature = this.findParameter('40014', data);
const pHeatPompParam = this.findParameter('43437', data);
const pTemperatureParam = this.findParameter('40008', data);
const previousValue = this.getCharacteristicValue(service, 'CurrentHeatingCoolingState');
const isHeating = this.isHeating(pHeatPompParam, pTemperatureParam, previousValue);
const previousCurrentTemperature = this.getData(platformAccessory, 'previousCurrentTemperature');
const isHeating = this.isHeating(pHeatPompParam, pTemperatureParam, pCurrentTemperature, previousCurrentTemperature);
this.updateCharacteristic(service, 'CurrentHeatingCoolingState', isHeating ? 1 : 0, CURRENT_HEATING_STATE_PROPS);
this.updateCharacteristic(service, 'TargetHeatingCoolingState', 3, TARGET_HEATING_COOLING_STATE_PROPS);

const pCurrentTemperature = this.findParameter('40014', data);
this.updateCharacteristic(service, 'TargetHeatingCoolingState', 3, TARGET_HEATING_COOLING_STATE_PROPS);
if (pCurrentTemperature) {
this.updateCharacteristic(service, 'CurrentTemperature', pCurrentTemperature.value);
this.updateCharacteristic(service, 'TemperatureDisplayUnits', this.toTemperatureUnit(pCurrentTemperature.unit), RO_PROPS);
this.putData(platformAccessory, 'previousCurrentTemperature', pCurrentTemperature.value);
}

const hotWaterTemp = this.maxValue(this.findParameters([ '40008', '40014' ], data));
this.updateCharacteristic(service, 'TargetTemperature', hotWaterTemp, TARGET_TEMPERATURE_PROPS);

this.updateCharacteristic(service, 'HeatingThresholdTemperature', this.config.hotWaterHeatingTemp, HEATING_THRESHOLD_TEMPERATURE_PROPS);
this.updateCharacteristic(service, 'HeatingThresholdTemperature', pTemperatureParam?.value || 0, HEATING_THRESHOLD_TEMPERATURE_PROPS);
}

isTempLuxActive(value): boolean {
Expand All @@ -124,16 +124,16 @@ export class HotWaterAccessory extends AccessoryDefinition {
return max;
}

isHeating(heatPompParam, temperatureParam, previousValue) {
isHeating(heatPompParam, temperatureParam, currentTemperature, previousCurrentTemperature) {
if (!heatPompParam || heatPompParam.rawValue <= 0) {
return false; // OFF
}

if (temperatureParam && temperatureParam.value) {
if (temperatureParam.value > this.config.hotWaterHeatingTemp) {
if (temperatureParam.value > currentTemperature.value) {
return true; // HEATING
}
if (previousValue < temperatureParam.value) {
if (previousCurrentTemperature < currentTemperature.value) {
return true; // HEATING
}
}
Expand Down
1 change: 0 additions & 1 deletion tests/HotWaterAccessory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ describe('Test HotWaterAccessory', () => {
new Locale('en', testLogger),
serviceResolver,
testLogger,
{ hotWaterHeatingTemp: 40 },
async (deviceId: string, paramId: string, value: any) => {
return Promise.resolve();
},
Expand Down

0 comments on commit 7495f2b

Please sign in to comment.