diff --git a/api/address.php b/api/address.php index b85ebc1..5bca5da 100644 --- a/api/address.php +++ b/api/address.php @@ -17,14 +17,6 @@ class address extends cora\crud { 'public' => [] ]; - public static $converged = [ - 'normalized' => [ - 'type' => 'json' - ] - ]; - - public static $user_locked = true; - /** * Search for an address based on an address string. This will make an API * call to Smarty Streets using that address string (after first checking diff --git a/api/announcement.php b/api/announcement.php index 38a7d25..6c8a7d8 100644 --- a/api/announcement.php +++ b/api/announcement.php @@ -17,18 +17,6 @@ class announcement extends cora\crud { ] ]; - public static $converged = [ - 'title' => [ - 'type' => 'string' - ], - 'text' => [ - 'type' => 'string' - ], - 'icon' => [ - 'type' => 'string' - ] - ]; - public static $user_locked = false; } diff --git a/api/cora/api_cache.php b/api/cora/api_cache.php index 0024c0d..4c0c34d 100644 --- a/api/cora/api_cache.php +++ b/api/cora/api_cache.php @@ -9,10 +9,6 @@ namespace cora; */ class api_cache extends crud { - public static $converged = []; - - public static $user_locked = true; - /** * Insert an item into the current resource with the provided attributes. * Setting of the primary key column is not allowed and will be overwritten @@ -45,7 +41,7 @@ class api_cache extends crud { $attributes = []; $attributes['key'] = $key; $attributes['expires_at'] = date('Y-m-d H:i:s', time() + $duration); - $attributes['json_response_data'] = $response_data; + $attributes['response_data'] = $response_data; $attributes['request_resource'] = $api_call['resource']; $attributes['request_method'] = $api_call['method']; @@ -63,7 +59,7 @@ class api_cache extends crud { $attributes = []; $attributes['expires_at'] = date('Y-m-d H:i:s', time() + $duration); - $attributes['json_response_data'] = $response_data; + $attributes['response_data'] = $response_data; $attributes['api_cache_id'] = $cache_hit['api_cache_id']; return $this->update($attributes); diff --git a/api/cora/api_user.php b/api/cora/api_user.php index ecd83f8..b3c955c 100644 --- a/api/cora/api_user.php +++ b/api/cora/api_user.php @@ -12,8 +12,6 @@ namespace cora; */ class api_user extends crud { - public static $converged = []; - public static $user_locked = false; } diff --git a/api/cora/cora.php b/api/cora/cora.php index 222f17c..0d9a91d 100644 --- a/api/cora/cora.php +++ b/api/cora/cora.php @@ -330,7 +330,7 @@ final class cora { if($api_cache !== null) { // If there was a cache entry available, use that. - $this->response_data[$index] = $api_cache['json_response_data']; + $this->response_data[$index] = $api_cache['response_data']; $this->from_cache[$index] = true; $this->cached_until[$index] = date('c', strtotime($api_cache['expires_at'])); } else { diff --git a/api/cora/database.php b/api/cora/database.php index fba3df2..123eab5 100644 --- a/api/cora/database.php +++ b/api/cora/database.php @@ -38,6 +38,13 @@ final class database extends \mysqli { */ private static $transactionless_instance; + /** + * Column types + * + * @var array + */ + private static $types; + /** * Whether or not to use transactions in this connection. * @@ -63,7 +70,7 @@ final class database extends \mysqli { /** * The total time all queries have taken to execute. * - * @var float; + * @var float */ private $query_time = 0; @@ -348,6 +355,7 @@ final class database extends \mysqli { * FUNCTION DIRECTLY. THIS FUNCTION DOES NOT DO IT FOR YOU. * * @param string $query The query to execute. + * @param int $resultmode Just here because PHP requires it. * * @throws DuplicateEntryException if the query failed due to a duplicate * entry (unique key violation) @@ -356,7 +364,7 @@ final class database extends \mysqli { * * @return mixed The result directly from $mysqli->query. */ - public function query($query, $resultmode = NULL) { + public function query($query, $resultmode = null) { // If this was an insert, update or delete, start a transaction $query_type = substr(trim($query), 0, 6); if( @@ -486,10 +494,6 @@ final class database extends \mysqli { else if($field_info->type === 245) { $json_fields[] = $field_info->name; } - else if(substr($field_info->name, 0, 5) === 'json_') { - // TODO This will go away as soon as I switch to json type columns. - $json_fields[] = $field_info->name; - } } $results = []; @@ -505,6 +509,7 @@ final class database extends \mysqli { $row[$json_field] = json_decode($row[$json_field], true); } + // Diverge the converged column. if( isset($row['converged']) === true && @@ -590,7 +595,8 @@ final class database extends \mysqli { * @param array $attributes The attributes to set. * @param array $return_mode Either "row" or "id". Specifying row will * return the newly created row (does a database read). Specifying id will - * return just the ID of the created row. + * return just the ID of the created row instead of performing another query + * to get the whole inserted row. * * @throws \Exception If no attributes were specified. * @@ -599,9 +605,8 @@ final class database extends \mysqli { public function update($resource, $attributes, $return_mode = 'row') { $table = $this->get_table($resource); - // TODO This will go away as soon as I switch to json type columns. foreach($attributes as $key => $value) { - if(substr($key, 0, 5) === 'json_') { + if($this->get_type($resource, $key) === 'json') { if($value === null) { $attributes[$key] = null; } @@ -700,9 +705,8 @@ final class database extends \mysqli { public function create($resource, $attributes, $return_mode = 'row') { $table = $this->get_table($resource); - // TODO This will go away as soon as I switch to json type columns. foreach($attributes as $key => $value) { - if(substr($key, 0, 5) === 'json_') { + if($this->get_type($resource, $key) === 'json') { if($value === null) { $attributes[$key] = null; } @@ -769,6 +773,47 @@ final class database extends \mysqli { return end($class_parts); } + /** + * Get the type of a specific column. + * + * @param string $table The table. + * @param string $column The column. + * + * @return string The type. + */ + private function get_type($resource, $column) { + $table = $this->get_table($resource); + + // If this column is in converged, get the type from there. + if( + class_exists($resource) === true && // This will also call the autoloader to make sure it's loaded + isset($resource::$converged) === true && + isset($resource::$converged[$column]) === true + ) { + return $resource::$converged[$column]['type']; + } + + // Otherwise query the entire schema (and cache it) to see what the type is. + if(isset(self::$types) === false) { + self::$types = []; + $result = $this->query(' + select + `table_name`, + `column_name`, + `data_type` + from + `information_schema`.`columns` + where + `table_schema` = ' . $this->escape($this->setting->get('database_name')) . ' + '); + while($row = $result->fetch_assoc()) { + self::$types[$row['table_name'] . '.' . $row['column_name']] = $row['data_type']; + } + } + + return self::$types[$table . '.' . $column]; + } + /** * Attempt to get a database lock. * diff --git a/api/cora/session.php b/api/cora/session.php index 68c18d8..9c8c695 100644 --- a/api/cora/session.php +++ b/api/cora/session.php @@ -9,10 +9,6 @@ namespace cora; */ final class session { - public static $converged = []; - - public static $user_locked = true; - /** * The session_key for this session. * diff --git a/api/ecobee_sensor.php b/api/ecobee_sensor.php index 64acfc4..78c5fe5 100644 --- a/api/ecobee_sensor.php +++ b/api/ecobee_sensor.php @@ -15,10 +15,6 @@ class ecobee_sensor extends cora\crud { 'public' => [] ]; - public static $converged = []; - - public static $user_locked = true; - /** * Sync sensors. */ @@ -173,7 +169,7 @@ class ecobee_sensor extends cora\crud { 'type' => $api_sensor['type'], 'code' => (isset($api_sensor['code']) === true ? $api_sensor['code'] : null), 'in_use' => ($api_sensor['inUse'] === true ? 1 : 0), - 'json_capability' => $api_sensor['capability'], + 'capability' => $api_sensor['capability'], 'inactive' => 0 ] ); diff --git a/api/ecobee_thermostat.php b/api/ecobee_thermostat.php index e4c5d1b..d191bf0 100644 --- a/api/ecobee_thermostat.php +++ b/api/ecobee_thermostat.php @@ -15,10 +15,6 @@ class ecobee_thermostat extends cora\crud { 'public' => [] ]; - public static $converged = []; - - public static $user_locked = true; - /** * Sync thermostats. */ @@ -135,7 +131,7 @@ class ecobee_thermostat extends cora\crud { [ 'attributes' => [ 'ecobee_thermostat_id' => $ecobee_thermostat['ecobee_thermostat_id'], - 'json_alerts' => [] + 'alerts' => [] ] ] ); @@ -150,27 +146,27 @@ class ecobee_thermostat extends cora\crud { 'identifier' => $api_thermostat['identifier'], 'utc_time' => $api_thermostat['utcTime'], 'model_number' => $api_thermostat['modelNumber'], - 'json_runtime' => $api_thermostat['runtime'], - 'json_extended_runtime' => $api_thermostat['extendedRuntime'], - 'json_electricity' => $api_thermostat['electricity'], - 'json_settings' => $api_thermostat['settings'], - 'json_location' => $api_thermostat['location'], - 'json_program' => $api_thermostat['program'], - 'json_events' => $api_thermostat['events'], - 'json_device' => $api_thermostat['devices'], - 'json_technician' => $api_thermostat['technician'], - 'json_utility' => $api_thermostat['utility'], - 'json_management' => $api_thermostat['management'], - 'json_alerts' => $api_thermostat['alerts'], - 'json_weather' => $api_thermostat['weather'], - 'json_house_details' => $api_thermostat['houseDetails'], - 'json_oem_cfg' => $api_thermostat['oemCfg'], - 'json_equipment_status' => trim($api_thermostat['equipmentStatus']) !== '' ? explode(',', $api_thermostat['equipmentStatus']) : [], - 'json_notification_settings' => $api_thermostat['notificationSettings'], - 'json_privacy' => $api_thermostat['privacy'], - 'json_version' => $api_thermostat['version'], - 'json_remote_sensors' => $api_thermostat['remoteSensors'], - 'json_audio' => $api_thermostat['audio'], + 'runtime' => $api_thermostat['runtime'], + 'extended_runtime' => $api_thermostat['extendedRuntime'], + 'electricity' => $api_thermostat['electricity'], + 'settings' => $api_thermostat['settings'], + 'location' => $api_thermostat['location'], + 'program' => $api_thermostat['program'], + 'events' => $api_thermostat['events'], + 'device' => $api_thermostat['devices'], + 'technician' => $api_thermostat['technician'], + 'utility' => $api_thermostat['utility'], + 'management' => $api_thermostat['management'], + 'alerts' => $api_thermostat['alerts'], + 'weather' => $api_thermostat['weather'], + 'house_details' => $api_thermostat['houseDetails'], + 'oem_cfg' => $api_thermostat['oemCfg'], + 'equipment_status' => trim($api_thermostat['equipmentStatus']) !== '' ? explode(',', $api_thermostat['equipmentStatus']) : [], + 'notification_settings' => $api_thermostat['notificationSettings'], + 'privacy' => $api_thermostat['privacy'], + 'version' => $api_thermostat['version'], + 'remote_sensors' => $api_thermostat['remoteSensors'], + 'audio' => $api_thermostat['audio'], 'inactive' => 0 ] ); @@ -210,7 +206,7 @@ class ecobee_thermostat extends cora\crud { $attributes['property'] = $this->get_property($thermostat, $ecobee_thermostat); $attributes['filters'] = $this->get_filters($thermostat, $ecobee_thermostat); - $attributes['json_alerts'] = $this->get_alerts($thermostat, $ecobee_thermostat); + $attributes['alerts'] = $this->get_alerts($thermostat, $ecobee_thermostat); $attributes['weather'] = $this->get_weather($thermostat, $ecobee_thermostat); $attributes['time_zone'] = $this->get_time_zone($thermostat, $ecobee_thermostat); @@ -302,28 +298,28 @@ class ecobee_thermostat extends cora\crud { private function get_address($thermostat, $ecobee_thermostat) { $address_parts = []; - if(isset($ecobee_thermostat['json_location']['streetAddress']) === true) { - $address_parts[] = $ecobee_thermostat['json_location']['streetAddress']; + if(isset($ecobee_thermostat['location']['streetAddress']) === true) { + $address_parts[] = $ecobee_thermostat['location']['streetAddress']; } - if(isset($ecobee_thermostat['json_location']['city']) === true) { - $address_parts[] = $ecobee_thermostat['json_location']['city']; + if(isset($ecobee_thermostat['location']['city']) === true) { + $address_parts[] = $ecobee_thermostat['location']['city']; } - if(isset($ecobee_thermostat['json_location']['provinceState']) === true) { - $address_parts[] = $ecobee_thermostat['json_location']['provinceState']; + if(isset($ecobee_thermostat['location']['provinceState']) === true) { + $address_parts[] = $ecobee_thermostat['location']['provinceState']; } - if(isset($ecobee_thermostat['json_location']['postalCode']) === true) { - $address_parts[] = $ecobee_thermostat['json_location']['postalCode']; + if(isset($ecobee_thermostat['location']['postalCode']) === true) { + $address_parts[] = $ecobee_thermostat['location']['postalCode']; } if( - isset($ecobee_thermostat['json_location']['country']) === true && - trim($ecobee_thermostat['json_location']['country']) !== '' + isset($ecobee_thermostat['location']['country']) === true && + trim($ecobee_thermostat['location']['country']) !== '' ) { - if(preg_match('/(^USA?$)|(united.?states)/i', $ecobee_thermostat['json_location']['country']) === 1) { + if(preg_match('/(^USA?$)|(united.?states)/i', $ecobee_thermostat['location']['country']) === 1) { $country = 'USA'; } else { - $country = $ecobee_thermostat['json_location']['country']; + $country = $ecobee_thermostat['location']['country']; } } else { @@ -359,8 +355,8 @@ class ecobee_thermostat extends cora\crud { * "semiDetached", "townhouse", "Townhouse" */ $property['structure_type'] = null; - if(isset($ecobee_thermostat['json_house_details']['style']) === true) { - $structure_type = $ecobee_thermostat['json_house_details']['style']; + if(isset($ecobee_thermostat['house_details']['style']) === true) { + $structure_type = $ecobee_thermostat['house_details']['style']; if(preg_match('/^detached$/i', $structure_type) === 1) { $property['structure_type'] = 'detached'; } @@ -388,8 +384,8 @@ class ecobee_thermostat extends cora\crud { * Example values from ecobee: "0", "1", "2", "3", "4", "5", "8", "9", "10" */ $property['stories'] = null; - if(isset($ecobee_thermostat['json_house_details']['numberOfFloors']) === true) { - $stories = $ecobee_thermostat['json_house_details']['numberOfFloors']; + if(isset($ecobee_thermostat['house_details']['numberOfFloors']) === true) { + $stories = $ecobee_thermostat['house_details']['numberOfFloors']; if(ctype_digit((string) $stories) === true && $stories > 0) { $property['stories'] = (int) $stories; } @@ -404,8 +400,8 @@ class ecobee_thermostat extends cora\crud { * "9000", "9500", "10000" */ $property['square_feet'] = null; - if(isset($ecobee_thermostat['json_house_details']['size']) === true) { - $square_feet = $ecobee_thermostat['json_house_details']['size']; + if(isset($ecobee_thermostat['house_details']['size']) === true) { + $square_feet = $ecobee_thermostat['house_details']['size']; if(ctype_digit((string) $square_feet) === true && $square_feet > 0) { $property['square_feet'] = (int) $square_feet; } @@ -425,8 +421,8 @@ class ecobee_thermostat extends cora\crud { * "121", "122", "123", "124" */ $property['age'] = null; - if(isset($ecobee_thermostat['json_house_details']['age']) === true) { - $age = $ecobee_thermostat['json_house_details']['age']; + if(isset($ecobee_thermostat['house_details']['age']) === true) { + $age = $ecobee_thermostat['house_details']['age']; if(ctype_digit((string) $age) === true) { $property['age'] = (int) $age; } @@ -471,8 +467,8 @@ class ecobee_thermostat extends cora\crud { $sums = []; $min_timestamp = INF; - if(isset($ecobee_thermostat['json_notification_settings']['equipment']) === true) { - foreach($ecobee_thermostat['json_notification_settings']['equipment'] as $notification) { + if(isset($ecobee_thermostat['notification_settings']['equipment']) === true) { + foreach($ecobee_thermostat['notification_settings']['equipment'] as $notification) { if($notification['enabled'] === true && isset($supported_types[$notification['type']]) === true) { $key = $supported_types[$notification['type']]['key']; $sum_column = $supported_types[$notification['type']]['sum_column']; @@ -522,7 +518,7 @@ class ecobee_thermostat extends cora\crud { private function get_alerts($thermostat, $ecobee_thermostat) { // Get a list of all ecobee thermostat alerts $new_alerts = []; - foreach($ecobee_thermostat['json_alerts'] as $ecobee_thermostat_alert) { + foreach($ecobee_thermostat['alerts'] as $ecobee_thermostat_alert) { $alert = []; $alert['timestamp'] = date( 'Y-m-d H:i:s', @@ -539,7 +535,7 @@ class ecobee_thermostat extends cora\crud { } // Cool Differential Temperature - if($ecobee_thermostat['json_settings']['stage1CoolingDifferentialTemp'] / 10 === 0.5) { + if($ecobee_thermostat['settings']['stage1CoolingDifferentialTemp'] / 10 === 0.5) { $alert = [ 'timestamp' => date('Y-m-d H:i:s'), 'text' => 'Cool Differential Temperature is set to 0.5°F; we recommend at least 1.0°F', @@ -554,7 +550,7 @@ class ecobee_thermostat extends cora\crud { } // Heat Differential Temperature - if($ecobee_thermostat['json_settings']['stage1HeatingDifferentialTemp'] / 10 === 0.5) { + if($ecobee_thermostat['settings']['stage1HeatingDifferentialTemp'] / 10 === 0.5) { $alert = [ 'timestamp' => date('Y-m-d H:i:s'), 'text' => 'Heat Differential Temperature is set to 0.5°F; we recommend at least 1.0°F', @@ -570,13 +566,13 @@ class ecobee_thermostat extends cora\crud { // Get the guids for easy comparison $new_guids = array_column($new_alerts, 'guid'); - $existing_guids = array_column($thermostat['json_alerts'], 'guid'); + $existing_guids = array_column($thermostat['alerts'], 'guid'); $guids_to_add = array_diff($new_guids, $existing_guids); $guids_to_remove = array_diff($existing_guids, $new_guids); // Remove any removed alerts - $final_alerts = $thermostat['json_alerts']; + $final_alerts = $thermostat['alerts']; foreach($final_alerts as $key => $thermostat_alert) { if(in_array($thermostat_alert['guid'], $guids_to_remove) === true) { unset($final_alerts[$key]); @@ -652,8 +648,8 @@ class ecobee_thermostat extends cora\crud { private function get_detected_system_type($thermostat, $ecobee_thermostat) { $detected_system_type = []; - $settings = $ecobee_thermostat['json_settings']; - $devices = $ecobee_thermostat['json_device']; + $settings = $ecobee_thermostat['settings']; + $devices = $ecobee_thermostat['device']; // Get a list of all outputs. These get their type set when they get // connected to a wire so it's a pretty reliable way to see what's hooked @@ -743,15 +739,15 @@ class ecobee_thermostat extends cora\crud { 'condition' => null ]; - if(isset($ecobee_thermostat['json_weather']['weatherStation']) === true) { - $weather['station'] = $ecobee_thermostat['json_weather']['weatherStation']; + if(isset($ecobee_thermostat['weather']['weatherStation']) === true) { + $weather['station'] = $ecobee_thermostat['weather']['weatherStation']; } if( - isset($ecobee_thermostat['json_weather']['forecasts']) === true && - isset($ecobee_thermostat['json_weather']['forecasts'][0]) === true + isset($ecobee_thermostat['weather']['forecasts']) === true && + isset($ecobee_thermostat['weather']['forecasts'][0]) === true ) { - $ecobee_weather = $ecobee_thermostat['json_weather']['forecasts'][0]; + $ecobee_weather = $ecobee_thermostat['weather']['forecasts'][0]; if(isset($ecobee_weather['dewpoint']) === true) { $weather['dew_point'] = $ecobee_weather['dewpoint']; @@ -872,12 +868,12 @@ class ecobee_thermostat extends cora\crud { * @return The time zone. */ private function get_time_zone($thermostat, $ecobee_thermostat) { - $time_zone = $ecobee_thermostat['json_location']['timeZone']; + $time_zone = $ecobee_thermostat['location']['timeZone']; if (in_array($time_zone, timezone_identifiers_list()) === true) { return $time_zone; - } else if ($ecobee_thermostat['json_location']['timeZoneOffsetMinutes'] !== '') { - $offset_seconds = $ecobee_thermostat['json_location']['timeZoneOffsetMinutes'] * 60; + } else if ($ecobee_thermostat['location']['timeZoneOffsetMinutes'] !== '') { + $offset_seconds = $ecobee_thermostat['location']['timeZoneOffsetMinutes'] * 60; $time_zone = timezone_name_from_abbr('', $offset_seconds, 1); // Workaround for bug #44780 if ($time_zone === false) { diff --git a/api/ecobee_token.php b/api/ecobee_token.php index 5f766ab..dd61ed4 100644 --- a/api/ecobee_token.php +++ b/api/ecobee_token.php @@ -7,10 +7,6 @@ */ class ecobee_token extends cora\crud { - public static $converged = []; - - public static $user_locked = true; - /** * This should be called when connecting a new user. Get the access/refresh * tokens, then attach them to a brand new anonymous user. diff --git a/api/external_api_cache.php b/api/external_api_cache.php index 7d83bed..2ed18bd 100644 --- a/api/external_api_cache.php +++ b/api/external_api_cache.php @@ -7,8 +7,6 @@ */ class external_api_cache extends cora\crud { - public static $converged = []; - public static $user_locked = false; public function delete($id) { diff --git a/api/external_api_log.php b/api/external_api_log.php index 4e7cff6..4f67901 100644 --- a/api/external_api_log.php +++ b/api/external_api_log.php @@ -7,15 +7,6 @@ */ class external_api_log extends cora\crud { - public static $converged = [ - 'request' => [ - 'type' => 'json' - ], - 'response' => [ - 'type' => 'string' - ] - ]; - /** * Insert an item into the log table using the transactionless database * connection. diff --git a/api/patreon_token.php b/api/patreon_token.php index cc9b5fe..71cd7de 100644 --- a/api/patreon_token.php +++ b/api/patreon_token.php @@ -7,10 +7,6 @@ */ class patreon_token extends cora\crud { - public static $converged = []; - - public static $user_locked = true; - /** * Obtain Patreon access & refresh tokens. If a token already exists for * this user, overwrite it. diff --git a/api/sensor.php b/api/sensor.php index c0b1225..11b63a3 100644 --- a/api/sensor.php +++ b/api/sensor.php @@ -19,10 +19,6 @@ class sensor extends cora\crud { 'sync' => 300 // 5 Minutes ]; - public static $converged = []; - - public static $user_locked = true; - /** * Sync all sensors connected to this account. Once Nest support is * added this will need to check for all connected accounts and run the diff --git a/api/thermostat.php b/api/thermostat.php index b631aab..1063807 100644 --- a/api/thermostat.php +++ b/api/thermostat.php @@ -21,26 +21,6 @@ class thermostat extends cora\crud { 'sync' => 300 // 5 Minutes ]; - public static $converged = [ - 'filters' => [ - 'type' => 'json' - ], - 'temperature_profile' => [ - 'type' => 'json' - ], - 'property' => [ - 'type' => 'json' - ], - 'system_type' => [ - 'type' => 'json' - ], - 'weather' => [ - 'type' => 'json' - ] - ]; - - public static $user_locked = true; - /** * Sync all thermostats for the current user with their associated service. */ @@ -72,7 +52,7 @@ class thermostat extends cora\crud { */ public function dismiss_alert($thermostat_id, $guid) { $thermostat = $this->get($thermostat_id); - foreach($thermostat['json_alerts'] as &$alert) { + foreach($thermostat['alerts'] as &$alert) { if($alert['guid'] === $guid) { $alert['dismissed'] = true; break; @@ -81,7 +61,7 @@ class thermostat extends cora\crud { $this->update( [ 'thermostat_id' => $thermostat_id, - 'json_alerts' => $thermostat['json_alerts'] + 'alerts' => $thermostat['alerts'] ] ); } @@ -94,7 +74,7 @@ class thermostat extends cora\crud { */ public function restore_alert($thermostat_id, $guid) { $thermostat = $this->get($thermostat_id); - foreach($thermostat['json_alerts'] as &$alert) { + foreach($thermostat['alerts'] as &$alert) { if($alert['guid'] === $guid) { $alert['dismissed'] = false; break; @@ -103,7 +83,7 @@ class thermostat extends cora\crud { $this->update( [ 'thermostat_id' => $thermostat_id, - 'json_alerts' => $thermostat['json_alerts'] + 'alerts' => $thermostat['alerts'] ] ); } diff --git a/api/thermostat_group.php b/api/thermostat_group.php index 865423c..cefc001 100644 --- a/api/thermostat_group.php +++ b/api/thermostat_group.php @@ -26,17 +26,6 @@ class thermostat_group extends cora\crud { 'get_scores' => 604800 // 7 Days ]; - public static $converged = [ - 'temperature_profile' => [ - 'type' => 'json' - ], - 'weather' => [ - 'type' => 'json' - ] - ]; - - public static $user_locked = true; - /** * Generate the group temperature profile. * diff --git a/api/user.php b/api/user.php index 18370a4..a6cdd19 100644 --- a/api/user.php +++ b/api/user.php @@ -18,10 +18,6 @@ class user extends cora\crud { 'public' => [] ]; - public static $converged = []; - - public static $user_locked = true; - /** * Selects a user. * @@ -177,10 +173,10 @@ class user extends cora\crud { */ public function update_setting($key, $value) { $user = $this->get($this->session->get_user_id()); - if($user['json_settings'] === null) { + if($user['settings'] === null) { $settings = []; } else { - $settings = $user['json_settings']; + $settings = $user['settings']; } $settings[$key] = $value; @@ -189,7 +185,7 @@ class user extends cora\crud { $this->update( [ 'user_id' => $this->session->get_user_id(), - 'json_settings' => $settings + 'settings' => $settings ] ); } @@ -206,10 +202,10 @@ class user extends cora\crud { */ public function update_sync_status($key) { $user = $this->get($this->session->get_user_id()); - if($user['json_sync_status'] === null) { + if($user['sync_status'] === null) { $sync_status = []; } else { - $sync_status = $user['json_sync_status']; + $sync_status = $user['sync_status']; } $sync_status[$key] = date('Y-m-d H:i:s'); @@ -217,7 +213,7 @@ class user extends cora\crud { $this->update( [ 'user_id' => $this->session->get_user_id(), - 'json_sync_status' => $sync_status + 'sync_status' => $sync_status ] ); @@ -264,7 +260,7 @@ class user extends cora\crud { $this->update( [ 'user_id' => $this->session->get_user_id(), - 'json_patreon_status' => $include['attributes'] + 'patreon_status' => $include['attributes'] ] ); } @@ -275,7 +271,7 @@ class user extends cora\crud { $this->update( [ 'user_id' => $this->session->get_user_id(), - 'json_patreon_status' => null + 'patreon_status' => null ] ); } else { @@ -283,7 +279,7 @@ class user extends cora\crud { $this->update( [ 'user_id' => $this->session->get_user_id(), - 'json_patreon_status' => [ + 'patreon_status' => [ 'patron_status' => 'not_patron' ] ] diff --git a/js/beestat.js b/js/beestat.js index 27aaf4f..f22a401 100644 --- a/js/beestat.js +++ b/js/beestat.js @@ -47,7 +47,7 @@ beestat.get_climate = function(climate_ref) { thermostat.ecobee_thermostat_id ]; - var climates = ecobee_thermostat.json_program.climates; + var climates = ecobee_thermostat.program.climates; for (var i = 0; i < climates.length; i++) { if (climates[i].climateRef === climate_ref) { @@ -68,36 +68,36 @@ beestat.get_thermostat_color = function(thermostat_id) { ]; if ( - ecobee_thermostat.json_equipment_status.indexOf('compCool2') !== -1 || - ecobee_thermostat.json_equipment_status.indexOf('compCool1') !== -1 + ecobee_thermostat.equipment_status.indexOf('compCool2') !== -1 || + ecobee_thermostat.equipment_status.indexOf('compCool1') !== -1 ) { return beestat.style.color.blue.light; } else if ( - ecobee_thermostat.json_settings.hasHeatPump === true && + ecobee_thermostat.settings.hasHeatPump === true && ( - ecobee_thermostat.json_equipment_status.indexOf('auxHeat3') !== -1 || - ecobee_thermostat.json_equipment_status.indexOf('auxHeat2') !== -1 || - ecobee_thermostat.json_equipment_status.indexOf('auxHeat1') !== -1 || - ecobee_thermostat.json_equipment_status.indexOf('auxHotWater') !== -1 + ecobee_thermostat.equipment_status.indexOf('auxHeat3') !== -1 || + ecobee_thermostat.equipment_status.indexOf('auxHeat2') !== -1 || + ecobee_thermostat.equipment_status.indexOf('auxHeat1') !== -1 || + ecobee_thermostat.equipment_status.indexOf('auxHotWater') !== -1 ) ) { return beestat.style.color.red.base; } else if ( ( - ecobee_thermostat.json_settings.hasHeatPump === false && + ecobee_thermostat.settings.hasHeatPump === false && ( - ecobee_thermostat.json_equipment_status.indexOf('auxHeat3') !== -1 || - ecobee_thermostat.json_equipment_status.indexOf('auxHeat2') !== -1 || - ecobee_thermostat.json_equipment_status.indexOf('auxHeat1') !== -1 || - ecobee_thermostat.json_equipment_status.indexOf('compHotWater') !== -1 || - ecobee_thermostat.json_equipment_status.indexOf('auxHotWater') !== -1 + ecobee_thermostat.equipment_status.indexOf('auxHeat3') !== -1 || + ecobee_thermostat.equipment_status.indexOf('auxHeat2') !== -1 || + ecobee_thermostat.equipment_status.indexOf('auxHeat1') !== -1 || + ecobee_thermostat.equipment_status.indexOf('compHotWater') !== -1 || + ecobee_thermostat.equipment_status.indexOf('auxHotWater') !== -1 ) ) || ( - ecobee_thermostat.json_settings.hasHeatPump === true && + ecobee_thermostat.settings.hasHeatPump === true && ( - ecobee_thermostat.json_equipment_status.indexOf('heatPump1') !== -1 || - ecobee_thermostat.json_equipment_status.indexOf('heatPump2') !== -1 + ecobee_thermostat.equipment_status.indexOf('heatPump1') !== -1 || + ecobee_thermostat.equipment_status.indexOf('heatPump2') !== -1 ) ) ) { @@ -173,9 +173,9 @@ beestat.has_early_access = function() { var user = beestat.get_user(); return user.user_id === 1 || ( - user.json_patreon_status !== null && - user.json_patreon_status.patron_status === 'active_patron' && - user.json_patreon_status.currently_entitled_amount_cents >= 500 + user.patreon_status !== null && + user.patreon_status.patron_status === 'active_patron' && + user.patreon_status.currently_entitled_amount_cents >= 500 ); }; diff --git a/js/beestat/setting.js b/js/beestat/setting.js index 0a7de74..62a6872 100644 --- a/js/beestat/setting.js +++ b/js/beestat/setting.js @@ -26,8 +26,8 @@ beestat.setting = function(key, opt_value, opt_callback) { 'temperature_unit': '°F' }; - if (user.json_settings === null) { - user.json_settings = {}; + if (user.settings === null) { + user.settings = {}; } /* @@ -35,16 +35,16 @@ beestat.setting = function(key, opt_value, opt_callback) { * control. Just doing this so other parts of the application can be built out * properly. */ - if (user.json_settings.thermostat_id !== undefined) { - user.json_settings.thermostat_id = parseInt( - user.json_settings.thermostat_id, + if (user.settings.thermostat_id !== undefined) { + user.settings.thermostat_id = parseInt( + user.settings.thermostat_id, 10 ); } if (opt_value === undefined && typeof key !== 'object') { - if (user.json_settings[key] !== undefined) { - return user.json_settings[key]; + if (user.settings[key] !== undefined) { + return user.settings[key]; } else if (defaults[key] !== undefined) { return defaults[key]; } @@ -64,8 +64,8 @@ beestat.setting = function(key, opt_value, opt_callback) { var has_calls = false; for (var k in settings) { - if (user.json_settings[k] !== settings[k]) { - user.json_settings[k] = settings[k]; + if (user.settings[k] !== settings[k]) { + user.settings[k] = settings[k]; beestat.dispatcher.dispatchEvent('setting.' + k); diff --git a/js/component/alert.js b/js/component/alert.js index 14bc0fb..4aa76e4 100644 --- a/js/component/alert.js +++ b/js/component/alert.js @@ -262,7 +262,7 @@ beestat.component.alert.prototype.decorate_detail_ = function(parent) { ) .send(); - beestat.cache.thermostat[beestat.setting('thermostat_id')].json_alerts.forEach(function(alert) { + beestat.cache.thermostat[beestat.setting('thermostat_id')].alerts.forEach(function(alert) { if (alert.guid === self.alert_.guid) { alert.dismissed = true; } @@ -299,7 +299,7 @@ beestat.component.alert.prototype.decorate_detail_ = function(parent) { ) .send(); - beestat.cache.thermostat[beestat.setting('thermostat_id')].json_alerts.forEach(function(alert) { + beestat.cache.thermostat[beestat.setting('thermostat_id')].alerts.forEach(function(alert) { if (alert.guid === self.alert_.guid) { alert.dismissed = false; } diff --git a/js/component/card/alerts.js b/js/component/card/alerts.js index ce07c5a..987008c 100644 --- a/js/component/card/alerts.js +++ b/js/component/card/alerts.js @@ -40,7 +40,7 @@ beestat.component.card.alerts.prototype.decorate_contents_ = function(parent) { .set_color(beestat.style.color.bluegray.light) ).render(this.no_alerts_); - thermostat.json_alerts.forEach(function(alert) { + thermostat.alerts.forEach(function(alert) { var alert_component = new beestat.component.alert(alert); alert_component.addEventListener('click', function() { diff --git a/js/component/card/recent_activity.js b/js/component/card/recent_activity.js index 5991ca7..6f31b14 100755 --- a/js/component/card/recent_activity.js +++ b/js/component/card/recent_activity.js @@ -1045,7 +1045,7 @@ beestat.component.card.recent_activity.prototype.get_series_ = function() { thermostat.ecobee_thermostat_id ]; - this_calendar_event = 'calendar_event_' + ecobee_thermostat.json_program.schedule[day_of_week_index][chunk_of_day_index]; + this_calendar_event = 'calendar_event_' + ecobee_thermostat.program.schedule[day_of_week_index][chunk_of_day_index]; } else { if (runtime_thermostat.event === null) { if (runtime_thermostat.climate === null) { diff --git a/js/component/card/system.js b/js/component/card/system.js index 4e5a7e1..d29c8ba 100644 --- a/js/component/card/system.js +++ b/js/component/card/system.js @@ -160,56 +160,56 @@ beestat.component.card.system.prototype.decorate_equipment_ = function(parent) { var running_equipment = []; - if (ecobee_thermostat.json_equipment_status.indexOf('fan') !== -1) { + if (ecobee_thermostat.equipment_status.indexOf('fan') !== -1) { running_equipment.push('fan'); } - if (ecobee_thermostat.json_equipment_status.indexOf('ventilator') !== -1) { + if (ecobee_thermostat.equipment_status.indexOf('ventilator') !== -1) { running_equipment.push('ventilator'); } - if (ecobee_thermostat.json_equipment_status.indexOf('humidifier') !== -1) { + if (ecobee_thermostat.equipment_status.indexOf('humidifier') !== -1) { running_equipment.push('humidifier'); } - if (ecobee_thermostat.json_equipment_status.indexOf('dehumidifier') !== -1) { + if (ecobee_thermostat.equipment_status.indexOf('dehumidifier') !== -1) { running_equipment.push('dehumidifier'); } - if (ecobee_thermostat.json_equipment_status.indexOf('economizer') !== -1) { + if (ecobee_thermostat.equipment_status.indexOf('economizer') !== -1) { running_equipment.push('economizer'); } - if (ecobee_thermostat.json_equipment_status.indexOf('compCool2') !== -1) { + if (ecobee_thermostat.equipment_status.indexOf('compCool2') !== -1) { running_equipment.push('cool_2'); - } else if (ecobee_thermostat.json_equipment_status.indexOf('compCool1') !== -1) { + } else if (ecobee_thermostat.equipment_status.indexOf('compCool1') !== -1) { running_equipment.push('cool_1'); } - if (ecobee_thermostat.json_settings.hasHeatPump === true) { - if (ecobee_thermostat.json_equipment_status.indexOf('heatPump3') !== -1) { + if (ecobee_thermostat.settings.hasHeatPump === true) { + if (ecobee_thermostat.equipment_status.indexOf('heatPump3') !== -1) { running_equipment.push('heat_3'); - } else if (ecobee_thermostat.json_equipment_status.indexOf('heatPump2') !== -1) { + } else if (ecobee_thermostat.equipment_status.indexOf('heatPump2') !== -1) { running_equipment.push('heat_2'); - } else if (ecobee_thermostat.json_equipment_status.indexOf('heatPump') !== -1) { + } else if (ecobee_thermostat.equipment_status.indexOf('heatPump') !== -1) { running_equipment.push('heat_1'); } - if (ecobee_thermostat.json_equipment_status.indexOf('auxHeat3') !== -1) { + if (ecobee_thermostat.equipment_status.indexOf('auxHeat3') !== -1) { running_equipment.push('aux_3'); - } else if (ecobee_thermostat.json_equipment_status.indexOf('auxHeat2') !== -1) { + } else if (ecobee_thermostat.equipment_status.indexOf('auxHeat2') !== -1) { running_equipment.push('aux_2'); - } else if (ecobee_thermostat.json_equipment_status.indexOf('auxHeat1') !== -1) { + } else if (ecobee_thermostat.equipment_status.indexOf('auxHeat1') !== -1) { running_equipment.push('aux_1'); } - } else if (ecobee_thermostat.json_equipment_status.indexOf('auxHeat3') !== -1) { + } else if (ecobee_thermostat.equipment_status.indexOf('auxHeat3') !== -1) { running_equipment.push('heat_3'); - } else if (ecobee_thermostat.json_equipment_status.indexOf('auxHeat2') !== -1) { + } else if (ecobee_thermostat.equipment_status.indexOf('auxHeat2') !== -1) { running_equipment.push('heat_2'); - } else if (ecobee_thermostat.json_equipment_status.indexOf('auxHeat1') !== -1) { + } else if (ecobee_thermostat.equipment_status.indexOf('auxHeat1') !== -1) { running_equipment.push('heat_1'); } - if (ecobee_thermostat.json_equipment_status.indexOf('compHotWater') !== -1) { + if (ecobee_thermostat.equipment_status.indexOf('compHotWater') !== -1) { running_equipment.push('heat_1'); } - if (ecobee_thermostat.json_equipment_status.indexOf('auxHotWater') !== -1) { + if (ecobee_thermostat.equipment_status.indexOf('auxHotWater') !== -1) { running_equipment.push('aux_1'); } @@ -300,7 +300,7 @@ beestat.component.card.system.prototype.decorate_climate_ = function(parent) { ]; var climate = beestat.get_climate( - ecobee_thermostat.json_program.currentClimateRef + ecobee_thermostat.program.currentClimateRef ); var climate_container = $.createElement('div') @@ -389,26 +389,26 @@ beestat.component.card.system.prototype.get_subtitle_ = function() { ]; var climate = beestat.get_climate( - ecobee_thermostat.json_program.currentClimateRef + ecobee_thermostat.program.currentClimateRef ); // Is the temperature overridden? var override = ( - ecobee_thermostat.json_runtime.desiredHeat !== climate.heatTemp || - ecobee_thermostat.json_runtime.desiredCool !== climate.coolTemp + ecobee_thermostat.runtime.desiredHeat !== climate.heatTemp || + ecobee_thermostat.runtime.desiredCool !== climate.coolTemp ); // Get the heat/cool values to display. var heat; if (override === true) { - heat = ecobee_thermostat.json_runtime.desiredHeat / 10; + heat = ecobee_thermostat.runtime.desiredHeat / 10; } else { heat = climate.heatTemp / 10; } var cool; if (override === true) { - cool = ecobee_thermostat.json_runtime.desiredCool / 10; + cool = ecobee_thermostat.runtime.desiredCool / 10; } else { cool = climate.coolTemp / 10; } @@ -422,7 +422,7 @@ beestat.component.card.system.prototype.get_subtitle_ = function() { 'heat': 'Heat' }; - var hvac_mode = hvac_modes[ecobee_thermostat.json_settings.hvacMode]; + var hvac_mode = hvac_modes[ecobee_thermostat.settings.hvacMode]; heat = beestat.temperature({ 'temperature': heat @@ -433,7 +433,7 @@ beestat.component.card.system.prototype.get_subtitle_ = function() { var subtitle = hvac_mode; - if (ecobee_thermostat.json_settings.hvacMode !== 'off') { + if (ecobee_thermostat.settings.hvacMode !== 'off') { if (override === true) { subtitle += ' / Overridden'; } else { @@ -441,15 +441,15 @@ beestat.component.card.system.prototype.get_subtitle_ = function() { } } - if (ecobee_thermostat.json_settings.hvacMode === 'auto') { + if (ecobee_thermostat.settings.hvacMode === 'auto') { subtitle += ' / ' + heat + ' - ' + cool; } else if ( - ecobee_thermostat.json_settings.hvacMode === 'heat' || - ecobee_thermostat.json_settings.hvacMode === 'auxHeatOnly' + ecobee_thermostat.settings.hvacMode === 'heat' || + ecobee_thermostat.settings.hvacMode === 'auxHeatOnly' ) { subtitle += ' / ' + heat; } else if ( - ecobee_thermostat.json_settings.hvacMode === 'cool' + ecobee_thermostat.settings.hvacMode === 'cool' ) { subtitle += ' / ' + cool; } diff --git a/js/component/modal/patreon_hide.js b/js/component/modal/patreon_hide.js index a196cbd..189edee 100644 --- a/js/component/modal/patreon_hide.js +++ b/js/component/modal/patreon_hide.js @@ -69,8 +69,8 @@ beestat.component.modal.patreon_hide.prototype.hide_patreon_card_for_ = function */ beestat.component.modal.patreon_hide.prototype.is_active_patron_ = function() { var user = beestat.get_user(); - if (user.json_patreon_status !== null) { - return (user.json_patreon_status.patron_status === 'active_patron'); + if (user.patreon_status !== null) { + return (user.patreon_status.patron_status === 'active_patron'); } return null; }; diff --git a/js/component/modal/thermostat_info.js b/js/component/modal/thermostat_info.js index e5c1790..25fcca8 100644 --- a/js/component/modal/thermostat_info.js +++ b/js/component/modal/thermostat_info.js @@ -32,15 +32,15 @@ beestat.component.modal.thermostat_info.prototype.decorate_contents_ = function( }, { 'name': 'Firmware Revision', - 'value': ecobee_thermostat.json_version.thermostatFirmwareVersion + 'value': ecobee_thermostat.version.thermostatFirmwareVersion }, { 'name': 'Weather Station', - 'value': ecobee_thermostat.json_weather.weatherStation + 'value': ecobee_thermostat.weather.weatherStation }, { 'name': 'First Connected', - 'value': moment.utc(ecobee_thermostat.json_runtime.firstConnected).local() + 'value': moment.utc(ecobee_thermostat.runtime.firstConnected).local() .format('MMM Do, YYYY') } ]; diff --git a/js/layer/dashboard.js b/js/layer/dashboard.js index b31b788..d6a619b 100644 --- a/js/layer/dashboard.js +++ b/js/layer/dashboard.js @@ -51,8 +51,8 @@ beestat.layer.dashboard.prototype.decorate_ = function(parent) { var user = beestat.get_user(); if ( - user.json_patreon_status !== null && - user.json_patreon_status.patron_status === 'active_patron' + user.patreon_status !== null && + user.patreon_status.patron_status === 'active_patron' ) { show_patreon_card = false; } diff --git a/js/layer/load.js b/js/layer/load.js index ec5b8b4..2a8e337 100644 --- a/js/layer/load.js +++ b/js/layer/load.js @@ -179,15 +179,15 @@ beestat.layer.load.prototype.decorate_ = function(parent) { beestat.setting('temperature_unit', thermostat.temperature_unit); // Rename series if only one stage is available. - if (ecobee_thermostat.json_settings.coolStages === 1) { + if (ecobee_thermostat.settings.coolStages === 1) { beestat.series.sum_compressor_cool_1.name = 'Cool'; } - if (ecobee_thermostat.json_settings.heatStages === 1) { + if (ecobee_thermostat.settings.heatStages === 1) { beestat.series.sum_compressor_heat_1.name = 'Heat'; } // Fix some other stuff for non-heat-pump. - if (ecobee_thermostat.json_settings.hasHeatPump === false) { + if (ecobee_thermostat.settings.hasHeatPump === false) { beestat.series.auxiliary_heat_1.name = beestat.series.sum_compressor_heat_1.name; beestat.series.auxiliary_heat_1.color =