diff --git a/Boiler_2_Stufig_Landwirtschaft/module.php b/Boiler_2_Stufig_Landwirtschaft/module.php index bdef834..838cb0b 100644 --- a/Boiler_2_Stufig_Landwirtschaft/module.php +++ b/Boiler_2_Stufig_Landwirtschaft/module.php @@ -82,18 +82,27 @@ class Boiler_2_Stufig_Landwirtschaft extends IPSModule } public function getNextTimeAndTemperature($zeitplan) { - $arr = json_decode($zeitplan); - if (empty($arr)) { + $arr = json_decode($zeitplan, true); + if (empty($arr)) { return null; } - $currentTime = date('H:i'); + $currentTime = new DateTime(); + $nextEntry = null; + $minDiff = PHP_INT_MAX; + foreach ($arr as $entry) { - if ($entry['Uhrzeit'] > $currentTime) { - return $entry; + $entryTime = DateTime::createFromFormat('H:i', $entry['Uhrzeit']); + if ($entryTime < $currentTime) { + $entryTime->modify('+1 day'); + } + $diff = $currentTime->diff($entryTime)->format('%r%a') * 24 * 60 + $currentTime->diff($entryTime)->format('%r%h') * 60 + $currentTime->diff($entryTime)->format('%r%i'); + if ($diff < $minDiff) { + $minDiff = $diff; + $nextEntry = $entry; } } - // Falls keine spätere Uhrzeit gefunden wird, nimm den ersten Eintrag am nächsten Tag - return $zeitplan[0]; + + return $nextEntry; } public function calculateRemainingTime($nextTime) { diff --git a/library.json b/library.json index c507d51..c6a3f63 100644 --- a/library.json +++ b/library.json @@ -6,7 +6,7 @@ "compatibility": { "version": "7.1" }, - "version": "1.034", + "version": "1.035", "build": 0, "date": 0 } \ No newline at end of file