From 65cfc072206ce4ee14398301656c6944fa89b59e Mon Sep 17 00:00:00 2001 From: Jon Ziebell Date: Sun, 12 Dec 2021 21:11:40 -0500 Subject: [PATCH] Fixed #346 - Profiles break when adding a new thermostat --- api/profile.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/api/profile.php b/api/profile.php index 6dd75a9..a8dae15 100644 --- a/api/profile.php +++ b/api/profile.php @@ -323,12 +323,21 @@ class profile extends cora\api { } } + if( isset($runtime[$current_timestamp]) === true && // Had data for at least one thermostat isset($runtime[$current_timestamp][$thermostat_id]) === true // Had data for the requested thermostat ) { $current_runtime = $runtime[$current_timestamp][$thermostat_id]; + // List of thermostat_ids that have data for this timestamp. + $relevant_thermostat_ids = []; + foreach($group_thermostats as $possible_relevant_thermostat) { + if(strtotime($possible_relevant_thermostat['data_begin']) <= $current_timestamp) { + $relevant_thermostat_ids[] = $possible_relevant_thermostat['thermostat_id']; + } + } + if($debug === true) { $debug_data = [ 'sample' => null @@ -357,7 +366,7 @@ class profile extends cora\api { $most_off = true; $all_off = true; if( - count($runtime[$current_timestamp]) < count($thermostat_ids) + count($runtime[$current_timestamp]) < count($relevant_thermostat_ids) ) { // If I didn't get data at this timestamp for all thermostats in the // group, all off can't be true.