fix: 修复拨码开关数字孪生无法正常工作的问题

This commit is contained in:
SikongJueluo 2025-08-17 12:29:46 +08:00
parent b6720d867d
commit 97b86acfa8
No known key found for this signature in database
2 changed files with 15 additions and 2 deletions

View File

@ -114,7 +114,7 @@ public class SwitchController : ControllerBase
for (int i = 0; i < keyStatus.Length; i++)
{
var result = await switchCtrl.SetSwitchOnOff(i, keyStatus[i]);
var result = await switchCtrl.SetSwitchOnOff(i + 1, keyStatus[i]);
if (!result.IsSuccessful)
{
logger.Error(result.Error, $"SetSwitchOnOff({i}, {keyStatus[i]}) failed");

View File

@ -127,6 +127,10 @@ const switchCount = computed(() => {
else return props.switchCount;
});
function getClient() {
return AuthManager.createClient(SwitchClient);
}
//
function parseInitialValues(): boolean[] {
if (Array.isArray(props.initialValues)) {
@ -162,7 +166,7 @@ function updateStatus(newStates: boolean[], index?: number) {
btnStatus.value = newStates.slice(0, switchCount.value);
if (props.enableDigitalTwin) {
try {
const client = AuthManager.createClient(SwitchClient);
const client = getClient();
if (!isUndefined(index)) client.setSwitchOnOff(index, newStates[index]);
else client.setMultiSwitchsOnOff(btnStatus.value);
} catch (error: any) {}
@ -186,6 +190,15 @@ function setBtnStatus(idx: number, isOn: boolean) {
}
// props
watch(
() => props.enableDigitalTwin,
(newVal) => {
const client = getClient();
client.setEnable(newVal);
},
{ immediate: true },
);
watch(
() => [switchCount.value, props.initialValues],
() => {