koishi-plugin-prism 0.1.36 → 0.1.37
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/README.md +1 -0
- package/lib/index.js +21 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -69,6 +69,7 @@ pricingConfigIds: [pricing-mahjong-a]
|
|
|
69
69
|
* `items` - 查看当前玩家持有的道具或资产。
|
|
70
70
|
* `list` - 查看当前在线/在店游玩玩家的列表,按 session 标签分组并对同一玩家去重;存在非音乐游戏 session 时取最新的非音乐标签,麻将桌显示当前人数和容量。已开局桌位由后端 session 恢复;未满桌候座由机器人进程暂存,机器人重启后不会保留。
|
|
71
71
|
* `show [deviceId]` - 查看设备电源与连接状态。
|
|
72
|
+
设备状态按后端的普通字符串契约显示;插件仍兼容历史数据库中的 JSON 字符串状态,避免旧记录显示为 `unknown`。
|
|
72
73
|
* `history` - 查看自己的历史游玩记录。
|
|
73
74
|
* `lock` - 发送开门指令。
|
|
74
75
|
* `on <deviceRef>` - 使用后台设备名称、别名或 `all` 请求启动电源;仅已通过 `login`/`入场` 开启活跃计费 session 的玩家可用。不接受 Home Assistant entity ID,成功回复使用后端返回的设备名称。
|
package/lib/index.js
CHANGED
|
@@ -729,11 +729,11 @@ class PrismKoishiService {
|
|
|
729
729
|
const matched = states.find((d) => d.deviceId === alias || d.label === alias);
|
|
730
730
|
if (!matched)
|
|
731
731
|
return `找不到设备: ${alias}`;
|
|
732
|
-
const stateVal = matched.state
|
|
732
|
+
const stateVal = normalizeDeviceState(matched.state);
|
|
733
733
|
return `${matched.label || matched.deviceId}: ${stateVal}`;
|
|
734
734
|
}
|
|
735
735
|
return states
|
|
736
|
-
.map((d) => `${d.label || d.deviceId}: ${d.state
|
|
736
|
+
.map((d) => `${d.label || d.deviceId}: ${normalizeDeviceState(d.state)}`)
|
|
737
737
|
.join("\n");
|
|
738
738
|
}
|
|
739
739
|
async autoPowerOffLoop() {
|
|
@@ -746,7 +746,7 @@ class PrismKoishiService {
|
|
|
746
746
|
return;
|
|
747
747
|
const statesResult = (await this.client.listDeviceStates());
|
|
748
748
|
const states = (statesResult?.deviceStates ?? []);
|
|
749
|
-
const anyOn = states.some((d) => d.state
|
|
749
|
+
const anyOn = states.some((d) => normalizeDeviceState(d.state) === "on");
|
|
750
750
|
if (!anyOn)
|
|
751
751
|
return;
|
|
752
752
|
const dummySender = { id: "system", name: "system" };
|
|
@@ -1136,6 +1136,24 @@ function powerFailureReason(error) {
|
|
|
1136
1136
|
function genericCommandFailure() {
|
|
1137
1137
|
return "操作失败,请稍后再试。";
|
|
1138
1138
|
}
|
|
1139
|
+
function normalizeDeviceState(value) {
|
|
1140
|
+
if (typeof value === "object" && value !== null) {
|
|
1141
|
+
return cleanText(value.state) || "unknown";
|
|
1142
|
+
}
|
|
1143
|
+
const raw = cleanText(value);
|
|
1144
|
+
if (!raw)
|
|
1145
|
+
return "unknown";
|
|
1146
|
+
if (raw.startsWith("{")) {
|
|
1147
|
+
try {
|
|
1148
|
+
const decoded = JSON.parse(raw);
|
|
1149
|
+
return cleanText(decoded?.state) || "unknown";
|
|
1150
|
+
}
|
|
1151
|
+
catch {
|
|
1152
|
+
return raw;
|
|
1153
|
+
}
|
|
1154
|
+
}
|
|
1155
|
+
return raw;
|
|
1156
|
+
}
|
|
1139
1157
|
function resolveMahjongTableConfigs(structured) {
|
|
1140
1158
|
const tables = new Map();
|
|
1141
1159
|
for (const input of structured) {
|