Skip to content

Commit f8f2178

Browse files
committed
Add ThermostatModeProperty
1 parent 5878e48 commit f8f2178

File tree

2 files changed

+81
-1
lines changed

2 files changed

+81
-1
lines changed

src/zigbee2mqtt/zigbee2mqtt-device.ts

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
parseType,
2121
isReadable,
2222
parseUnit,
23+
HeatingCoolingProperty,
2324
} from './zigbee2mqtt-property';
2425
import mqtt from 'mqtt';
2526
import DEBUG_FLAG from '../zb-debug';
@@ -254,7 +255,44 @@ export class Zigbee2MqttDevice extends Device {
254255

255256
for (const feature of expose.features) {
256257
if (feature.name) {
257-
this.createProperty(feature);
258+
switch (feature.name) {
259+
case 'system_mode': {
260+
console.log(`Creating property for ${feature.name}`);
261+
262+
const property = new Zigbee2MqttProperty<string>(
263+
this,
264+
feature.name,
265+
feature,
266+
this.client,
267+
this.deviceTopic,
268+
{
269+
'@type': 'ThermostatModeProperty',
270+
type: 'string',
271+
}
272+
);
273+
274+
this.addProperty(property);
275+
break;
276+
}
277+
case 'running_state':
278+
{
279+
console.log(`Creating property for ${feature.name}`);
280+
281+
const property = new HeatingCoolingProperty(
282+
this,
283+
feature.name,
284+
feature,
285+
this.client,
286+
this.deviceTopic
287+
);
288+
289+
this.addProperty(property);
290+
}
291+
break;
292+
default:
293+
this.createProperty(feature);
294+
break;
295+
}
258296
} else {
259297
console.log(`Ignoring property without name: ${JSON.stringify(expose, null, 0)}`);
260298
}

src/zigbee2mqtt/zigbee2mqtt-property.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,3 +333,45 @@ function xyBriToRgb(x: number, y: number, bri: number): RGB {
333333
function limit(value: number, min: number, max: number): number {
334334
return Math.max(Math.min(value, max), min);
335335
}
336+
337+
function convertHeatingCoolingValues(value?: string[]): string[] | undefined {
338+
if (value) {
339+
return value.map((x) => convertHeatingCoolingValue(x));
340+
}
341+
342+
return value;
343+
}
344+
345+
function convertHeatingCoolingValue(value: string): string {
346+
switch (value) {
347+
case 'idle':
348+
return 'off';
349+
case 'heat':
350+
return 'heating';
351+
case 'cool':
352+
return 'cooling';
353+
default:
354+
throw new Error(`Invalid HeatingCoolingValue ${value}, expected idle, heat or cool`);
355+
}
356+
}
357+
358+
export class HeatingCoolingProperty extends Zigbee2MqttProperty<string> {
359+
constructor(
360+
device: Zigbee2MqttDevice,
361+
name: string,
362+
expose: Expos,
363+
client: mqtt.Client,
364+
deviceTopic: string
365+
) {
366+
super(device, name, expose, client, deviceTopic, {
367+
'@type': 'HeatingCoolingProperty',
368+
title: 'Run Mode',
369+
type: 'string',
370+
enum: convertHeatingCoolingValues(expose.values),
371+
});
372+
}
373+
374+
update(value: string): void {
375+
this.setCachedValueAndNotify(convertHeatingCoolingValue(value));
376+
}
377+
}

0 commit comments

Comments
 (0)