@riddix/hamh 2.1.0-alpha.450 → 2.1.0-alpha.452
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/backend/cli.js
CHANGED
|
@@ -165874,10 +165874,254 @@ function transactionIsOffline(context) {
|
|
|
165874
165874
|
|
|
165875
165875
|
// src/matter/behaviors/fan-control-server.ts
|
|
165876
165876
|
init_home_assistant_entity_behavior();
|
|
165877
|
+
|
|
165878
|
+
// src/matter/behaviors/on-off-server.ts
|
|
165879
|
+
init_esm();
|
|
165880
|
+
init_home_assistant_entity_behavior();
|
|
165881
|
+
|
|
165882
|
+
// src/matter/behaviors/level-control-server.ts
|
|
165883
|
+
init_esm();
|
|
165884
|
+
init_home_assistant_entity_behavior();
|
|
165885
|
+
var lastTurnOnTimestamps = /* @__PURE__ */ new Map();
|
|
165886
|
+
var optimisticLevelState = /* @__PURE__ */ new Map();
|
|
165887
|
+
var OPTIMISTIC_TIMEOUT_MS = 3e3;
|
|
165888
|
+
var OPTIMISTIC_TOLERANCE = 5;
|
|
165889
|
+
function notifyLightTurnedOn(entityId) {
|
|
165890
|
+
lastTurnOnTimestamps.set(entityId, Date.now());
|
|
165891
|
+
}
|
|
165892
|
+
var logger158 = Logger.get("LevelControlServer");
|
|
165893
|
+
var FeaturedBase3 = LevelControlServer.with("OnOff", "Lighting");
|
|
165894
|
+
var LevelControlServerBase = class extends FeaturedBase3 {
|
|
165895
|
+
pendingTransitionTime;
|
|
165896
|
+
async initialize() {
|
|
165897
|
+
if (this.state.currentLevel == null) {
|
|
165898
|
+
this.state.currentLevel = 1;
|
|
165899
|
+
}
|
|
165900
|
+
if (this.state.minLevel == null) {
|
|
165901
|
+
this.state.minLevel = 1;
|
|
165902
|
+
}
|
|
165903
|
+
if (this.state.maxLevel == null) {
|
|
165904
|
+
this.state.maxLevel = 254;
|
|
165905
|
+
}
|
|
165906
|
+
this.state.onLevel = null;
|
|
165907
|
+
logger158.debug(`initialize: calling super.initialize()`);
|
|
165908
|
+
try {
|
|
165909
|
+
await super.initialize();
|
|
165910
|
+
logger158.debug(`initialize: super.initialize() completed successfully`);
|
|
165911
|
+
} catch (error) {
|
|
165912
|
+
logger158.error(`initialize: super.initialize() FAILED:`, error);
|
|
165913
|
+
throw error;
|
|
165914
|
+
}
|
|
165915
|
+
const homeAssistant = await this.agent.load(HomeAssistantEntityBehavior);
|
|
165916
|
+
this.update(homeAssistant.entity);
|
|
165917
|
+
this.reactTo(homeAssistant.onChange, this.update);
|
|
165918
|
+
}
|
|
165919
|
+
update(entity) {
|
|
165920
|
+
if (!entity.state) {
|
|
165921
|
+
return;
|
|
165922
|
+
}
|
|
165923
|
+
const { state } = entity;
|
|
165924
|
+
const config10 = this.state.config;
|
|
165925
|
+
const minLevel = 1;
|
|
165926
|
+
const maxLevel = 254;
|
|
165927
|
+
const levelRange = maxLevel - minLevel;
|
|
165928
|
+
const currentLevelPercent = config10.getValuePercent(state, this.agent);
|
|
165929
|
+
let currentLevel = currentLevelPercent != null ? Math.round(currentLevelPercent * levelRange + minLevel) : null;
|
|
165930
|
+
if (currentLevel != null) {
|
|
165931
|
+
currentLevel = Math.min(Math.max(minLevel, currentLevel), maxLevel);
|
|
165932
|
+
}
|
|
165933
|
+
const optimistic = optimisticLevelState.get(entity.entity_id);
|
|
165934
|
+
if (optimistic != null && currentLevel != null) {
|
|
165935
|
+
if (Date.now() - optimistic.timestamp > OPTIMISTIC_TIMEOUT_MS) {
|
|
165936
|
+
optimisticLevelState.delete(entity.entity_id);
|
|
165937
|
+
} else if (Math.abs(currentLevel - optimistic.expectedLevel) <= OPTIMISTIC_TOLERANCE) {
|
|
165938
|
+
optimisticLevelState.delete(entity.entity_id);
|
|
165939
|
+
} else {
|
|
165940
|
+
currentLevel = null;
|
|
165941
|
+
}
|
|
165942
|
+
}
|
|
165943
|
+
applyPatchState(this.state, {
|
|
165944
|
+
minLevel,
|
|
165945
|
+
maxLevel,
|
|
165946
|
+
...currentLevel != null ? { currentLevel } : {}
|
|
165947
|
+
});
|
|
165948
|
+
}
|
|
165949
|
+
// Fix for Google Home (#41): it sends moveToLevel/moveToLevelWithOnOff/step commands
|
|
165950
|
+
// with transitionTime as null or completely omitted. The TLV schema is patched at startup
|
|
165951
|
+
// (see patch-level-control-tlv.ts) to accept omitted fields. Here we default to 0 (instant).
|
|
165952
|
+
async moveToLevel(request) {
|
|
165953
|
+
if (request.transitionTime == null) {
|
|
165954
|
+
request.transitionTime = 0;
|
|
165955
|
+
}
|
|
165956
|
+
this.pendingTransitionTime = request.transitionTime;
|
|
165957
|
+
return super.moveToLevel(request);
|
|
165958
|
+
}
|
|
165959
|
+
async moveToLevelWithOnOff(request) {
|
|
165960
|
+
if (request.transitionTime == null) {
|
|
165961
|
+
request.transitionTime = 0;
|
|
165962
|
+
}
|
|
165963
|
+
this.pendingTransitionTime = request.transitionTime;
|
|
165964
|
+
return super.moveToLevelWithOnOff(request);
|
|
165965
|
+
}
|
|
165966
|
+
step(request) {
|
|
165967
|
+
if (request.transitionTime == null) {
|
|
165968
|
+
request.transitionTime = 0;
|
|
165969
|
+
}
|
|
165970
|
+
return super.step(request);
|
|
165971
|
+
}
|
|
165972
|
+
stepWithOnOff(request) {
|
|
165973
|
+
if (request.transitionTime == null) {
|
|
165974
|
+
request.transitionTime = 0;
|
|
165975
|
+
}
|
|
165976
|
+
return super.stepWithOnOff(request);
|
|
165977
|
+
}
|
|
165978
|
+
moveToLevelLogic(level) {
|
|
165979
|
+
const homeAssistant = this.agent.get(HomeAssistantEntityBehavior);
|
|
165980
|
+
const config10 = this.state.config;
|
|
165981
|
+
const entityId = homeAssistant.entity.entity_id;
|
|
165982
|
+
const levelRange = this.maxLevel - this.minLevel;
|
|
165983
|
+
const levelPercent = (level - this.minLevel) / levelRange;
|
|
165984
|
+
const lastTurnOn = lastTurnOnTimestamps.get(entityId);
|
|
165985
|
+
const timeSinceTurnOn = lastTurnOn ? Date.now() - lastTurnOn : Infinity;
|
|
165986
|
+
const isMaxBrightness = level >= this.maxLevel;
|
|
165987
|
+
if (isMaxBrightness && timeSinceTurnOn < 200) {
|
|
165988
|
+
logger158.debug(
|
|
165989
|
+
`[${entityId}] Ignoring moveToLevel(${level}) - Alexa brightness reset detected (${timeSinceTurnOn}ms after turn-on)`
|
|
165990
|
+
);
|
|
165991
|
+
return;
|
|
165992
|
+
}
|
|
165993
|
+
const current = config10.getValuePercent(
|
|
165994
|
+
homeAssistant.entity.state,
|
|
165995
|
+
this.agent
|
|
165996
|
+
);
|
|
165997
|
+
if (levelPercent === current) {
|
|
165998
|
+
return;
|
|
165999
|
+
}
|
|
166000
|
+
const action = config10.moveToLevelPercent(levelPercent, this.agent);
|
|
166001
|
+
const transitionTimeTenths = this.pendingTransitionTime;
|
|
166002
|
+
this.pendingTransitionTime = void 0;
|
|
166003
|
+
if (transitionTimeTenths && transitionTimeTenths > 0) {
|
|
166004
|
+
action.data = {
|
|
166005
|
+
...action.data,
|
|
166006
|
+
transition: transitionTimeTenths / 10
|
|
166007
|
+
};
|
|
166008
|
+
}
|
|
166009
|
+
this.state.currentLevel = level;
|
|
166010
|
+
optimisticLevelState.set(entityId, {
|
|
166011
|
+
expectedLevel: level,
|
|
166012
|
+
timestamp: Date.now()
|
|
166013
|
+
});
|
|
166014
|
+
homeAssistant.callAction(action);
|
|
166015
|
+
}
|
|
166016
|
+
};
|
|
166017
|
+
((LevelControlServerBase2) => {
|
|
166018
|
+
class State extends FeaturedBase3.State {
|
|
166019
|
+
config;
|
|
166020
|
+
}
|
|
166021
|
+
LevelControlServerBase2.State = State;
|
|
166022
|
+
})(LevelControlServerBase || (LevelControlServerBase = {}));
|
|
166023
|
+
function LevelControlServer2(config10) {
|
|
166024
|
+
return LevelControlServerBase.set({
|
|
166025
|
+
options: { executeIfOff: true },
|
|
166026
|
+
config: config10
|
|
166027
|
+
});
|
|
166028
|
+
}
|
|
166029
|
+
|
|
166030
|
+
// src/matter/behaviors/on-off-server.ts
|
|
166031
|
+
var logger159 = Logger.get("OnOffServer");
|
|
166032
|
+
var optimisticOnOffState = /* @__PURE__ */ new Map();
|
|
166033
|
+
var OPTIMISTIC_TIMEOUT_MS2 = 3e3;
|
|
166034
|
+
var OnOffServerBase = class extends OnOffServer {
|
|
166035
|
+
async initialize() {
|
|
166036
|
+
await super.initialize();
|
|
166037
|
+
const homeAssistant = await this.agent.load(HomeAssistantEntityBehavior);
|
|
166038
|
+
this.update(homeAssistant.entity);
|
|
166039
|
+
this.reactTo(homeAssistant.onChange, this.update);
|
|
166040
|
+
}
|
|
166041
|
+
update({ state }) {
|
|
166042
|
+
const onOff = this.isOn(state);
|
|
166043
|
+
const entityId = this.agent.get(HomeAssistantEntityBehavior).entity.entity_id;
|
|
166044
|
+
const optimistic = optimisticOnOffState.get(entityId);
|
|
166045
|
+
if (optimistic != null) {
|
|
166046
|
+
if (Date.now() - optimistic.timestamp > OPTIMISTIC_TIMEOUT_MS2) {
|
|
166047
|
+
optimisticOnOffState.delete(entityId);
|
|
166048
|
+
} else if (onOff === optimistic.expectedOnOff) {
|
|
166049
|
+
optimisticOnOffState.delete(entityId);
|
|
166050
|
+
} else {
|
|
166051
|
+
return;
|
|
166052
|
+
}
|
|
166053
|
+
}
|
|
166054
|
+
applyPatchState(this.state, { onOff });
|
|
166055
|
+
}
|
|
166056
|
+
isOn(entity) {
|
|
166057
|
+
return this.state.config?.isOn?.(entity, this.agent) ?? (this.agent.get(HomeAssistantEntityBehavior).isAvailable && entity.state !== "off");
|
|
166058
|
+
}
|
|
166059
|
+
on() {
|
|
166060
|
+
const { turnOn, turnOff } = this.state.config;
|
|
166061
|
+
if (turnOn === null) {
|
|
166062
|
+
setTimeout(this.callback(this.autoReset), 1e3);
|
|
166063
|
+
return;
|
|
166064
|
+
}
|
|
166065
|
+
const homeAssistant = this.agent.get(HomeAssistantEntityBehavior);
|
|
166066
|
+
const action = turnOn?.(void 0, this.agent) ?? {
|
|
166067
|
+
action: "homeassistant.turn_on"
|
|
166068
|
+
};
|
|
166069
|
+
logger159.info(`[${homeAssistant.entityId}] Turning ON -> ${action.action}`);
|
|
166070
|
+
notifyLightTurnedOn(homeAssistant.entityId);
|
|
166071
|
+
applyPatchState(this.state, { onOff: true });
|
|
166072
|
+
optimisticOnOffState.set(homeAssistant.entityId, {
|
|
166073
|
+
expectedOnOff: true,
|
|
166074
|
+
timestamp: Date.now()
|
|
166075
|
+
});
|
|
166076
|
+
homeAssistant.callAction(action);
|
|
166077
|
+
if (turnOff === null) {
|
|
166078
|
+
setTimeout(this.callback(this.autoReset), 1e3);
|
|
166079
|
+
}
|
|
166080
|
+
}
|
|
166081
|
+
off() {
|
|
166082
|
+
const { turnOff } = this.state.config;
|
|
166083
|
+
if (turnOff === null) {
|
|
166084
|
+
setTimeout(this.callback(this.autoReset), 1e3);
|
|
166085
|
+
return;
|
|
166086
|
+
}
|
|
166087
|
+
const homeAssistant = this.agent.get(HomeAssistantEntityBehavior);
|
|
166088
|
+
const action = turnOff?.(void 0, this.agent) ?? {
|
|
166089
|
+
action: "homeassistant.turn_off"
|
|
166090
|
+
};
|
|
166091
|
+
logger159.info(`[${homeAssistant.entityId}] Turning OFF -> ${action.action}`);
|
|
166092
|
+
applyPatchState(this.state, { onOff: false });
|
|
166093
|
+
optimisticOnOffState.set(homeAssistant.entityId, {
|
|
166094
|
+
expectedOnOff: false,
|
|
166095
|
+
timestamp: Date.now()
|
|
166096
|
+
});
|
|
166097
|
+
homeAssistant.callAction(action);
|
|
166098
|
+
}
|
|
166099
|
+
autoReset() {
|
|
166100
|
+
const homeAssistant = this.agent.get(HomeAssistantEntityBehavior);
|
|
166101
|
+
this.update(homeAssistant.entity);
|
|
166102
|
+
}
|
|
166103
|
+
};
|
|
166104
|
+
((OnOffServerBase2) => {
|
|
166105
|
+
class State extends OnOffServer.State {
|
|
166106
|
+
config;
|
|
166107
|
+
}
|
|
166108
|
+
OnOffServerBase2.State = State;
|
|
166109
|
+
})(OnOffServerBase || (OnOffServerBase = {}));
|
|
166110
|
+
function OnOffServer2(config10 = {}) {
|
|
166111
|
+
return OnOffServerBase.set({ config: config10 });
|
|
166112
|
+
}
|
|
166113
|
+
function setOptimisticOnOff(entityId, expectedOnOff) {
|
|
166114
|
+
optimisticOnOffState.set(entityId, {
|
|
166115
|
+
expectedOnOff,
|
|
166116
|
+
timestamp: Date.now()
|
|
166117
|
+
});
|
|
166118
|
+
}
|
|
166119
|
+
|
|
166120
|
+
// src/matter/behaviors/fan-control-server.ts
|
|
165877
166121
|
var defaultStepSize = 33.33;
|
|
165878
166122
|
var minSpeedMax = 3;
|
|
165879
166123
|
var maxSpeedMax = 100;
|
|
165880
|
-
var
|
|
166124
|
+
var FeaturedBase4 = FanControlServer.with(
|
|
165881
166125
|
"Step",
|
|
165882
166126
|
"MultiSpeed",
|
|
165883
166127
|
"AirflowDirection",
|
|
@@ -165891,7 +166135,7 @@ var FeaturedBase3 = FanControlServer.with(
|
|
|
165891
166135
|
rockSupport: { rockUpDown: true },
|
|
165892
166136
|
windSupport: { naturalWind: true, sleepWind: true }
|
|
165893
166137
|
});
|
|
165894
|
-
var FanControlServerBase = class extends
|
|
166138
|
+
var FanControlServerBase = class extends FeaturedBase4 {
|
|
165895
166139
|
async initialize() {
|
|
165896
166140
|
if (this.features.multiSpeed) {
|
|
165897
166141
|
if (this.state.speedMax == null || this.state.speedMax < minSpeedMax) {
|
|
@@ -166024,6 +166268,7 @@ var FanControlServerBase = class extends FeaturedBase3 {
|
|
|
166024
166268
|
if (!homeAssistant.isAvailable) {
|
|
166025
166269
|
return;
|
|
166026
166270
|
}
|
|
166271
|
+
this.syncOnOff(percentSetting !== 0);
|
|
166027
166272
|
if (percentSetting === 0) {
|
|
166028
166273
|
homeAssistant.callAction(this.state.config.turnOff(void 0, this.agent));
|
|
166029
166274
|
} else {
|
|
@@ -166064,6 +166309,7 @@ var FanControlServerBase = class extends FeaturedBase3 {
|
|
|
166064
166309
|
}
|
|
166065
166310
|
const targetFanMode = FanMode.create(fanMode, this.state.fanModeSequence);
|
|
166066
166311
|
if (targetFanMode.mode === FanControl3.FanMode.Auto) {
|
|
166312
|
+
this.syncOnOff(true);
|
|
166067
166313
|
homeAssistant.callAction(
|
|
166068
166314
|
this.state.config.setAutoMode(void 0, this.agent)
|
|
166069
166315
|
);
|
|
@@ -166093,6 +166339,7 @@ var FanControlServerBase = class extends FeaturedBase3 {
|
|
|
166093
166339
|
homeAssistant.entity.state,
|
|
166094
166340
|
this.agent
|
|
166095
166341
|
);
|
|
166342
|
+
this.syncOnOff(percentage !== 0);
|
|
166096
166343
|
if (percentage === 0) {
|
|
166097
166344
|
homeAssistant.callAction(config10.turnOff(void 0, this.agent));
|
|
166098
166345
|
} else if (supportsPercentage) {
|
|
@@ -166177,6 +166424,18 @@ var FanControlServerBase = class extends FeaturedBase3 {
|
|
|
166177
166424
|
homeAssistant.callAction(this.state.config.setWindMode(mode, this.agent));
|
|
166178
166425
|
});
|
|
166179
166426
|
}
|
|
166427
|
+
// Cross-cluster sync: keep OnOff in sync with FanControl per Matter spec
|
|
166428
|
+
// §4.4.6.6.1. matter.js does not implement this automatically.
|
|
166429
|
+
syncOnOff(on) {
|
|
166430
|
+
try {
|
|
166431
|
+
if (!this.agent.has(OnOffBehavior)) return;
|
|
166432
|
+
const onOffState = this.agent.get(OnOffBehavior).state;
|
|
166433
|
+
applyPatchState(onOffState, { onOff: on });
|
|
166434
|
+
const entityId = this.agent.get(HomeAssistantEntityBehavior).entity.entity_id;
|
|
166435
|
+
setOptimisticOnOff(entityId, on);
|
|
166436
|
+
} catch {
|
|
166437
|
+
}
|
|
166438
|
+
}
|
|
166180
166439
|
mapWindModeToSetting(mode) {
|
|
166181
166440
|
return {
|
|
166182
166441
|
naturalWind: mode === "natural",
|
|
@@ -166185,7 +166444,7 @@ var FanControlServerBase = class extends FeaturedBase3 {
|
|
|
166185
166444
|
}
|
|
166186
166445
|
};
|
|
166187
166446
|
((FanControlServerBase2) => {
|
|
166188
|
-
class State extends
|
|
166447
|
+
class State extends FeaturedBase4.State {
|
|
166189
166448
|
config;
|
|
166190
166449
|
}
|
|
166191
166450
|
FanControlServerBase2.State = State;
|
|
@@ -166253,222 +166512,6 @@ var fanControlConfig = {
|
|
|
166253
166512
|
};
|
|
166254
166513
|
var FanFanControlServer = FanControlServer2(fanControlConfig);
|
|
166255
166514
|
|
|
166256
|
-
// src/matter/behaviors/on-off-server.ts
|
|
166257
|
-
init_esm();
|
|
166258
|
-
init_home_assistant_entity_behavior();
|
|
166259
|
-
|
|
166260
|
-
// src/matter/behaviors/level-control-server.ts
|
|
166261
|
-
init_esm();
|
|
166262
|
-
init_home_assistant_entity_behavior();
|
|
166263
|
-
var lastTurnOnTimestamps = /* @__PURE__ */ new Map();
|
|
166264
|
-
var optimisticLevelState = /* @__PURE__ */ new Map();
|
|
166265
|
-
var OPTIMISTIC_TIMEOUT_MS = 3e3;
|
|
166266
|
-
var OPTIMISTIC_TOLERANCE = 5;
|
|
166267
|
-
function notifyLightTurnedOn(entityId) {
|
|
166268
|
-
lastTurnOnTimestamps.set(entityId, Date.now());
|
|
166269
|
-
}
|
|
166270
|
-
var logger158 = Logger.get("LevelControlServer");
|
|
166271
|
-
var FeaturedBase4 = LevelControlServer.with("OnOff", "Lighting");
|
|
166272
|
-
var LevelControlServerBase = class extends FeaturedBase4 {
|
|
166273
|
-
pendingTransitionTime;
|
|
166274
|
-
async initialize() {
|
|
166275
|
-
if (this.state.currentLevel == null) {
|
|
166276
|
-
this.state.currentLevel = 1;
|
|
166277
|
-
}
|
|
166278
|
-
if (this.state.minLevel == null) {
|
|
166279
|
-
this.state.minLevel = 1;
|
|
166280
|
-
}
|
|
166281
|
-
if (this.state.maxLevel == null) {
|
|
166282
|
-
this.state.maxLevel = 254;
|
|
166283
|
-
}
|
|
166284
|
-
this.state.onLevel = null;
|
|
166285
|
-
logger158.debug(`initialize: calling super.initialize()`);
|
|
166286
|
-
try {
|
|
166287
|
-
await super.initialize();
|
|
166288
|
-
logger158.debug(`initialize: super.initialize() completed successfully`);
|
|
166289
|
-
} catch (error) {
|
|
166290
|
-
logger158.error(`initialize: super.initialize() FAILED:`, error);
|
|
166291
|
-
throw error;
|
|
166292
|
-
}
|
|
166293
|
-
const homeAssistant = await this.agent.load(HomeAssistantEntityBehavior);
|
|
166294
|
-
this.update(homeAssistant.entity);
|
|
166295
|
-
this.reactTo(homeAssistant.onChange, this.update);
|
|
166296
|
-
}
|
|
166297
|
-
update(entity) {
|
|
166298
|
-
if (!entity.state) {
|
|
166299
|
-
return;
|
|
166300
|
-
}
|
|
166301
|
-
const { state } = entity;
|
|
166302
|
-
const config10 = this.state.config;
|
|
166303
|
-
const minLevel = 1;
|
|
166304
|
-
const maxLevel = 254;
|
|
166305
|
-
const levelRange = maxLevel - minLevel;
|
|
166306
|
-
const currentLevelPercent = config10.getValuePercent(state, this.agent);
|
|
166307
|
-
let currentLevel = currentLevelPercent != null ? Math.round(currentLevelPercent * levelRange + minLevel) : null;
|
|
166308
|
-
if (currentLevel != null) {
|
|
166309
|
-
currentLevel = Math.min(Math.max(minLevel, currentLevel), maxLevel);
|
|
166310
|
-
}
|
|
166311
|
-
const optimistic = optimisticLevelState.get(entity.entity_id);
|
|
166312
|
-
if (optimistic != null && currentLevel != null) {
|
|
166313
|
-
if (Date.now() - optimistic.timestamp > OPTIMISTIC_TIMEOUT_MS) {
|
|
166314
|
-
optimisticLevelState.delete(entity.entity_id);
|
|
166315
|
-
} else if (Math.abs(currentLevel - optimistic.expectedLevel) <= OPTIMISTIC_TOLERANCE) {
|
|
166316
|
-
optimisticLevelState.delete(entity.entity_id);
|
|
166317
|
-
} else {
|
|
166318
|
-
currentLevel = null;
|
|
166319
|
-
}
|
|
166320
|
-
}
|
|
166321
|
-
applyPatchState(this.state, {
|
|
166322
|
-
minLevel,
|
|
166323
|
-
maxLevel,
|
|
166324
|
-
...currentLevel != null ? { currentLevel } : {}
|
|
166325
|
-
});
|
|
166326
|
-
}
|
|
166327
|
-
// Fix for Google Home (#41): it sends moveToLevel/moveToLevelWithOnOff/step commands
|
|
166328
|
-
// with transitionTime as null or completely omitted. The TLV schema is patched at startup
|
|
166329
|
-
// (see patch-level-control-tlv.ts) to accept omitted fields. Here we default to 0 (instant).
|
|
166330
|
-
async moveToLevel(request) {
|
|
166331
|
-
if (request.transitionTime == null) {
|
|
166332
|
-
request.transitionTime = 0;
|
|
166333
|
-
}
|
|
166334
|
-
this.pendingTransitionTime = request.transitionTime;
|
|
166335
|
-
return super.moveToLevel(request);
|
|
166336
|
-
}
|
|
166337
|
-
async moveToLevelWithOnOff(request) {
|
|
166338
|
-
if (request.transitionTime == null) {
|
|
166339
|
-
request.transitionTime = 0;
|
|
166340
|
-
}
|
|
166341
|
-
this.pendingTransitionTime = request.transitionTime;
|
|
166342
|
-
return super.moveToLevelWithOnOff(request);
|
|
166343
|
-
}
|
|
166344
|
-
step(request) {
|
|
166345
|
-
if (request.transitionTime == null) {
|
|
166346
|
-
request.transitionTime = 0;
|
|
166347
|
-
}
|
|
166348
|
-
return super.step(request);
|
|
166349
|
-
}
|
|
166350
|
-
stepWithOnOff(request) {
|
|
166351
|
-
if (request.transitionTime == null) {
|
|
166352
|
-
request.transitionTime = 0;
|
|
166353
|
-
}
|
|
166354
|
-
return super.stepWithOnOff(request);
|
|
166355
|
-
}
|
|
166356
|
-
moveToLevelLogic(level) {
|
|
166357
|
-
const homeAssistant = this.agent.get(HomeAssistantEntityBehavior);
|
|
166358
|
-
const config10 = this.state.config;
|
|
166359
|
-
const entityId = homeAssistant.entity.entity_id;
|
|
166360
|
-
const levelRange = this.maxLevel - this.minLevel;
|
|
166361
|
-
const levelPercent = (level - this.minLevel) / levelRange;
|
|
166362
|
-
const lastTurnOn = lastTurnOnTimestamps.get(entityId);
|
|
166363
|
-
const timeSinceTurnOn = lastTurnOn ? Date.now() - lastTurnOn : Infinity;
|
|
166364
|
-
const isMaxBrightness = level >= this.maxLevel;
|
|
166365
|
-
if (isMaxBrightness && timeSinceTurnOn < 200) {
|
|
166366
|
-
logger158.debug(
|
|
166367
|
-
`[${entityId}] Ignoring moveToLevel(${level}) - Alexa brightness reset detected (${timeSinceTurnOn}ms after turn-on)`
|
|
166368
|
-
);
|
|
166369
|
-
return;
|
|
166370
|
-
}
|
|
166371
|
-
const current = config10.getValuePercent(
|
|
166372
|
-
homeAssistant.entity.state,
|
|
166373
|
-
this.agent
|
|
166374
|
-
);
|
|
166375
|
-
if (levelPercent === current) {
|
|
166376
|
-
return;
|
|
166377
|
-
}
|
|
166378
|
-
const action = config10.moveToLevelPercent(levelPercent, this.agent);
|
|
166379
|
-
const transitionTimeTenths = this.pendingTransitionTime;
|
|
166380
|
-
this.pendingTransitionTime = void 0;
|
|
166381
|
-
if (transitionTimeTenths && transitionTimeTenths > 0) {
|
|
166382
|
-
action.data = {
|
|
166383
|
-
...action.data,
|
|
166384
|
-
transition: transitionTimeTenths / 10
|
|
166385
|
-
};
|
|
166386
|
-
}
|
|
166387
|
-
this.state.currentLevel = level;
|
|
166388
|
-
optimisticLevelState.set(entityId, {
|
|
166389
|
-
expectedLevel: level,
|
|
166390
|
-
timestamp: Date.now()
|
|
166391
|
-
});
|
|
166392
|
-
homeAssistant.callAction(action);
|
|
166393
|
-
}
|
|
166394
|
-
};
|
|
166395
|
-
((LevelControlServerBase2) => {
|
|
166396
|
-
class State extends FeaturedBase4.State {
|
|
166397
|
-
config;
|
|
166398
|
-
}
|
|
166399
|
-
LevelControlServerBase2.State = State;
|
|
166400
|
-
})(LevelControlServerBase || (LevelControlServerBase = {}));
|
|
166401
|
-
function LevelControlServer2(config10) {
|
|
166402
|
-
return LevelControlServerBase.set({
|
|
166403
|
-
options: { executeIfOff: true },
|
|
166404
|
-
config: config10
|
|
166405
|
-
});
|
|
166406
|
-
}
|
|
166407
|
-
|
|
166408
|
-
// src/matter/behaviors/on-off-server.ts
|
|
166409
|
-
var logger159 = Logger.get("OnOffServer");
|
|
166410
|
-
var OnOffServerBase = class extends OnOffServer {
|
|
166411
|
-
async initialize() {
|
|
166412
|
-
await super.initialize();
|
|
166413
|
-
const homeAssistant = await this.agent.load(HomeAssistantEntityBehavior);
|
|
166414
|
-
this.update(homeAssistant.entity);
|
|
166415
|
-
this.reactTo(homeAssistant.onChange, this.update);
|
|
166416
|
-
}
|
|
166417
|
-
update({ state }) {
|
|
166418
|
-
applyPatchState(this.state, {
|
|
166419
|
-
onOff: this.isOn(state)
|
|
166420
|
-
});
|
|
166421
|
-
}
|
|
166422
|
-
isOn(entity) {
|
|
166423
|
-
return this.state.config?.isOn?.(entity, this.agent) ?? (this.agent.get(HomeAssistantEntityBehavior).isAvailable && entity.state !== "off");
|
|
166424
|
-
}
|
|
166425
|
-
on() {
|
|
166426
|
-
const { turnOn, turnOff } = this.state.config;
|
|
166427
|
-
if (turnOn === null) {
|
|
166428
|
-
setTimeout(this.callback(this.autoReset), 1e3);
|
|
166429
|
-
return;
|
|
166430
|
-
}
|
|
166431
|
-
const homeAssistant = this.agent.get(HomeAssistantEntityBehavior);
|
|
166432
|
-
const action = turnOn?.(void 0, this.agent) ?? {
|
|
166433
|
-
action: "homeassistant.turn_on"
|
|
166434
|
-
};
|
|
166435
|
-
logger159.info(`[${homeAssistant.entityId}] Turning ON -> ${action.action}`);
|
|
166436
|
-
notifyLightTurnedOn(homeAssistant.entityId);
|
|
166437
|
-
applyPatchState(this.state, { onOff: true });
|
|
166438
|
-
homeAssistant.callAction(action);
|
|
166439
|
-
if (turnOff === null) {
|
|
166440
|
-
setTimeout(this.callback(this.autoReset), 1e3);
|
|
166441
|
-
}
|
|
166442
|
-
}
|
|
166443
|
-
off() {
|
|
166444
|
-
const { turnOff } = this.state.config;
|
|
166445
|
-
if (turnOff === null) {
|
|
166446
|
-
setTimeout(this.callback(this.autoReset), 1e3);
|
|
166447
|
-
return;
|
|
166448
|
-
}
|
|
166449
|
-
const homeAssistant = this.agent.get(HomeAssistantEntityBehavior);
|
|
166450
|
-
const action = turnOff?.(void 0, this.agent) ?? {
|
|
166451
|
-
action: "homeassistant.turn_off"
|
|
166452
|
-
};
|
|
166453
|
-
logger159.info(`[${homeAssistant.entityId}] Turning OFF -> ${action.action}`);
|
|
166454
|
-
applyPatchState(this.state, { onOff: false });
|
|
166455
|
-
homeAssistant.callAction(action);
|
|
166456
|
-
}
|
|
166457
|
-
autoReset() {
|
|
166458
|
-
const homeAssistant = this.agent.get(HomeAssistantEntityBehavior);
|
|
166459
|
-
this.update(homeAssistant.entity);
|
|
166460
|
-
}
|
|
166461
|
-
};
|
|
166462
|
-
((OnOffServerBase2) => {
|
|
166463
|
-
class State extends OnOffServer.State {
|
|
166464
|
-
config;
|
|
166465
|
-
}
|
|
166466
|
-
OnOffServerBase2.State = State;
|
|
166467
|
-
})(OnOffServerBase || (OnOffServerBase = {}));
|
|
166468
|
-
function OnOffServer2(config10 = {}) {
|
|
166469
|
-
return OnOffServerBase.set({ config: config10 });
|
|
166470
|
-
}
|
|
166471
|
-
|
|
166472
166515
|
// src/matter/endpoints/legacy/fan/behaviors/fan-on-off-server.ts
|
|
166473
166516
|
var FanOnOffServer = OnOffServer2({
|
|
166474
166517
|
turnOn: () => ({ action: "fan.turn_on" }),
|
|
@@ -169488,7 +169531,7 @@ init_nodejs();
|
|
|
169488
169531
|
init_home_assistant_entity_behavior();
|
|
169489
169532
|
var logger170 = Logger.get("ColorControlServer");
|
|
169490
169533
|
var optimisticColorState = /* @__PURE__ */ new Map();
|
|
169491
|
-
var
|
|
169534
|
+
var OPTIMISTIC_TIMEOUT_MS3 = 3e3;
|
|
169492
169535
|
var OPTIMISTIC_TOLERANCE2 = 5;
|
|
169493
169536
|
var pendingColorStaging = /* @__PURE__ */ new Map();
|
|
169494
169537
|
function consumePendingColorStaging(entityId) {
|
|
@@ -169578,7 +169621,7 @@ var ColorControlServerBase = class extends FeaturedBase7 {
|
|
|
169578
169621
|
let skipColorTemp = false;
|
|
169579
169622
|
let skipHueSat = false;
|
|
169580
169623
|
if (optimistic != null) {
|
|
169581
|
-
if (Date.now() - optimistic.timestamp >
|
|
169624
|
+
if (Date.now() - optimistic.timestamp > OPTIMISTIC_TIMEOUT_MS3) {
|
|
169582
169625
|
optimisticColorState.delete(entity.entity_id);
|
|
169583
169626
|
} else {
|
|
169584
169627
|
if (optimistic.colorTemperatureMireds != null && currentMireds != null) {
|
|
@@ -171012,7 +171055,7 @@ init_esm();
|
|
|
171012
171055
|
init_home_assistant_entity_behavior();
|
|
171013
171056
|
var logger175 = Logger.get("SpeakerLevelControlServer");
|
|
171014
171057
|
var optimisticLevelState2 = /* @__PURE__ */ new Map();
|
|
171015
|
-
var
|
|
171058
|
+
var OPTIMISTIC_TIMEOUT_MS4 = 3e3;
|
|
171016
171059
|
var OPTIMISTIC_TOLERANCE3 = 5;
|
|
171017
171060
|
var FeaturedBase9 = LevelControlServer.with("OnOff");
|
|
171018
171061
|
var SpeakerLevelControlServerBase = class extends FeaturedBase9 {
|
|
@@ -171051,7 +171094,7 @@ var SpeakerLevelControlServerBase = class extends FeaturedBase9 {
|
|
|
171051
171094
|
);
|
|
171052
171095
|
const optimistic = optimisticLevelState2.get(entity.entity_id);
|
|
171053
171096
|
if (optimistic != null && currentLevel != null) {
|
|
171054
|
-
if (Date.now() - optimistic.timestamp >
|
|
171097
|
+
if (Date.now() - optimistic.timestamp > OPTIMISTIC_TIMEOUT_MS4) {
|
|
171055
171098
|
optimisticLevelState2.delete(entity.entity_id);
|
|
171056
171099
|
} else if (Math.abs(currentLevel - optimistic.expectedLevel) <= OPTIMISTIC_TOLERANCE3) {
|
|
171057
171100
|
optimisticLevelState2.delete(entity.entity_id);
|