diff --git a/cmd/meross-lan-api/apiserver.go b/cmd/meross-lan-api/apiserver.go index f1be1d2..5f72688 100644 --- a/cmd/meross-lan-api/apiserver.go +++ b/cmd/meross-lan-api/apiserver.go @@ -77,10 +77,11 @@ func SetLastOff(deviceName string) { } } -func SetLastStatus(deviceName string) { +func SetStatus(deviceName string, status string) { for idx, d := range config.Devices { if d.Name == deviceName { config.Devices[idx].LastStatus = time.Now() + config.Devices[idx].Status = status } } } @@ -113,15 +114,19 @@ func (apiServer APIServer) deviceStatus(w http.ResponseWriter, deviceName string } if !time.Now().After(device.LastStatus.Add(config.AntiSpam)) { - log.Println("Already turned got status in the last 5 seconds") - writeResponse(w, device, false) - return + log.Println("Already got status in the last 5 seconds") + for idx, d := range config.Devices { + if d.Name == deviceName { + writeResponse(w, config.Devices[idx], false) + return + } + } } device.Status = getStatusString(device) writeResponse(w, device, false) - SetLastStatus(deviceName) + SetStatus(deviceName, device.Status) } func (apiServer APIServer) turnOn(w http.ResponseWriter, deviceName string) { diff --git a/cmd/meross-lan-api/meross.go b/cmd/meross-lan-api/meross.go index 2704822..85e2614 100644 --- a/cmd/meross-lan-api/meross.go +++ b/cmd/meross-lan-api/meross.go @@ -107,10 +107,6 @@ func sendRequest(deviceIp string, body Request) (Response, error) { // convert body to bytes bodyJSON, _ := json.Marshal(body) - if config.Debug { - return result, nil - } - // create and send request req, err := http.NewRequest("POST", "http://"+deviceIp+"/config", bytes.NewBuffer(bodyJSON)) req.Header.Add("Content-Type", "application/json; charset=UTF-8")