@riddix/hamh 2.1.0-alpha.482 → 2.1.0-alpha.484
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
|
@@ -166823,6 +166823,25 @@ var EntityStateProvider = class extends Service {
|
|
|
166823
166823
|
}
|
|
166824
166824
|
return value;
|
|
166825
166825
|
}
|
|
166826
|
+
/**
|
|
166827
|
+
* Get battery percentage from a battery entity.
|
|
166828
|
+
* Handles both numeric sensors (e.g. sensor.battery → "25.0" → 25)
|
|
166829
|
+
* and binary sensors (e.g. binary_sensor.battery → off=100%, on=0%).
|
|
166830
|
+
* In HA, binary_sensor with device_class=battery uses on=low battery.
|
|
166831
|
+
*/
|
|
166832
|
+
getBatteryPercent(entityId) {
|
|
166833
|
+
const state = this.getState(entityId);
|
|
166834
|
+
if (!state) {
|
|
166835
|
+
return null;
|
|
166836
|
+
}
|
|
166837
|
+
const numericValue = Number.parseFloat(state.state);
|
|
166838
|
+
if (!Number.isNaN(numericValue)) {
|
|
166839
|
+
return numericValue;
|
|
166840
|
+
}
|
|
166841
|
+
if (state.state === "off") return 100;
|
|
166842
|
+
if (state.state === "on") return 0;
|
|
166843
|
+
return null;
|
|
166844
|
+
}
|
|
166826
166845
|
};
|
|
166827
166846
|
|
|
166828
166847
|
// src/utils/converters/temperature.ts
|
|
@@ -168010,7 +168029,7 @@ var batteryConfig = {
|
|
|
168010
168029
|
const batteryEntity = homeAssistant.state.mapping?.batteryEntity;
|
|
168011
168030
|
if (batteryEntity) {
|
|
168012
168031
|
const stateProvider = agent.env.get(EntityStateProvider);
|
|
168013
|
-
const battery = stateProvider.
|
|
168032
|
+
const battery = stateProvider.getBatteryPercent(batteryEntity);
|
|
168014
168033
|
if (battery != null) return Math.max(0, Math.min(100, battery));
|
|
168015
168034
|
}
|
|
168016
168035
|
return null;
|
|
@@ -168310,7 +168329,7 @@ var batteryConfig2 = {
|
|
|
168310
168329
|
const batteryEntity = homeAssistant.state.mapping?.batteryEntity;
|
|
168311
168330
|
if (batteryEntity) {
|
|
168312
168331
|
const stateProvider = agent.env.get(EntityStateProvider);
|
|
168313
|
-
const battery = stateProvider.
|
|
168332
|
+
const battery = stateProvider.getBatteryPercent(batteryEntity);
|
|
168314
168333
|
if (battery != null) return Math.max(0, Math.min(100, battery));
|
|
168315
168334
|
}
|
|
168316
168335
|
return null;
|
|
@@ -168876,7 +168895,7 @@ var ContactSensorWithBatteryType = ContactSensorDevice.with(
|
|
|
168876
168895
|
const batteryEntity = homeAssistant.state.mapping?.batteryEntity;
|
|
168877
168896
|
if (batteryEntity) {
|
|
168878
168897
|
const stateProvider = agent.env.get(EntityStateProvider);
|
|
168879
|
-
const battery = stateProvider.
|
|
168898
|
+
const battery = stateProvider.getBatteryPercent(batteryEntity);
|
|
168880
168899
|
if (battery != null) {
|
|
168881
168900
|
return Math.max(0, Math.min(100, battery));
|
|
168882
168901
|
}
|
|
@@ -168944,7 +168963,7 @@ var MotionSensorWithBatteryType = OccupancySensorDevice.with(
|
|
|
168944
168963
|
const batteryEntity = homeAssistant.state.mapping?.batteryEntity;
|
|
168945
168964
|
if (batteryEntity) {
|
|
168946
168965
|
const stateProvider = agent.env.get(EntityStateProvider);
|
|
168947
|
-
const battery = stateProvider.
|
|
168966
|
+
const battery = stateProvider.getBatteryPercent(batteryEntity);
|
|
168948
168967
|
if (battery != null) {
|
|
168949
168968
|
return Math.max(0, Math.min(100, battery));
|
|
168950
168969
|
}
|
|
@@ -169012,7 +169031,7 @@ var OccupancySensorWithBatteryType = OccupancySensorDevice.with(
|
|
|
169012
169031
|
const batteryEntity = homeAssistant.state.mapping?.batteryEntity;
|
|
169013
169032
|
if (batteryEntity) {
|
|
169014
169033
|
const stateProvider = agent.env.get(EntityStateProvider);
|
|
169015
|
-
const battery = stateProvider.
|
|
169034
|
+
const battery = stateProvider.getBatteryPercent(batteryEntity);
|
|
169016
169035
|
if (battery != null) {
|
|
169017
169036
|
return Math.max(0, Math.min(100, battery));
|
|
169018
169037
|
}
|
|
@@ -169050,7 +169069,7 @@ var OnOffSensorWithBatteryType = OnOffSensorDevice.with(
|
|
|
169050
169069
|
const batteryEntity = homeAssistant.state.mapping?.batteryEntity;
|
|
169051
169070
|
if (batteryEntity) {
|
|
169052
169071
|
const stateProvider = agent.env.get(EntityStateProvider);
|
|
169053
|
-
const battery = stateProvider.
|
|
169072
|
+
const battery = stateProvider.getBatteryPercent(batteryEntity);
|
|
169054
169073
|
if (battery != null) {
|
|
169055
169074
|
return Math.max(0, Math.min(100, battery));
|
|
169056
169075
|
}
|
|
@@ -169106,7 +169125,7 @@ var AlarmPowerSourceServer = PowerSourceServer2({
|
|
|
169106
169125
|
const batteryEntity = homeAssistant.state.mapping?.batteryEntity;
|
|
169107
169126
|
if (batteryEntity) {
|
|
169108
169127
|
const stateProvider = agent.env.get(EntityStateProvider);
|
|
169109
|
-
const battery = stateProvider.
|
|
169128
|
+
const battery = stateProvider.getBatteryPercent(batteryEntity);
|
|
169110
169129
|
if (battery != null) {
|
|
169111
169130
|
return Math.max(0, Math.min(100, battery));
|
|
169112
169131
|
}
|
|
@@ -170111,7 +170130,7 @@ var ClimatePowerSourceServer = PowerSourceServer2({
|
|
|
170111
170130
|
const batteryEntity = homeAssistant.state.mapping?.batteryEntity;
|
|
170112
170131
|
if (batteryEntity) {
|
|
170113
170132
|
const stateProvider = agent.env.get(EntityStateProvider);
|
|
170114
|
-
const battery = stateProvider.
|
|
170133
|
+
const battery = stateProvider.getBatteryPercent(batteryEntity);
|
|
170115
170134
|
if (battery != null) {
|
|
170116
170135
|
return Math.max(0, Math.min(100, battery));
|
|
170117
170136
|
}
|
|
@@ -170281,6 +170300,9 @@ var WindowCoveringServerBase = class _WindowCoveringServerBase extends FeaturedB
|
|
|
170281
170300
|
// Track when the last command was received to implement two-phase debounce
|
|
170282
170301
|
lastLiftCommandTime = 0;
|
|
170283
170302
|
lastTiltCommandTime = 0;
|
|
170303
|
+
// Track lift direction to skip redundant tilt on downOrClose / upOrOpen (#246)
|
|
170304
|
+
lastLiftMovementMs = 0;
|
|
170305
|
+
lastLiftMovementDirection = null;
|
|
170284
170306
|
// Store everything needed for debounced HA calls - entityId and actions service
|
|
170285
170307
|
// must be captured before setTimeout because agent context expires after command handler
|
|
170286
170308
|
pendingLiftAction = null;
|
|
@@ -170403,6 +170425,8 @@ var WindowCoveringServerBase = class _WindowCoveringServerBase extends FeaturedB
|
|
|
170403
170425
|
`handleMovement: type=${MovementType[type]}, direction=${MovementDirection[direction]}, target=${targetPercent100ths}, currentLift=${currentLift}, currentTilt=${currentTilt}, absolutePosition=${this.features.absolutePosition}`
|
|
170404
170426
|
);
|
|
170405
170427
|
if (type === MovementType.Lift) {
|
|
170428
|
+
this.lastLiftMovementMs = Date.now();
|
|
170429
|
+
this.lastLiftMovementDirection = direction;
|
|
170406
170430
|
if (targetPercent100ths === 0) {
|
|
170407
170431
|
this.handleLiftOpen();
|
|
170408
170432
|
} else if (targetPercent100ths === 1e4) {
|
|
@@ -170415,6 +170439,12 @@ var WindowCoveringServerBase = class _WindowCoveringServerBase extends FeaturedB
|
|
|
170415
170439
|
this.handleLiftClose();
|
|
170416
170440
|
}
|
|
170417
170441
|
} else if (type === MovementType.Tilt) {
|
|
170442
|
+
if (targetPercent100ths == null && this.lastLiftMovementDirection === direction && Date.now() - this.lastLiftMovementMs < 50) {
|
|
170443
|
+
logger175.info(
|
|
170444
|
+
`Skipping tilt ${MovementDirection[direction]} \u2014 lift already moving in same direction`
|
|
170445
|
+
);
|
|
170446
|
+
return;
|
|
170447
|
+
}
|
|
170418
170448
|
if (targetPercent100ths === 0) {
|
|
170419
170449
|
this.handleTiltOpen();
|
|
170420
170450
|
} else if (targetPercent100ths === 1e4) {
|
|
@@ -170699,7 +170729,7 @@ var CoverPowerSourceServer = PowerSourceServer2({
|
|
|
170699
170729
|
const batteryEntity = homeAssistant.state.mapping?.batteryEntity;
|
|
170700
170730
|
if (batteryEntity) {
|
|
170701
170731
|
const stateProvider = agent.env.get(EntityStateProvider);
|
|
170702
|
-
const battery = stateProvider.
|
|
170732
|
+
const battery = stateProvider.getBatteryPercent(batteryEntity);
|
|
170703
170733
|
if (battery != null) {
|
|
170704
170734
|
return Math.max(0, Math.min(100, battery));
|
|
170705
170735
|
}
|
|
@@ -170873,7 +170903,7 @@ var FanPowerSourceServer = PowerSourceServer2({
|
|
|
170873
170903
|
const batteryEntity = homeAssistant.state.mapping?.batteryEntity;
|
|
170874
170904
|
if (batteryEntity) {
|
|
170875
170905
|
const stateProvider = agent.env.get(EntityStateProvider);
|
|
170876
|
-
const battery = stateProvider.
|
|
170906
|
+
const battery = stateProvider.getBatteryPercent(batteryEntity);
|
|
170877
170907
|
if (battery != null) {
|
|
170878
170908
|
return Math.max(0, Math.min(100, battery));
|
|
170879
170909
|
}
|
|
@@ -171471,7 +171501,7 @@ var LightPowerSourceServer = PowerSourceServer2({
|
|
|
171471
171501
|
const batteryEntity = homeAssistant.state.mapping?.batteryEntity;
|
|
171472
171502
|
if (batteryEntity) {
|
|
171473
171503
|
const stateProvider = agent.env.get(EntityStateProvider);
|
|
171474
|
-
const battery = stateProvider.
|
|
171504
|
+
const battery = stateProvider.getBatteryPercent(batteryEntity);
|
|
171475
171505
|
if (battery != null) {
|
|
171476
171506
|
return Math.max(0, Math.min(100, battery));
|
|
171477
171507
|
}
|
|
@@ -171508,7 +171538,7 @@ var LightPowerSourceServer2 = PowerSourceServer2({
|
|
|
171508
171538
|
const batteryEntity = homeAssistant.state.mapping?.batteryEntity;
|
|
171509
171539
|
if (batteryEntity) {
|
|
171510
171540
|
const stateProvider = agent.env.get(EntityStateProvider);
|
|
171511
|
-
const battery = stateProvider.
|
|
171541
|
+
const battery = stateProvider.getBatteryPercent(batteryEntity);
|
|
171512
171542
|
if (battery != null) {
|
|
171513
171543
|
return Math.max(0, Math.min(100, battery));
|
|
171514
171544
|
}
|
|
@@ -171558,7 +171588,7 @@ var LightPowerSourceServer3 = PowerSourceServer2({
|
|
|
171558
171588
|
const batteryEntity = homeAssistant.state.mapping?.batteryEntity;
|
|
171559
171589
|
if (batteryEntity) {
|
|
171560
171590
|
const stateProvider = agent.env.get(EntityStateProvider);
|
|
171561
|
-
const battery = stateProvider.
|
|
171591
|
+
const battery = stateProvider.getBatteryPercent(batteryEntity);
|
|
171562
171592
|
if (battery != null) {
|
|
171563
171593
|
return Math.max(0, Math.min(100, battery));
|
|
171564
171594
|
}
|
|
@@ -172279,7 +172309,7 @@ var LockPowerSourceServer = PowerSourceServer2({
|
|
|
172279
172309
|
const batteryEntity = homeAssistant.state.mapping?.batteryEntity;
|
|
172280
172310
|
if (batteryEntity) {
|
|
172281
172311
|
const stateProvider = agent.env.get(EntityStateProvider);
|
|
172282
|
-
const battery = stateProvider.
|
|
172312
|
+
const battery = stateProvider.getBatteryPercent(batteryEntity);
|
|
172283
172313
|
if (battery != null) {
|
|
172284
172314
|
return Math.max(0, Math.min(100, battery));
|
|
172285
172315
|
}
|
|
@@ -173970,7 +174000,7 @@ var batteryConfig3 = {
|
|
|
173970
174000
|
const batteryEntity = homeAssistant.state.mapping?.batteryEntity;
|
|
173971
174001
|
if (batteryEntity) {
|
|
173972
174002
|
const stateProvider = agent.env.get(EntityStateProvider);
|
|
173973
|
-
const battery = stateProvider.
|
|
174003
|
+
const battery = stateProvider.getBatteryPercent(batteryEntity);
|
|
173974
174004
|
if (battery != null) {
|
|
173975
174005
|
return Math.max(0, Math.min(100, battery));
|
|
173976
174006
|
}
|
|
@@ -174468,7 +174498,7 @@ var batteryConfig4 = {
|
|
|
174468
174498
|
const batteryEntity = homeAssistant.state.mapping?.batteryEntity;
|
|
174469
174499
|
if (batteryEntity) {
|
|
174470
174500
|
const stateProvider = agent.env.get(EntityStateProvider);
|
|
174471
|
-
const battery = stateProvider.
|
|
174501
|
+
const battery = stateProvider.getBatteryPercent(batteryEntity);
|
|
174472
174502
|
if (battery != null) {
|
|
174473
174503
|
return Math.max(0, Math.min(100, battery));
|
|
174474
174504
|
}
|
|
@@ -174550,7 +174580,7 @@ var batteryConfig5 = {
|
|
|
174550
174580
|
const batteryEntity = homeAssistant.state.mapping?.batteryEntity;
|
|
174551
174581
|
if (batteryEntity) {
|
|
174552
174582
|
const stateProvider = agent.env.get(EntityStateProvider);
|
|
174553
|
-
const battery = stateProvider.
|
|
174583
|
+
const battery = stateProvider.getBatteryPercent(batteryEntity);
|
|
174554
174584
|
if (battery != null) {
|
|
174555
174585
|
return Math.max(0, Math.min(100, battery));
|
|
174556
174586
|
}
|
|
@@ -174695,7 +174725,7 @@ var SwitchWithBatteryEndpointType = OnOffPlugInUnitDevice.with(
|
|
|
174695
174725
|
const batteryEntity = homeAssistant.state.mapping?.batteryEntity;
|
|
174696
174726
|
if (batteryEntity) {
|
|
174697
174727
|
const stateProvider = agent.env.get(EntityStateProvider);
|
|
174698
|
-
const battery = stateProvider.
|
|
174728
|
+
const battery = stateProvider.getBatteryPercent(batteryEntity);
|
|
174699
174729
|
if (battery != null) {
|
|
174700
174730
|
return Math.max(0, Math.min(100, battery));
|
|
174701
174731
|
}
|
|
@@ -175697,7 +175727,7 @@ var VacuumPowerSourceServer = PowerSourceServer2({
|
|
|
175697
175727
|
const batteryEntity = homeAssistant.state.mapping?.batteryEntity;
|
|
175698
175728
|
if (batteryEntity) {
|
|
175699
175729
|
const stateProvider = agent.env.get(EntityStateProvider);
|
|
175700
|
-
const battery = stateProvider.
|
|
175730
|
+
const battery = stateProvider.getBatteryPercent(batteryEntity);
|
|
175701
175731
|
if (battery != null) {
|
|
175702
175732
|
return Math.max(0, Math.min(100, battery));
|
|
175703
175733
|
}
|
|
@@ -178162,6 +178192,16 @@ var BridgeRegistry = class _BridgeRegistry {
|
|
|
178162
178192
|
return entity.entity_id;
|
|
178163
178193
|
}
|
|
178164
178194
|
}
|
|
178195
|
+
for (const entity of sameDevice) {
|
|
178196
|
+
if (!entity.entity_id.startsWith("binary_sensor.")) continue;
|
|
178197
|
+
const state = this.registry.states[entity.entity_id];
|
|
178198
|
+
if (!state) continue;
|
|
178199
|
+
const attrs = state.attributes;
|
|
178200
|
+
if (attrs.device_class === "battery") {
|
|
178201
|
+
this._batteryEntityCache.set(deviceId, entity.entity_id);
|
|
178202
|
+
return entity.entity_id;
|
|
178203
|
+
}
|
|
178204
|
+
}
|
|
178165
178205
|
this._batteryEntityCache.set(deviceId, null);
|
|
178166
178206
|
return void 0;
|
|
178167
178207
|
}
|
|
@@ -178625,6 +178665,13 @@ var BridgeRegistry = class _BridgeRegistry {
|
|
|
178625
178665
|
if (attrs.device_class === SensorDeviceClass.battery) continue;
|
|
178626
178666
|
}
|
|
178627
178667
|
}
|
|
178668
|
+
if (entity.entity_id.startsWith("binary_sensor.")) {
|
|
178669
|
+
const state = this._states[entity.entity_id];
|
|
178670
|
+
if (state) {
|
|
178671
|
+
const attrs = state.attributes;
|
|
178672
|
+
if (attrs.device_class === "battery") continue;
|
|
178673
|
+
}
|
|
178674
|
+
}
|
|
178628
178675
|
const batteryEntityId = this.findBatteryEntityForDevice(
|
|
178629
178676
|
entity.device_id
|
|
178630
178677
|
);
|