@riddix/hamh 2.1.0-alpha.481 → 2.1.0-alpha.483

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.
@@ -168891,6 +168891,74 @@ var ContactSensorWithBatteryType = ContactSensorDevice.with(
168891
168891
  })
168892
168892
  );
168893
168893
 
168894
+ // src/matter/endpoints/legacy/binary-sensor/motion-sensor.ts
168895
+ init_home_assistant_entity_behavior();
168896
+
168897
+ // src/matter/behaviors/pir-occupancy-sensing-server.ts
168898
+ init_home_assistant_entity_behavior();
168899
+ var PirOccupancySensingServerBase = OccupancySensingServer.with(
168900
+ OccupancySensing3.Feature.PassiveInfrared
168901
+ );
168902
+ var PirOccupancySensingServer = class extends PirOccupancySensingServerBase {
168903
+ async initialize() {
168904
+ await super.initialize();
168905
+ const homeAssistant = await this.agent.load(HomeAssistantEntityBehavior);
168906
+ this.update(homeAssistant.entity);
168907
+ this.reactTo(homeAssistant.onChange, this.update);
168908
+ }
168909
+ update(entity) {
168910
+ if (!entity.state) {
168911
+ return;
168912
+ }
168913
+ const { state } = entity;
168914
+ applyPatchState(this.state, {
168915
+ occupancy: { occupied: this.isOccupied(state) },
168916
+ occupancySensorType: OccupancySensing3.OccupancySensorType.Pir,
168917
+ occupancySensorTypeBitmap: {
168918
+ pir: true,
168919
+ physicalContact: false,
168920
+ ultrasonic: false
168921
+ }
168922
+ });
168923
+ }
168924
+ isOccupied(state) {
168925
+ return this.agent.get(HomeAssistantEntityBehavior).isAvailable && state.state !== "off";
168926
+ }
168927
+ };
168928
+
168929
+ // src/matter/endpoints/legacy/binary-sensor/motion-sensor.ts
168930
+ var MotionSensorType = OccupancySensorDevice.with(
168931
+ BasicInformationServer2,
168932
+ IdentifyServer2,
168933
+ HomeAssistantEntityBehavior,
168934
+ PirOccupancySensingServer
168935
+ );
168936
+ var MotionSensorWithBatteryType = OccupancySensorDevice.with(
168937
+ BasicInformationServer2,
168938
+ IdentifyServer2,
168939
+ HomeAssistantEntityBehavior,
168940
+ PirOccupancySensingServer,
168941
+ PowerSourceServer2({
168942
+ getBatteryPercent: (entity, agent) => {
168943
+ const homeAssistant = agent.get(HomeAssistantEntityBehavior);
168944
+ const batteryEntity = homeAssistant.state.mapping?.batteryEntity;
168945
+ if (batteryEntity) {
168946
+ const stateProvider = agent.env.get(EntityStateProvider);
168947
+ const battery = stateProvider.getNumericState(batteryEntity);
168948
+ if (battery != null) {
168949
+ return Math.max(0, Math.min(100, battery));
168950
+ }
168951
+ }
168952
+ const attrs = entity.attributes;
168953
+ const level = attrs.battery_level ?? attrs.battery;
168954
+ if (level == null || Number.isNaN(Number(level))) {
168955
+ return null;
168956
+ }
168957
+ return Number(level);
168958
+ }
168959
+ })
168960
+ );
168961
+
168894
168962
  // src/matter/endpoints/legacy/binary-sensor/occupancy-sensor.ts
168895
168963
  init_home_assistant_entity_behavior();
168896
168964
 
