@riddix/hamh 2.1.0-alpha.696 → 2.1.0-alpha.698
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
|
@@ -148005,6 +148005,24 @@ import debounce2 from "debounce";
|
|
|
148005
148005
|
|
|
148006
148006
|
// src/services/bridges/entity-state-provider.ts
|
|
148007
148007
|
init_service();
|
|
148008
|
+
var BATTERY_ENUM_PERCENT = {
|
|
148009
|
+
empty: 0,
|
|
148010
|
+
full: 100,
|
|
148011
|
+
high: 90,
|
|
148012
|
+
low: 20,
|
|
148013
|
+
medium: 50,
|
|
148014
|
+
normal: 70,
|
|
148015
|
+
verylow: 5
|
|
148016
|
+
};
|
|
148017
|
+
function resolveBatteryPercent(state) {
|
|
148018
|
+
const numericValue = Number.parseFloat(state);
|
|
148019
|
+
if (!Number.isNaN(numericValue)) {
|
|
148020
|
+
return numericValue;
|
|
148021
|
+
}
|
|
148022
|
+
if (state === "off") return 100;
|
|
148023
|
+
if (state === "on") return 0;
|
|
148024
|
+
return BATTERY_ENUM_PERCENT[state.toLowerCase()] ?? null;
|
|
148025
|
+
}
|
|
148008
148026
|
var EntityStateProvider = class extends Service {
|
|
148009
148027
|
constructor(registry2) {
|
|
148010
148028
|
super("EntityStateProvider");
|
|
@@ -148044,13 +148062,8 @@ var EntityStateProvider = class extends Service {
|
|
|
148044
148062
|
if (!state) {
|
|
148045
148063
|
return null;
|
|
148046
148064
|
}
|
|
148047
|
-
const numericValue =
|
|
148048
|
-
|
|
148049
|
-
return numericValue;
|
|
148050
|
-
}
|
|
148051
|
-
if (state.state === "off") return 100;
|
|
148052
|
-
if (state.state === "on") return 0;
|
|
148053
|
-
return null;
|
|
148065
|
+
const numericValue = resolveBatteryPercent(state.state);
|
|
148066
|
+
return numericValue;
|
|
148054
148067
|
}
|
|
148055
148068
|
};
|
|
148056
148069
|
|
|
@@ -161075,7 +161088,7 @@ var BridgeRegistry = class _BridgeRegistry {
|
|
|
161075
161088
|
continue;
|
|
161076
161089
|
}
|
|
161077
161090
|
const attrs = state.attributes;
|
|
161078
|
-
if (attrs.device_class === SensorDeviceClass.battery) {
|
|
161091
|
+
if (attrs.device_class === SensorDeviceClass.battery && resolveBatteryPercent(state.state) != null) {
|
|
161079
161092
|
this._batteryEntityCache.set(deviceId, entity.entity_id);
|
|
161080
161093
|
return entity.entity_id;
|
|
161081
161094
|
}
|
|
@@ -161085,7 +161098,17 @@ var BridgeRegistry = class _BridgeRegistry {
|
|
|
161085
161098
|
const state = this.registry.states[entity.entity_id];
|
|
161086
161099
|
if (!state) continue;
|
|
161087
161100
|
const attrs = state.attributes;
|
|
161088
|
-
if (attrs.device_class === "battery") {
|
|
161101
|
+
if (attrs.device_class === "battery" && resolveBatteryPercent(state.state) != null) {
|
|
161102
|
+
this._batteryEntityCache.set(deviceId, entity.entity_id);
|
|
161103
|
+
return entity.entity_id;
|
|
161104
|
+
}
|
|
161105
|
+
}
|
|
161106
|
+
for (const entity of sameDevice) {
|
|
161107
|
+
if (!entity.entity_id.startsWith("sensor.")) continue;
|
|
161108
|
+
const state = this.registry.states[entity.entity_id];
|
|
161109
|
+
if (!state) continue;
|
|
161110
|
+
const attrs = state.attributes;
|
|
161111
|
+
if ((attrs.device_class === "enum" || attrs.device_class == null) && resolveBatteryPercent(state.state) != null) {
|
|
161089
161112
|
this._batteryEntityCache.set(deviceId, entity.entity_id);
|
|
161090
161113
|
return entity.entity_id;
|
|
161091
161114
|
}
|