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

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],
@@ -177000,6 +177069,9 @@ var matterDeviceTypeFactories = {
177000
177069
  electrical_sensor: (ha) => ElectricalSensorType.set({
177001
177070
  homeAssistantEntity: { entity: ha.entity, customName: ha.customName }
177002
177071
  }),
177072
+ motion_sensor: (ha) => MotionSensorType.set({
177073
+ homeAssistantEntity: { entity: ha.entity, customName: ha.customName }
177074
+ }),
177003
177075
  mode_select: SelectDevice,
177004
177076
  water_valve: ValveDevice,
177005
177077
  pump: PumpEndpoint,