@@ -169121,8 +169189,8 @@ var deviceClasses = {
169121
169189
  [BinarySensorDeviceClass.Update]: ContactSensorType,
169122
169190
  [BinarySensorDeviceClass.Vibration]: ContactSensorType,
169123
169191
  [BinarySensorDeviceClass.Window]: ContactSensorType,
169124
- [BinarySensorDeviceClass.Motion]: OccupancySensorType,
169125
- [BinarySensorDeviceClass.Moving]: OccupancySensorType,
169192
+ [BinarySensorDeviceClass.Motion]: MotionSensorType,
169193
+ [BinarySensorDeviceClass.Moving]: MotionSensorType,
169126
169194
  [BinarySensorDeviceClass.Occupancy]: OccupancySensorType,
169127
169195
  [BinarySensorDeviceClass.Presence]: OccupancySensorType,
169128
169196
  [BinarySensorDeviceClass.Smoke]: SmokeAlarmType,
@@ -169130,6 +169198,7 @@ var deviceClasses = {
169130
169198
  };
169131
169199
  var batteryTypes = /* @__PURE__ */ new Map([
169132
169200
  [ContactSensorType, ContactSensorWithBatteryType],
169201
+ [MotionSensorType, MotionSensorWithBatteryType],
169133
169202
  [OccupancySensorType, OccupancySensorWithBatteryType],
169134
169203
  [OnOffSensorType, OnOffSensorWithBatteryType],
169135
169204
  [SmokeAlarmType, SmokeAlarmWithBatteryType],
@@ -170212,6 +170281,9 @@ var WindowCoveringServerBase = class _WindowCoveringServerBase extends FeaturedB
170212
170281
  // Track when the last command was received to implement two-phase debounce
170213
170282
  lastLiftCommandTime = 0;
170214
170283
  lastTiltCommandTime = 0;
170284
+ // Track lift direction to skip redundant tilt on downOrClose / upOrOpen (#246)
170285
+ lastLiftMovementMs = 0;
170286
+ lastLiftMovementDirection = null;
170215
170287
  // Store everything needed for debounced HA calls - entityId and actions service
170216
170288
  // must be captured before setTimeout because agent context expires after command handler
170217
170289
  pendingLiftAction = null;
@@ -170334,6 +170406,8 @@ var WindowCoveringServerBase = class _WindowCoveringServerBase extends FeaturedB
170334
170406
  `handleMovement: type=${MovementType[type]}, direction=${MovementDirection[direction]}, target=${targetPercent100ths}, currentLift=${currentLift}, currentTilt=${currentTilt}, absolutePosition=${this.features.absolutePosition}`
170335
170407
  );
170336
170408
  if (type === MovementType.Lift) {
170409
+ this.lastLiftMovementMs = Date.now();
170410
+ this.lastLiftMovementDirection = direction;
170337
170411
  if (targetPercent100ths === 0) {
170338
170412
  this.handleLiftOpen();
170339
170413
  } else if (targetPercent100ths === 1e4) {
@@ -170346,6 +170420,12 @@ var WindowCoveringServerBase = class _WindowCoveringServerBase extends FeaturedB
170346
170420
  this.handleLiftClose();
170347
170421
  }
170348
170422
  } else if (type === MovementType.Tilt) {
170423
+ if (targetPercent100ths == null && this.lastLiftMovementDirection === direction && Date.now() - this.lastLiftMovementMs < 50) {
170424
+ logger175.info(
170425
+ `Skipping tilt ${MovementDirection[direction]} \u2014 lift already moving in same direction`
170426
+ );
170427
+ return;
170428
+ }
170349
170429
  if (targetPercent100ths === 0) {
170350
170430
  this.handleTiltOpen();
170351
170431
  } else if (targetPercent100ths === 1e4) {
@@ -177000,6 +177080,9 @@ var matterDeviceTypeFactories = {
177000
177080
  electrical_sensor: (ha) => ElectricalSensorType.set({
177001
177081
  homeAssistantEntity: { entity: ha.entity, customName: ha.customName }
177002
177082
  }),
177083
+ motion_sensor: (ha) => MotionSensorType.set({
177084
+ homeAssistantEntity: { entity: ha.entity, customName: ha.customName }
177085
+ }),
177003
177086
  mode_select: SelectDevice,
177004
177087
  water_valve: ValveDevice,
177005
177088
  pump: PumpEndpoint,