1
0
mirror of https://github.com/beestat/app.git synced 2025-07-09 03:04:07 -04:00

Fixed #332 - Sync fails if one of the sync times is during non-existent time

This commit is contained in:
Jon Ziebell 2021-03-15 09:19:28 -04:00
parent 8992ac93fc
commit d5696ba37f
2 changed files with 71 additions and 46 deletions

View File

@ -237,6 +237,19 @@ class ecobee extends external_api {
$this->api('ecobee_token', 'delete', $ecobee_token['ecobee_token_id']); $this->api('ecobee_token', 'delete', $ecobee_token['ecobee_token_id']);
throw new cora\exception('Ecobee access was revoked by user.', 10508, false, null, false); throw new cora\exception('Ecobee access was revoked by user.', 10508, false, null, false);
} }
else if (isset($response['status']) === true && $response['status']['code'] === 3) {
if (
isset($response['status']['message']) === true &&
stripos($response['status']['message'], 'Illegal instant due to time zone offset transition') !== false
) {
// Processing error. Illegal instant due to time zone offset transition (daylight savings time 'gap'): ...
// Happens when you try to use a time that doesn't exist due to daylight savings spring forward
if($this::$log_mysql !== 'all') {
$this->log_mysql($curl_response, true);
}
throw new cora\exception('Illegal instant due to time zone offset transition.', 10509, false, null, false);
}
}
else if (isset($response['status']) === true && $response['status']['code'] !== 0) { else if (isset($response['status']) === true && $response['status']['code'] !== 0) {
// Any other error // Any other error
if($this::$log_mysql !== 'all') { if($this::$log_mysql !== 'all') {

View File

@ -339,59 +339,71 @@ class runtime extends cora\api {
*/ */
$begin = floor($begin / 300) * 300; $begin = floor($begin / 300) * 300;
$end = floor($end / 300) * 300; $end = floor($end / 300) * 300;
$begin_interval = $this->get_interval($begin); $begin_interval = $this->get_interval($begin);
$end_interval = $this->get_interval($end); $end_interval = $this->get_interval($end);
$begin_date = date('Y-m-d', $begin); $begin_date = date('Y-m-d', $begin);
$end_date = date('Y-m-d', $end); $end_date = date('Y-m-d', $end);
$response = $this->api( try {
'ecobee', $response = $this->api(
'ecobee_api', 'ecobee',
[ 'ecobee_api',
'method' => 'GET', [
'endpoint' => 'runtimeReport', 'method' => 'GET',
'arguments' => [ 'endpoint' => 'runtimeReport',
'body' => json_encode([ 'arguments' => [
'selection' => [ 'body' => json_encode([
'selectionType' => 'thermostats', 'selection' => [
'selectionMatch' => $ecobee_thermostat['identifier'] 'selectionType' => 'thermostats',
], 'selectionMatch' => $ecobee_thermostat['identifier']
'startDate' => $begin_date, ],
'endDate' => $end_date, 'startDate' => $begin_date,
'startInterval' => $begin_interval, 'endDate' => $end_date,
'endInterval' => $end_interval, 'startInterval' => $begin_interval,
'columns' => implode( 'endInterval' => $end_interval,
',', 'columns' => implode(
[ ',',
'compCool1', // compressor_1 [
'compCool2', // compressor_2 'compCool1', // compressor_1
'compHeat1', // compressor_1 'compCool2', // compressor_2
'compHeat2', // compressor_2 'compHeat1', // compressor_1
'auxHeat1', // auxiliary_heat_1 'compHeat2', // compressor_2
'auxHeat2', // auxiliary_heat_2 'auxHeat1', // auxiliary_heat_1
'fan', // fan 'auxHeat2', // auxiliary_heat_2
'humidifier', // accessory 'fan', // fan
'dehumidifier', // accessory 'humidifier', // accessory
'ventilator', // accessory 'dehumidifier', // accessory
'economizer', // accessory 'ventilator', // accessory
'hvacMode', // system_mode 'economizer', // accessory
'zoneAveTemp', // indoor_temperature 'hvacMode', // system_mode
'zoneHumidity', // indoor_humidity 'zoneAveTemp', // indoor_temperature
'outdoorTemp', // outdoor_temperature 'zoneHumidity', // indoor_humidity
'outdoorHumidity', // outdoor_humidity 'outdoorTemp', // outdoor_temperature
'zoneCalendarEvent', // event_runtime_thermostat_text_id 'outdoorHumidity', // outdoor_humidity
'zoneClimate', // climate_runtime_thermostat_text_id 'zoneCalendarEvent', // event_runtime_thermostat_text_id
'zoneCoolTemp', // setpoint_cool 'zoneClimate', // climate_runtime_thermostat_text_id
'zoneHeatTemp' // setpoint_heat 'zoneCoolTemp', // setpoint_cool
] 'zoneHeatTemp' // setpoint_heat
), ]
'includeSensors' => true ),
]) 'includeSensors' => true
])
]
] ]
] );
); } catch (cora\exception $e) {
if($e->getCode() === 10509) {
// Try the sync again with times that exist. :)
return $this->sync_(
$thermostat_id,
strtotime('-1 hour', $begin),
strtotime('+1 hour', $end)
);
} else {
throw $e;
}
}
$return = $this->sync_runtime_thermostat($thermostat, $response); $return = $this->sync_runtime_thermostat($thermostat, $response);
$this->sync_runtime_sensor($thermostat, $response); $this->sync_runtime_sensor($thermostat, $response);