[matter] Prevent Thermostat bridge failures (#21064)

Matter.js 0.17 implemented strict data validate for thermostats that we
could violate, preventing them from being added to the bridge.

Signed-off-by: Dan Cunningham <dan@digitaldan.com>
This commit is contained in:
Dan Cunningham
2026-06-26 22:53:09 +02:00
committed by GitHub
parent a94c69fd36
commit 82f0c988e6
2 changed files with 20 additions and 7 deletions
@@ -6,7 +6,7 @@ import { DeviceFunctions } from "../DeviceFunctions";
export class CustomThermostatServer extends ThermostatServer { export class CustomThermostatServer extends ThermostatServer {
static readonly DEFAULTS_COMMON = { static readonly DEFAULTS_COMMON = {
systemMode: 0, systemMode: 0,
localTemperature: 0, localTemperature: 0,
} as const; } as const;
static readonly DEFAULTS_COOL = { static readonly DEFAULTS_COOL = {
@@ -27,9 +27,6 @@ export class CustomThermostatServer extends ThermostatServer {
minSetpointDeadBand: 0, minSetpointDeadBand: 0,
} as const; } as const;
static readonly DEFAULTS = {
} as const;
static selectFeatures(values: any): Thermostat.Feature[] { static selectFeatures(values: any): Thermostat.Feature[] {
const feats: Thermostat.Feature[] = []; const feats: Thermostat.Feature[] = [];
let controlSeq = -1; let controlSeq = -1;
@@ -18,9 +18,25 @@ export class ThermostatDeviceType extends BaseDeviceType {
} }
override defaultClusterValues(userValues: Record<string, any>) { override defaultClusterValues(userValues: Record<string, any>) {
const defaults: Record<string, any> = { const thermostat = userValues.thermostat ?? {};
thermostat: CustomThermostatServer.DEFAULTS, const hasHeating = thermostat.occupiedHeatingSetpoint !== undefined;
const hasCooling = thermostat.occupiedCoolingSetpoint !== undefined;
const thermostatDefaults: Record<string, any> = {
...CustomThermostatServer.DEFAULTS_COMMON,
};
if (hasHeating) {
Object.assign(thermostatDefaults, CustomThermostatServer.DEFAULTS_HEAT);
}
if (hasCooling) {
Object.assign(thermostatDefaults, CustomThermostatServer.DEFAULTS_COOL);
}
if (hasHeating && hasCooling) {
Object.assign(thermostatDefaults, CustomThermostatServer.DEFAULTS_AUTO);
}
return {
thermostat: thermostatDefaults,
}; };
return defaults;
} }
} }