homebridge-shelly-blu-trv 1.0.8 → 1.0.10
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/shellyApi.js +40 -10
- package/package.json +1 -1
package/dist/shellyApi.js
CHANGED
|
@@ -46,10 +46,17 @@ class ShellyApi {
|
|
|
46
46
|
async rpcCall(id, method, params) {
|
|
47
47
|
// Try several RPC variants for wider compatibility with firmware differences
|
|
48
48
|
const paramsStr = params ? `¶ms=${encodeURIComponent(JSON.stringify(params))}` : '';
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
49
|
+
// Try direct GetStatus endpoints first (some firmwares expose dedicated GET endpoints)
|
|
50
|
+
const candidates = [];
|
|
51
|
+
if (method === 'TRV.GetStatus') {
|
|
52
|
+
candidates.push(`/rpc/BluTrv.GetStatus?id=${id}`);
|
|
53
|
+
candidates.push(`/rpc/BluTrv.GetStatus&id=${id}`);
|
|
54
|
+
}
|
|
55
|
+
// Common CALL variants (different firmware use call vs Call and different query separators)
|
|
56
|
+
candidates.push(`/rpc/BluTrv.Call?id=${id}&method=${method}${paramsStr}`);
|
|
57
|
+
candidates.push(`/rpc/BluTrv.call?id=${id}&method=${method}${paramsStr}`);
|
|
58
|
+
candidates.push(`/rpc/BluTrv.Call&id=${id}&method=${method}${paramsStr}`);
|
|
59
|
+
candidates.push(`/rpc/BluTrv.call&id=${id}&method=${method}${paramsStr}`);
|
|
53
60
|
for (const path of candidates) {
|
|
54
61
|
try {
|
|
55
62
|
return await this.get(path);
|
|
@@ -112,15 +119,37 @@ class ShellyApi {
|
|
|
112
119
|
async getTrvState(id) {
|
|
113
120
|
this.log.debug(`[ShellyApi] Fetching state for TRV ${id}`);
|
|
114
121
|
try {
|
|
115
|
-
|
|
116
|
-
const
|
|
117
|
-
const
|
|
122
|
+
// RPC variant may return battery/paired status directly (BluTrv.GetStatus). Use RPC result first.
|
|
123
|
+
const rpcAny = await this.rpcCall(id, 'TRV.GetStatus');
|
|
124
|
+
const rpc = rpcAny;
|
|
125
|
+
// Validate required fields
|
|
126
|
+
if (typeof rpc.current_C !== 'number' ||
|
|
127
|
+
typeof rpc.target_C !== 'number' ||
|
|
128
|
+
typeof rpc.pos !== 'number') {
|
|
129
|
+
throw new Error(`Missing required TRV state fields in RPC response: ${JSON.stringify(rpc)}`);
|
|
130
|
+
}
|
|
131
|
+
// Prefer battery/online information from RPC response; if missing, try /status as a graceful fallback
|
|
132
|
+
let battery = typeof rpc.battery === 'number' ? rpc.battery : undefined;
|
|
133
|
+
let online = typeof rpc.paired === 'boolean' ? rpc.paired : undefined;
|
|
134
|
+
if (battery === undefined || online === undefined) {
|
|
135
|
+
try {
|
|
136
|
+
const status = await this.get("/status");
|
|
137
|
+
const dev = status.ble?.devices?.find((d) => d.id === id);
|
|
138
|
+
battery = battery ?? dev?.battery ?? 0;
|
|
139
|
+
online = online ?? !!dev?.online;
|
|
140
|
+
}
|
|
141
|
+
catch (err) {
|
|
142
|
+
this.log.debug(`[ShellyApi] /status fallback failed for TRV ${id}: ${err instanceof Error ? err.message : String(err)}`);
|
|
143
|
+
battery = battery ?? 0;
|
|
144
|
+
online = online ?? true;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
118
147
|
const state = {
|
|
119
148
|
currentTemp: rpc.current_C,
|
|
120
149
|
targetTemp: rpc.target_C,
|
|
121
150
|
valve: rpc.pos,
|
|
122
|
-
battery:
|
|
123
|
-
online: !!
|
|
151
|
+
battery: battery ?? 0,
|
|
152
|
+
online: !!online
|
|
124
153
|
};
|
|
125
154
|
this.log.debug(`[ShellyApi] TRV ${id} state: temp=${state.currentTemp}°C, target=${state.targetTemp}°C, valve=${state.valve}%, battery=${state.battery}%, online=${state.online}`);
|
|
126
155
|
return state;
|
|
@@ -133,7 +162,8 @@ class ShellyApi {
|
|
|
133
162
|
async setTargetTemp(id, value) {
|
|
134
163
|
this.log.debug(`[ShellyApi] Setting target temperature for TRV ${id} to ${value}°C`);
|
|
135
164
|
try {
|
|
136
|
-
|
|
165
|
+
// Include an explicit id:0 in params (observed in some firmware examples)
|
|
166
|
+
await this.rpcCall(id, 'TRV.SetTarget', { id: 0, target_C: value });
|
|
137
167
|
this.log.debug(`[ShellyApi] Successfully set target temperature for TRV ${id}`);
|
|
138
168
|
}
|
|
139
169
|
catch (error) {
|
package/package.json
CHANGED