8 Commits

Author SHA1 Message Date
GamerClassN7
64b50ead9f Notifications 2021-01-04 17:08:56 +01:00
GamerClassN7
a3a87d39d2 Fixes 2021-01-04 16:51:34 +01:00
GamerClassN7
c4f36235ab Google Home Heater controll Fix 2020-12-25 15:59:13 +01:00
daa0e0a2c5 Settings Save Mechanism an few fixes 2020-12-23 15:57:12 +01:00
GamerClassN7
464f229a16 Add Open Weather Settings 2020-12-17 19:42:29 +01:00
GamerClassN7
fe72097d75 Show Plugin Settings 2020-12-17 19:41:59 +01:00
GamerClassN7
98efb779b1 comment 2020-12-17 19:17:05 +01:00
30045b9f65 Merge pull request 'feature/bootstrap' (#2) from feature/bootstrap into remastering
Reviewed-on: #2
2020-12-15 21:22:52 +00:00
12 changed files with 83 additions and 19 deletions

1
.gitignore vendored
View File

@@ -2,6 +2,7 @@
.ftpconfig .ftpconfig
.ftpconfig2 .ftpconfig2
*.log *.log
*.bin
config.php config.php
_nemazat/index.html _nemazat/index.html

View File

@@ -53,6 +53,7 @@ $router->any('/api/HA', 'GoogleHomeApi@response');
$router->post('/api/endpoint/', 'EndpointsApi@default'); $router->post('/api/endpoint/', 'EndpointsApi@default');
$router->any('/api/update/', 'UpdatesApi@default'); $router->any('/api/update/', 'UpdatesApi@default');
$router->any('/api/users/status', 'UsersApi@status'); $router->any('/api/users/status', 'UsersApi@status');
$router->any('/api/users/subscribe', 'UsersApi@subscribe');
// examples // examples
$router->any('/api/example', 'ExampleApi@example'); $router->any('/api/example', 'ExampleApi@example');

View File

@@ -12,6 +12,11 @@ class CronApi extends ApiController
$backupWorker = new DatabaseBackup(); $backupWorker = new DatabaseBackup();
$backupWorker->purge(5); $backupWorker->purge(5);
//Old Records Cleanup
foreach (SubDeviceManager::getAllSubDevices() as $key => $value) {
RecordManager::setHistory($value['subdevice_id']);
}
$this->response(['Value' => 'OK']); $this->response(['Value' => 'OK']);
} }

View File

@@ -34,4 +34,13 @@ class UsersApi extends ApiController{
} }
$this->response(['value'=>'OK']); $this->response(['value'=>'OK']);
} }
public function subscribe(){
//$this->requireAuth();
$subscriptionToken = $this->input['token'];
$subscriptionUserId = $this->input['user_id'];
NotificationManager::addSubscriber($subscriptionUserId, $subscriptionToken);
$this->response(['value'=>'OK']);
}
} }

View File

@@ -28,6 +28,17 @@ if (isset($_POST) && !empty($_POST)){
die(); die();
} else if (isset ($_POST['userPermission']) && !empty ($_POST['userID'])) { } else if (isset ($_POST['userPermission']) && !empty ($_POST['userID'])) {
$userManager->setUserDataAdmin("permission", $_POST['userPermission'], $_POST['userID']); $userManager->setUserDataAdmin("permission", $_POST['userPermission'], $_POST['userID']);
header('Location: ' . BASEURL . 'setting');
die();
} else {
foreach ($_POST as $key => $value) {
if ($key == 'submit') continue;
$settingMng = new SettingsManager();
if ($settingMng->getByName($key)) {
$settingMng->update($key, $value);
}
}
header('Location: ' . BASEURL . 'setting'); header('Location: ' . BASEURL . 'setting');
die(); die();
} }

View File

@@ -26,7 +26,7 @@ class GoogleHome {
} }
} }
if ($traids < 0){ if ($traids < 1){
continue; continue;
} }

View File

