.
This commit is contained in:
parent
122115b5e9
commit
50795d806e
@ -394,14 +394,10 @@ func GlobalPowerControl(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
apiURL := fmt.Sprintf("%s/api/services/switch/%s", haURL, service)
|
apiURL := fmt.Sprintf("%s/api/services/switch/%s", haURL, service)
|
||||||
|
|
||||||
mcbs := []string{
|
// 🌟 PERBAIKAN: Hapus array dan loop, cukup gunakan 1 target saja
|
||||||
"switch.wifi_smart_meter_pro_switch", // Umum
|
targetSwitch := "switch.wifi_smart_meter_pro_switch"
|
||||||
"switch.wifi_smart_meter_pro_2_switch", // AC1
|
|
||||||
"switch.wifi_smart_meter_pro_3_switch", // AC2
|
|
||||||
}
|
|
||||||
|
|
||||||
for i, mcb := range mcbs {
|
payload := map[string]string{"entity_id": targetSwitch}
|
||||||
payload := map[string]string{"entity_id": mcb}
|
|
||||||
jsonPayload, _ := json.Marshal(payload)
|
jsonPayload, _ := json.Marshal(payload)
|
||||||
|
|
||||||
reqHA, err := http.NewRequest("POST", apiURL, bytes.NewBuffer(jsonPayload))
|
reqHA, err := http.NewRequest("POST", apiURL, bytes.NewBuffer(jsonPayload))
|
||||||
@ -416,13 +412,9 @@ func GlobalPowerControl(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("[MCB] Sinyal %s dikirim ke %s\n", req.Action, mcb)
|
fmt.Printf("[MCB] Sinyal %s dikirim ke %s\n", req.Action, targetSwitch)
|
||||||
|
|
||||||
if i < len(mcbs)-1 {
|
|
||||||
time.Sleep(1 * time.Second)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// Mematikan status virtual di dashboard
|
||||||
if req.Action == "off" {
|
if req.Action == "off" {
|
||||||
DeviceStatusCache["lampu1"] = "off"
|
DeviceStatusCache["lampu1"] = "off"
|
||||||
DeviceStatusCache["lampu2"] = "off"
|
DeviceStatusCache["lampu2"] = "off"
|
||||||
@ -432,7 +424,7 @@ func GlobalPowerControl(c *gin.Context) {
|
|||||||
|
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
"status": "success",
|
"status": "success",
|
||||||
"message": fmt.Sprintf("Seluruh daya ruangan berhasil di-%s secara berurutan", req.Action),
|
"message": fmt.Sprintf("Daya utama berhasil di-%s", req.Action),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user