Archived
1
0

Support for many thermostats

Uses the device ID to support several thermostats. Pretty simple - only
setup is now an array of devices, now a single device. However, many
changes follow...
This commit is contained in:
dorfl68
2016-01-19 22:29:04 -05:00
parent f9b7276cb6
commit 9a4f57b5bb
14 changed files with 568 additions and 469 deletions

View File

@@ -2,41 +2,47 @@
include('settings/globals.php');
$valid_thermostats = ["honeywell"];
if(in_array(THERMOSTAT_TYPE,$valid_thermostats)){
require('thermostats/'.THERMOSTAT_TYPE.'/scrape.php');
require('thermostats/'.THERMOSTAT_TYPE.'/scrape.php');
require('thermostats/'.THERMOSTAT_TYPE.'/logininfo.php');
} else{
die("Invalid THERMOSTAT_TYPE set in settings/globals.php");
}
$data = getCurrentInfo();
$conn = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$good_columns = array("coolLowerSetpLimit","coolNextPeriod","coolSetpoint","coolUpperSetptLimit","deviceID","dispTemperature","displayedUnits","heatLowerSetptLimit","heatNextPeriod","heatSetpoint","heatUpperSetptLimit","isInVacationHoldMode","schedCoolSp","schedHeatSp","scheduleCapable","statusCool","statusHeat","systemSwitchPosition","weatherHumidity","weatherPhrase","weatherTemperature");
$clean_data = array();
foreach($good_columns as $col){
if(isset($data[$col])){
$clean_data[$col] = $data[$col];
}
}
$columns = implode(", ",array_keys($clean_data));
$values = implode(", ", array_values($clean_data));
$sql = "INSERT INTO `stat`(" . $columns . ") VALUES (" . $values.")";
$result = $conn->query($sql);
echo $sql;
echo "\n";
echo $result;
if (!$result) {
printf("Errormessage: %s\n", $conn->error);
}
// dorfl added simple loop
for ($i = 0; $i <enumerate_thermostats(); $i++) { // all thermostats
$data = getCurrentInfo($i); // changed info!
$conn = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$good_columns = array("coolLowerSetpLimit","coolNextPeriod","coolSetpoint","coolUpperSetptLimit","deviceID","dispTemperature","displayedUnits","heatLowerSetptLimit","heatNextPeriod","heatSetpoint","heatUpperSetptLimit","isInVacationHoldMode","schedCoolSp","schedHeatSp","scheduleCapable","statusCool","statusHeat","systemSwitchPosition","weatherHumidity","weatherPhrase","weatherTemperature");
$clean_data = array();
foreach($good_columns as $col){
if(isset($data[$col])){
$clean_data[$col] = $data[$col];
}
}
$columns = implode(", ",array_keys($clean_data));
$values = implode(", ", array_values($clean_data));
$sql = "INSERT INTO `stat`(" . $columns . ") VALUES (" . $values.")";
$result = $conn->query($sql);
echo $sql;
echo "\n";
echo $result;
if (!$result) {
printf("Errormessage: %s\n", $conn->error);
}
} // end for thermostats
$conn->close();