@@ -102,7 +102,7 @@ class RecordManager{
public static function clean ($day) { public static function clean ($day) {
if (isset($day)) { if (isset($day)) {
Db::command ('DELETE FROM records WHERE `time` < ADDDATE(NOW(), INTERVAL -? DAY);', array($day)); Db::command ('DELETE FROM records WHERE `time` < ADDDATE(NOW(), INTERVAL ? DAY);', array($day));
} }
} }
@@ -110,5 +110,10 @@ class RecordManager{
public static function cleanSubdeviceRecords ($subDeviceId) { public static function cleanSubdeviceRecords ($subDeviceId) {
Db::command ('DELETE FROM records WHERE subdevice_id = ?);', array($subDeviceId)); Db::command ('DELETE FROM records WHERE subdevice_id = ?);', array($subDeviceId));
} }
public static function setHistory($subDeviceId){
$history = SubDeviceManager::getSubDevice($subDeviceId)['history'];
if ($history > 0) self::clean(-abs($history));
}
} }
?> ?>

View File

@@ -14,6 +14,7 @@ class SettingsManager{
} }
public static function create ($name, $value, $type = '') { public static function create ($name, $value, $type = '') {
if (!self::getByName($name)){
$setting = array ( $setting = array (
'name' => $name, 'name' => $name,
'value' => $value, 'value' => $value,
@@ -26,9 +27,10 @@ class SettingsManager{
die(); die();
} }
} }
}
public static function update ($name, $value, $type = '') { public static function update ($name, $value, $type = '') {
if (self::getByName($name)){ if (!self::getByName($name)){
self::create($name, $value, $type); self::create($name, $value, $type);
} else { } else {
try { try {

View File

@@ -9,6 +9,14 @@ class AirQuality extends VirtualDeviceManager
function make() function make()
{ {
//Register the settings
$settingMng = new SettingsManager();
if (!($settingField = $settingMng->getByName("airquality"))) {
$settingMng->create("token", "", "airquality");
} else {
$app_id = $settingField['value'];
}
try { try {
if (DeviceManager::registeret($this->virtual_device_name)) { if (DeviceManager::registeret($this->virtual_device_name)) {
$deviceId = DeviceManager::getDeviceByToken($this->virtual_device_name)['device_id']; $deviceId = DeviceManager::getDeviceByToken($this->virtual_device_name)['device_id'];

View File

@@ -33,4 +33,8 @@ class OpenWeatherMap extends VirtualDeviceManager
return 'exception: ' . $e->getMessage(); return 'exception: ' . $e->getMessage();
} }
} }
function enable(){
(new SettingsManager)->create('open_weather_api_token', '', 'open_weather');
}
} }

View File

@@ -70,6 +70,8 @@ class Setting extends Template
$result = $settingsManager->getSettingGroup($plugins[$key]['slug']); $result = $settingsManager->getSettingGroup($plugins[$key]['slug']);
if (count ($result) > 0) { if (count ($result) > 0) {
$plugins[$key]['settings'] = $result; $plugins[$key]['settings'] = $result;
} else {
unset($plugins[$key]);
} }
} }
} }

View File

@@ -202,7 +202,23 @@ $partial = new Partial('head');
</form> </form>
</div> </div>
<!--Plugins Settings-->
<?php foreach ($PLUGINSSETTINGS as $key => $pluginSeting) { ?>
<div class="col-12 col-sm-9 mx-auto mt-4">
<h4 class="mb-4"><?php echo $pluginSeting['name'] ?></h4>
<form method="post">
<?php foreach ($pluginSeting['settings'] as $key => $pluginSetingField) { ?>
<div class="field">
<div class="label"><?php echo $pluginSetingField['name'] ?>:</div>
<input type="text" class="input" name="<?php echo $pluginSetingField['name'] ?>" value="<?php echo $pluginSetingField['value'] ?>">
</div>
<?php } ?>
<div class="field">
<input type="submit" name="submitPlugins<?php echo $pluginSeting['name'] ?>Settings" class="button" value="<?php $LANGMNG->echo('b_save') ?>">
</div>
</form>
</div>
<?php } ?>
</div> </div>