mirror of
https://github.com/beestat/app.git
synced 2025-05-24 02:14:03 -04:00
Added ability to manually manage thermostats
This commit is contained in:
parent
f57e4f123c
commit
969b6ada12
@ -119,151 +119,110 @@ class ecobee_sensor extends cora\crud {
|
|||||||
*/
|
*/
|
||||||
];
|
];
|
||||||
|
|
||||||
try {
|
// Get a list of all registered thermostats.
|
||||||
/**
|
$response = $this->api(
|
||||||
* This will force the device sync to use the secondary method that uses
|
'ecobee',
|
||||||
* the undocumented API calls instead of the normal GET "registered"
|
'ecobee_api',
|
||||||
* thermostats. This fixes an issue where beestat never sees shared
|
[
|
||||||
* thermostats if there is at least one registered thermostat.
|
'method' => 'GET',
|
||||||
*/
|
'endpoint' => 'thermostat',
|
||||||
$user = $this->api('user', 'get', $this->session->get_user_id());
|
'arguments' => [
|
||||||
if(
|
'body' => json_encode([
|
||||||
isset($user['settings']['app']) === true &&
|
'selection' => array_merge(
|
||||||
isset($user['settings']['app']['prefer_secondary_device_sync']) === true &&
|
[
|
||||||
$user['settings']['app']['prefer_secondary_device_sync'] === true
|
'selectionType' => 'registered',
|
||||||
) {
|
'selectionMatch' => ''
|
||||||
throw new cora\exception('No thermostats found.', 10511, false, null, false);
|
],
|
||||||
}
|
$include
|
||||||
|
)
|
||||||
$response = $this->api(
|
])
|
||||||
'ecobee',
|
|
||||||
'ecobee_api',
|
|
||||||
[
|
|
||||||
'method' => 'GET',
|
|
||||||
'endpoint' => 'thermostat',
|
|
||||||
'arguments' => [
|
|
||||||
'body' => json_encode([
|
|
||||||
'selection' => array_merge(
|
|
||||||
[
|
|
||||||
'selectionType' => 'registered',
|
|
||||||
'selectionMatch' => ''
|
|
||||||
],
|
|
||||||
$include
|
|
||||||
)
|
|
||||||
])
|
|
||||||
]
|
|
||||||
]
|
]
|
||||||
);
|
]
|
||||||
if(count($response['thermostatList']) === 0) {
|
);
|
||||||
throw new cora\exception('No thermostats found.', 10511, false, null, false);
|
$registered_identifiers = [];
|
||||||
}
|
foreach($response['thermostatList'] as $api_thermostat) {
|
||||||
} catch(cora\exception $e) {
|
$registered_identifiers[] = $api_thermostat['identifier'];
|
||||||
// If no thermostats found (ie. not the owner of any homes that contain a thermostat)
|
}
|
||||||
if($e->getCode() === 10511) {
|
|
||||||
$homes = $this->api(
|
// Get a list of manually added thermostats.
|
||||||
|
$manual_ecobee_thermostats = $this->api(
|
||||||
|
'ecobee_thermostat',
|
||||||
|
'read',
|
||||||
|
[
|
||||||
|
'attributes' => [
|
||||||
|
'model_number' => null
|
||||||
|
]
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
// For each of the manually added ones, check and see if ecobee gives a
|
||||||
|
// result. If so, store that identifier as good. If not, inactivate the
|
||||||
|
// manually added ecobee_thermostat row.
|
||||||
|
$manual_identifiers = [];
|
||||||
|
foreach($manual_ecobee_thermostats as $manual_ecobee_thermostat) {
|
||||||
|
try {
|
||||||
|
$response = $this->api(
|
||||||
'ecobee',
|
'ecobee',
|
||||||
'ecobee_api',
|
'ecobee_api',
|
||||||
[
|
[
|
||||||
'method' => 'GET',
|
'method' => 'GET',
|
||||||
'endpoint' => 'https://home.hm-prod.ecobee.com/homes',
|
'endpoint' => 'thermostat',
|
||||||
'arguments' => [
|
'arguments' => [
|
||||||
|
'body' => json_encode([
|
||||||
|
'selection' => array_merge(
|
||||||
|
[
|
||||||
|
'selectionType' => 'thermostats',
|
||||||
|
'selectionMatch' => $manual_ecobee_thermostat['identifier']
|
||||||
|
],
|
||||||
|
$include
|
||||||
|
)
|
||||||
|
])
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
$home_ids = array_column($homes['homes'], 'homeID');
|
foreach($response['thermostatList'] as $api_thermostat) {
|
||||||
|
$manual_identifiers[] = $api_thermostat['identifier'];
|
||||||
$serial_numbers = [];
|
}
|
||||||
foreach($home_ids as $home_id) {
|
} catch(\Exception $e) {
|
||||||
$devices = $this->api(
|
$this->api(
|
||||||
'ecobee',
|
'ecobee_thermostat',
|
||||||
'ecobee_api',
|
'update',
|
||||||
[
|
[
|
||||||
'method' => 'GET',
|
'attributes' => [
|
||||||
'endpoint' => 'https://home.hm-prod.ecobee.com/home/' . $home_id . '/devices',
|
'ecobee_thermostat_id' => $manual_ecobee_thermostat['ecobee_thermostat_id'],
|
||||||
'arguments' => [
|
'inactive' => 1
|
||||||
]
|
|
||||||
]
|
]
|
||||||
);
|
]
|
||||||
|
);
|
||||||
/**
|
|
||||||
* This is a select distinct from ecobee_thermostat. Ideally it
|
|
||||||
* would be possible to send *all* serial numbers from the devices
|
|
||||||
* call to the GET->thermostat API call, but that throws an error if
|
|
||||||
* you include a serial number for something that's not a
|
|
||||||
* thermostat. So I have to keep this array to identify valid serial
|
|
||||||
* numbers.
|
|
||||||
*/
|
|
||||||
$model_numbers = [
|
|
||||||
'athenaSmart',
|
|
||||||
'apolloSmart',
|
|
||||||
'idtSmart',
|
|
||||||
'nikeSmart',
|
|
||||||
'siSmart',
|
|
||||||
'corSmart',
|
|
||||||
'vulcanSmart',
|
|
||||||
'aresSmart',
|
|
||||||
'artemisSmart'
|
|
||||||
];
|
|
||||||
|
|
||||||
foreach($devices['devices'] as $device) {
|
|
||||||
if(in_array($device['modelNumber'], $model_numbers) === true) {
|
|
||||||
$serial_numbers[] = $device['serialNumber'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(count($serial_numbers) > 0) {
|
|
||||||
try {
|
|
||||||
$response = $this->api(
|
|
||||||
'ecobee',
|
|
||||||
'ecobee_api',
|
|
||||||
[
|
|
||||||
'method' => 'GET',
|
|
||||||
'endpoint' => 'thermostat',
|
|
||||||
'arguments' => [
|
|
||||||
'body' => json_encode([
|
|
||||||
'selection' => array_merge(
|
|
||||||
[
|
|
||||||
'selectionType' => 'thermostats',
|
|
||||||
'selectionMatch' => implode(',', $serial_numbers),
|
|
||||||
],
|
|
||||||
$include
|
|
||||||
)
|
|
||||||
])
|
|
||||||
]
|
|
||||||
]
|
|
||||||
);
|
|
||||||
} catch(cora\exception $e) {
|
|
||||||
/**
|
|
||||||
* For some reason, I can get a serial number in the /homes data
|
|
||||||
* and still get no results from the /thermostat endpoint. Likely
|
|
||||||
* due to two data sources not being in sync. Catch that exception
|
|
||||||
* and let the code continue so any existing thermostats still get
|
|
||||||
* inactivated.
|
|
||||||
*
|
|
||||||
* Also have to fabricate the $response a bit.
|
|
||||||
*/
|
|
||||||
if($e->getCode() === 10511) {
|
|
||||||
$response = [
|
|
||||||
'thermostatList' => []
|
|
||||||
];
|
|
||||||
} else {
|
|
||||||
throw new cora\exception($e->getMessage(), $e->getCode(), $e->getReportable(), $e->getExtraInfo(), $e->getRollback());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* At this point, $response will either be populated with results,
|
|
||||||
* or have an empty thermostatList attribute. The code can continue
|
|
||||||
* on as it will inactivate any thermostats that were not found.
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw new cora\exception($e->getMessage(), $e->getCode(), $e->getReportable(), $e->getExtraInfo(), $e->getRollback());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get a unique list of identifiers.
|
||||||
|
$identifiers = array_unique(array_merge($registered_identifiers, $manual_identifiers));
|
||||||
|
|
||||||
|
// Get all of the thermostats from ecobee.
|
||||||
|
$response = $this->api(
|
||||||
|
'ecobee',
|
||||||
|
'ecobee_api',
|
||||||
|
[
|
||||||
|
'method' => 'GET',
|
||||||
|
'endpoint' => 'thermostat',
|
||||||
|
'arguments' => [
|
||||||
|
'body' => json_encode([
|
||||||
|
'selection' => array_merge(
|
||||||
|
[
|
||||||
|
'selectionType' => 'thermostats',
|
||||||
|
'selectionMatch' => implode(',', $identifiers)
|
||||||
|
],
|
||||||
|
$include
|
||||||
|
)
|
||||||
|
])
|
||||||
|
]
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
// Loop over the returned sensors and create/update them as necessary.
|
// Loop over the returned sensors and create/update them as necessary.
|
||||||
$sensor_ids_to_keep = [];
|
$sensor_ids_to_keep = [];
|
||||||
foreach($response['thermostatList'] as $thermostat_api) {
|
foreach($response['thermostatList'] as $thermostat_api) {
|
||||||
|
@ -12,9 +12,34 @@ class ecobee_thermostat extends cora\crud {
|
|||||||
'private' => [
|
'private' => [
|
||||||
'read_id'
|
'read_id'
|
||||||
],
|
],
|
||||||
'public' => []
|
'public' => ['create', 'update']
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If an ecobee_thermostat row with the same identifier already exists,
|
||||||
|
* reactivate it. This avoids creating duplicates or fixes if you
|
||||||
|
* accidentally remove your thermostat so it doesn't re-sync.
|
||||||
|
*
|
||||||
|
* @param array $attributes An array of attributes to set for this item
|
||||||
|
*
|
||||||
|
* @return mixed The id of the inserted row.
|
||||||
|
*/
|
||||||
|
public function create($attributes) {
|
||||||
|
$existing_ecobee_thermostat = $this->get([
|
||||||
|
'identifier' => $attributes['identifier']
|
||||||
|
]);
|
||||||
|
|
||||||
|
if($existing_ecobee_thermostat !== null) {
|
||||||
|
return $this->update([
|
||||||
|
'ecobee_thermostat_id' => $existing_ecobee_thermostat['ecobee_thermostat_id'],
|
||||||
|
'inactive' => 0
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
return $this->create($attributes);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sync thermostats.
|
* Sync thermostats.
|
||||||
*/
|
*/
|
||||||
@ -82,151 +107,109 @@ class ecobee_thermostat extends cora\crud {
|
|||||||
*/
|
*/
|
||||||
];
|
];
|
||||||
|
|
||||||
try {
|
// Get a list of all registered thermostats.
|
||||||
/**
|
$response = $this->api(
|
||||||
* This will force the device sync to use the secondary method that uses
|
'ecobee',
|
||||||
* the undocumented API calls instead of the normal GET "registered"
|
'ecobee_api',
|
||||||
* thermostats. This fixes an issue where beestat never sees shared
|
[
|
||||||
* thermostats if there is at least one registered thermostat.
|
'method' => 'GET',
|
||||||
*/
|
'endpoint' => 'thermostat',
|
||||||
$user = $this->api('user', 'get', $this->session->get_user_id());
|
'arguments' => [
|
||||||
if(
|
'body' => json_encode([
|
||||||
isset($user['settings']['app']) === true &&
|
'selection' => array_merge(
|
||||||
isset($user['settings']['app']['prefer_secondary_device_sync']) === true &&
|
[
|
||||||
$user['settings']['app']['prefer_secondary_device_sync'] === true
|
'selectionType' => 'registered',
|
||||||
) {
|
'selectionMatch' => ''
|
||||||
throw new cora\exception('No thermostats found.', 10511, false, null, false);
|
],
|
||||||
}
|
$include
|
||||||
|
)
|
||||||
$response = $this->api(
|
])
|
||||||
'ecobee',
|
|
||||||
'ecobee_api',
|
|
||||||
[
|
|
||||||
'method' => 'GET',
|
|
||||||
'endpoint' => 'thermostat',
|
|
||||||
'arguments' => [
|
|
||||||
'body' => json_encode([
|
|
||||||
'selection' => array_merge(
|
|
||||||
[
|
|
||||||
'selectionType' => 'registered',
|
|
||||||
'selectionMatch' => ''
|
|
||||||
],
|
|
||||||
$include
|
|
||||||
)
|
|
||||||
])
|
|
||||||
]
|
|
||||||
]
|
]
|
||||||
);
|
]
|
||||||
if(count($response['thermostatList']) === 0) {
|
);
|
||||||
throw new cora\exception('No thermostats found.', 10511, false, null, false);
|
$registered_identifiers = [];
|
||||||
}
|
foreach($response['thermostatList'] as $api_thermostat) {
|
||||||
} catch(cora\exception $e) {
|
$registered_identifiers[] = $api_thermostat['identifier'];
|
||||||
// If no thermostats found (ie. not the owner of any homes that contain a thermostat)
|
}
|
||||||
if($e->getCode() === 10511) {
|
|
||||||
$homes = $this->api(
|
// Get a list of manually added thermostats.
|
||||||
|
$manual_ecobee_thermostats = $this->api(
|
||||||
|
'ecobee_thermostat',
|
||||||
|
'read',
|
||||||
|
[
|
||||||
|
'attributes' => [
|
||||||
|
'model_number' => null
|
||||||
|
]
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
// For each of the manually added ones, check and see if ecobee gives a
|
||||||
|
// result. If so, store that identifier as good. If not, inactivate the
|
||||||
|
// manually added ecobee_thermostat row.
|
||||||
|
$manual_identifiers = [];
|
||||||
|
foreach($manual_ecobee_thermostats as $manual_ecobee_thermostat) {
|
||||||
|
try {
|
||||||
|
$response = $this->api(
|
||||||
'ecobee',
|
'ecobee',
|
||||||
'ecobee_api',
|
'ecobee_api',
|
||||||
[
|
[
|
||||||
'method' => 'GET',
|
'method' => 'GET',
|
||||||
'endpoint' => 'https://home.hm-prod.ecobee.com/homes',
|
'endpoint' => 'thermostat',
|
||||||
'arguments' => [
|
'arguments' => [
|
||||||
|
'body' => json_encode([
|
||||||
|
'selection' => array_merge(
|
||||||
|
[
|
||||||
|
'selectionType' => 'thermostats',
|
||||||
|
'selectionMatch' => $manual_ecobee_thermostat['identifier']
|
||||||
|
],
|
||||||
|
$include
|
||||||
|
)
|
||||||
|
])
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
$home_ids = array_column($homes['homes'], 'homeID');
|
foreach($response['thermostatList'] as $api_thermostat) {
|
||||||
|
$manual_identifiers[] = $api_thermostat['identifier'];
|
||||||
$serial_numbers = [];
|
}
|
||||||
foreach($home_ids as $home_id) {
|
} catch(\Exception $e) {
|
||||||
$devices = $this->api(
|
$this->api(
|
||||||
'ecobee',
|
'ecobee_thermostat',
|
||||||
'ecobee_api',
|
'update',
|
||||||
[
|
[
|
||||||
'method' => 'GET',
|
'attributes' => [
|
||||||
'endpoint' => 'https://home.hm-prod.ecobee.com/home/' . $home_id . '/devices',
|
'ecobee_thermostat_id' => $manual_ecobee_thermostat['ecobee_thermostat_id'],
|
||||||
'arguments' => [
|
'inactive' => 1
|
||||||
]
|
|
||||||
]
|
]
|
||||||
);
|
]
|
||||||
|
);
|
||||||
/**
|
|
||||||
* This is a select distinct from ecobee_thermostat. Ideally it
|
|
||||||
* would be possible to send *all* serial numbers from the devices
|
|
||||||
* call to the GET->thermostat API call, but that throws an error if
|
|
||||||
* you include a serial number for something that's not a
|
|
||||||
* thermostat. So I have to keep this array to identify valid serial
|
|
||||||
* numbers.
|
|
||||||
*/
|
|
||||||
$model_numbers = [
|
|
||||||
'athenaSmart',
|
|
||||||
'apolloSmart',
|
|
||||||
'idtSmart',
|
|
||||||
'nikeSmart',
|
|
||||||
'siSmart',
|
|
||||||
'corSmart',
|
|
||||||
'vulcanSmart',
|
|
||||||
'aresSmart',
|
|
||||||
'artemisSmart'
|
|
||||||
];
|
|
||||||
|
|
||||||
foreach($devices['devices'] as $device) {
|
|
||||||
if(in_array($device['modelNumber'], $model_numbers) === true) {
|
|
||||||
$serial_numbers[] = $device['serialNumber'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(count($serial_numbers) > 0) {
|
|
||||||
try {
|
|
||||||
$response = $this->api(
|
|
||||||
'ecobee',
|
|
||||||
'ecobee_api',
|
|
||||||
[
|
|
||||||
'method' => 'GET',
|
|
||||||
'endpoint' => 'thermostat',
|
|
||||||
'arguments' => [
|
|
||||||
'body' => json_encode([
|
|
||||||
'selection' => array_merge(
|
|
||||||
[
|
|
||||||
'selectionType' => 'thermostats',
|
|
||||||
'selectionMatch' => implode(',', $serial_numbers),
|
|
||||||
],
|
|
||||||
$include
|
|
||||||
)
|
|
||||||
])
|
|
||||||
]
|
|
||||||
]
|
|
||||||
);
|
|
||||||
} catch(cora\exception $e) {
|
|
||||||
/**
|
|
||||||
* For some reason, I can get a serial number in the /homes data
|
|
||||||
* and still get no results from the /thermostat endpoint. Likely
|
|
||||||
* due to two data sources not being in sync. Catch that exception
|
|
||||||
* and let the code continue so any existing thermostats still get
|
|
||||||
* inactivated.
|
|
||||||
*
|
|
||||||
* Also have to fabricate the $response a bit.
|
|
||||||
*/
|
|
||||||
if($e->getCode() === 10511) {
|
|
||||||
$response = [
|
|
||||||
'thermostatList' => []
|
|
||||||
];
|
|
||||||
} else {
|
|
||||||
throw new cora\exception($e->getMessage(), $e->getCode(), $e->getReportable(), $e->getExtraInfo(), $e->getRollback());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* At this point, $response will either be populated with results,
|
|
||||||
* or have an empty thermostatList attribute. The code can continue
|
|
||||||
* on as it will inactivate any thermostats that were not found.
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw new cora\exception($e->getMessage(), $e->getCode(), $e->getReportable(), $e->getExtraInfo(), $e->getRollback());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get a unique list of identifiers.
|
||||||
|
$identifiers = array_unique(array_merge($registered_identifiers, $manual_identifiers));
|
||||||
|
|
||||||
|
// Get all of the thermostats from ecobee.
|
||||||
|
$response = $this->api(
|
||||||
|
'ecobee',
|
||||||
|
'ecobee_api',
|
||||||
|
[
|
||||||
|
'method' => 'GET',
|
||||||
|
'endpoint' => 'thermostat',
|
||||||
|
'arguments' => [
|
||||||
|
'body' => json_encode([
|
||||||
|
'selection' => array_merge(
|
||||||
|
[
|
||||||
|
'selectionType' => 'thermostats',
|
||||||
|
'selectionMatch' => implode(',', $identifiers)
|
||||||
|
],
|
||||||
|
$include
|
||||||
|
)
|
||||||
|
])
|
||||||
|
]
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
// Loop over the returned thermostats and create/update them as necessary.
|
// Loop over the returned thermostats and create/update them as necessary.
|
||||||
$thermostat_ids_to_keep = [];
|
$thermostat_ids_to_keep = [];
|
||||||
$email_addresses = [];
|
$email_addresses = [];
|
||||||
|
@ -23,6 +23,7 @@ beestat.user.stripe_is_active = function() {
|
|||||||
for (let i = 0; i < stripe_events.length; i++) {
|
for (let i = 0; i < stripe_events.length; i++) {
|
||||||
if (
|
if (
|
||||||
stripe_events[i].type === 'invoice.paid' &&
|
stripe_events[i].type === 'invoice.paid' &&
|
||||||
|
// This is a bug. It counts anyone who has contributed ever via stripe as a supporter.
|
||||||
moment.unix(stripe_events[i].data.period_end).isAfter(moment()) === false
|
moment.unix(stripe_events[i].data.period_end).isAfter(moment()) === false
|
||||||
) {
|
) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -2,6 +2,19 @@
|
|||||||
* Setting
|
* Setting
|
||||||
*/
|
*/
|
||||||
beestat.component.card.manage_thermostats = function() {
|
beestat.component.card.manage_thermostats = function() {
|
||||||
|
const self = this;
|
||||||
|
|
||||||
|
var change_function = beestat.debounce(function() {
|
||||||
|
self.rerender();
|
||||||
|
}, 10);
|
||||||
|
|
||||||
|
beestat.dispatcher.addEventListener(
|
||||||
|
[
|
||||||
|
'cache.ecobee_thermostat'
|
||||||
|
],
|
||||||
|
change_function
|
||||||
|
);
|
||||||
|
|
||||||
beestat.component.card.apply(this, arguments);
|
beestat.component.card.apply(this, arguments);
|
||||||
};
|
};
|
||||||
beestat.extend(beestat.component.card.manage_thermostats, beestat.component.card);
|
beestat.extend(beestat.component.card.manage_thermostats, beestat.component.card);
|
||||||
@ -12,6 +25,8 @@ beestat.extend(beestat.component.card.manage_thermostats, beestat.component.card
|
|||||||
* @param {rocket.Elements} parent Parent
|
* @param {rocket.Elements} parent Parent
|
||||||
*/
|
*/
|
||||||
beestat.component.card.manage_thermostats.prototype.decorate_contents_ = function(parent) {
|
beestat.component.card.manage_thermostats.prototype.decorate_contents_ = function(parent) {
|
||||||
|
const self = this;
|
||||||
|
|
||||||
var p = document.createElement('p');
|
var p = document.createElement('p');
|
||||||
p.innerText = 'Thermostats directly connected to your ecobee account are automatically added and synced. In some cases, shared thermostats cannot be automatically detected. Add them here.';
|
p.innerText = 'Thermostats directly connected to your ecobee account are automatically added and synced. In some cases, shared thermostats cannot be automatically detected. Add them here.';
|
||||||
parent.appendChild(p);
|
parent.appendChild(p);
|
||||||
@ -19,22 +34,21 @@ beestat.component.card.manage_thermostats.prototype.decorate_contents_ = functio
|
|||||||
// Existing
|
// Existing
|
||||||
(new beestat.component.title('Existing Thermostats')).render(parent);
|
(new beestat.component.title('Existing Thermostats')).render(parent);
|
||||||
|
|
||||||
var sorted_thermostats = $.values(beestat.cache.thermostat)
|
var sorted_ecobee_thermostats = $.values(beestat.cache.ecobee_thermostat)
|
||||||
.sort(function(a, b) {
|
.sort(function(a, b) {
|
||||||
return a.name > b.name;
|
return a.name > b.name;
|
||||||
});
|
});
|
||||||
|
|
||||||
const table = document.createElement('table');
|
const table = document.createElement('table');
|
||||||
sorted_thermostats.forEach(function(thermostat) {
|
sorted_ecobee_thermostats.forEach(function(ecobee_thermostat) {
|
||||||
const ecobee_thermostat = beestat.cache.ecobee_thermostat[thermostat.ecobee_thermostat_id];
|
|
||||||
|
|
||||||
const tr = document.createElement('tr');
|
const tr = document.createElement('tr');
|
||||||
|
|
||||||
const td_name = document.createElement('td');
|
const td_name = document.createElement('td');
|
||||||
|
td_name.style.paddingRight = `${beestat.style.size.gutter}px`;
|
||||||
const td_identifier = document.createElement('td');
|
const td_identifier = document.createElement('td');
|
||||||
const td_delete = document.createElement('td');
|
const td_delete = document.createElement('td');
|
||||||
|
|
||||||
td_name.innerText = thermostat.name;
|
td_name.innerText = ecobee_thermostat.name || '(Sync Queued)';
|
||||||
td_identifier.innerText = ecobee_thermostat.identifier;
|
td_identifier.innerText = ecobee_thermostat.identifier;
|
||||||
|
|
||||||
const tile_delete = new beestat.component.tile()
|
const tile_delete = new beestat.component.tile()
|
||||||
@ -44,7 +58,34 @@ beestat.component.card.manage_thermostats.prototype.decorate_contents_ = functio
|
|||||||
.render($(td_delete));
|
.render($(td_delete));
|
||||||
|
|
||||||
tile_delete.addEventListener('click', function() {
|
tile_delete.addEventListener('click', function() {
|
||||||
console.info('delete');
|
self.show_loading_();
|
||||||
|
|
||||||
|
new beestat.api()
|
||||||
|
.add_call(
|
||||||
|
'ecobee_thermostat',
|
||||||
|
'update',
|
||||||
|
{
|
||||||
|
'attributes': {
|
||||||
|
'ecobee_thermostat_id': ecobee_thermostat.ecobee_thermostat_id,
|
||||||
|
'inactive': 1
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'delete'
|
||||||
|
)
|
||||||
|
.add_call(
|
||||||
|
'ecobee_thermostat',
|
||||||
|
'read_id',
|
||||||
|
{
|
||||||
|
'attributes': {
|
||||||
|
'inactive': 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'read_id'
|
||||||
|
)
|
||||||
|
.set_callback(function(response) {
|
||||||
|
beestat.cache.set('ecobee_thermostat', response.read_id);
|
||||||
|
})
|
||||||
|
.send();
|
||||||
})
|
})
|
||||||
|
|
||||||
tr.appendChild(td_name);
|
tr.appendChild(td_name);
|
||||||
@ -71,9 +112,10 @@ beestat.component.card.manage_thermostats.prototype.decorate_contents_ = functio
|
|||||||
const input_container = document.createElement('div');
|
const input_container = document.createElement('div');
|
||||||
container.appendChild(input_container);
|
container.appendChild(input_container);
|
||||||
|
|
||||||
new_identifier = new beestat.component.input.text()
|
const new_identifier = new beestat.component.input.text()
|
||||||
.set_width(150)
|
.set_width(150)
|
||||||
.set_maxlength(12)
|
.set_maxlength(12)
|
||||||
|
.set_inputmode('numeric')
|
||||||
.set_placeholder('Serial #')
|
.set_placeholder('Serial #')
|
||||||
.render($(input_container));
|
.render($(input_container));
|
||||||
|
|
||||||
@ -85,15 +127,38 @@ beestat.component.card.manage_thermostats.prototype.decorate_contents_ = functio
|
|||||||
.set_background_hover_color(beestat.style.color.green.light)
|
.set_background_hover_color(beestat.style.color.green.light)
|
||||||
.set_text_color('#fff')
|
.set_text_color('#fff')
|
||||||
.set_text('Add Thermostat')
|
.set_text('Add Thermostat')
|
||||||
.render($(button_container));
|
.addEventListener('click', function() {
|
||||||
|
if (new_identifier.get_value()?.length === 12) {
|
||||||
|
self.show_loading_();
|
||||||
|
|
||||||
// TODO: Add thermostat button needs to make an API call. That call should
|
new beestat.api()
|
||||||
// look for an existing inactive thermostat on the account and add it back.
|
.add_call(
|
||||||
// If it doesn't exist, it should do an API call to ecobee to "sync" that
|
'ecobee_thermostat',
|
||||||
// thermostat which should immediately grab all of that data and create the
|
'create',
|
||||||
// rows for me using my existing code. Throw a loading spinner over the
|
{
|
||||||
// manage thermostats card while this happens, then call get thermostats when
|
'attributes': {
|
||||||
// that's done to update beestat's cache.
|
'identifier': new_identifier.get_value()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'create'
|
||||||
|
)
|
||||||
|
.add_call(
|
||||||
|
'ecobee_thermostat',
|
||||||
|
'read_id',
|
||||||
|
{
|
||||||
|
'attributes': {
|
||||||
|
'inactive': 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'read_id'
|
||||||
|
)
|
||||||
|
.set_callback(function(response) {
|
||||||
|
beestat.cache.set('ecobee_thermostat', response.read_id);
|
||||||
|
})
|
||||||
|
.send();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.render($(button_container));
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -33,15 +33,6 @@ beestat.layer.detail.prototype.decorate_ = function(parent) {
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Manage Thermostats
|
|
||||||
// cards.push([
|
|
||||||
// {
|
|
||||||
// 'card': new beestat.component.card.manage_thermostats(),
|
|
||||||
// 'card': new beestat.component.card.rookstack_survey_notification(),
|
|
||||||
// 'size': 12
|
|
||||||
// }
|
|
||||||
// ]);
|
|
||||||
|
|
||||||
cards.push([
|
cards.push([
|
||||||
{
|
{
|
||||||
'card': new beestat.component.card.system(thermostat.thermostat_id),
|
'card': new beestat.component.card.system(thermostat.thermostat_id),
|
||||||
|
@ -40,12 +40,12 @@ beestat.layer.settings.prototype.decorate_ = function(parent) {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
// Manage Thermostats
|
// Manage Thermostats
|
||||||
// cards.push([
|
cards.push([
|
||||||
// {
|
{
|
||||||
// 'card': new beestat.component.card.manage_thermostats(),
|
'card': new beestat.component.card.manage_thermostats(),
|
||||||
// 'size': 12
|
'size': 12
|
||||||
// }
|
}
|
||||||
// ]);
|
]);
|
||||||
|
|
||||||
// Footer
|
// Footer
|
||||||
cards.push([
|
cards.push([
|
||||||
|
Loading…
x
Reference in New Issue
Block a user