Integrate Shelly module with new routes, classes, helpers, and configurations

- Added `shelly` class to manage API operations, handle requests, and validate configurations.
- Introduced `shelly_i` interface and supporting helpers: `shelly_device_state`, `shelly_request_body_get_states`, and `shelly_response_body_get_states`.
- Created new routes for fetching and updating Shelly configurations (`/shelly/config`).
- Added Shelly module configurations: `enabled`, `secret_key`, and `server_url`.
- Implemented `shelly_c` for module setup and configuration handling.
- Integrated Shelly initialization in `index.php`.
This commit is contained in:
Jeppe Bundgaard
2025-10-15 10:54:01 +02:00
parent c97d0e3d39
commit e82b4950b7
12 changed files with 479 additions and 0 deletions
@@ -638,5 +638,36 @@ class moduleConfigRoute
'modules_virkdata_config' => 'Update virkdata config'
]
);
/** Shelly config -> GET */
$this->get('/shelly/config', function () {
global $response;
$this->requirePermission('modules_shelly_config');
$user = (new authentication())->get_user();
if ($user) {
(new logs_o())->add('shelly_config', 'global', 1, $user->id, 'SHELLY_CONFIG', 'Successfully fetched shelly config');
$response->success(
(new \classes\shelly())->config->getConfigRequest()
);
} else {
(new logs_o())->add('shelly_config', 'global', 1, 0, 'VIRKDATA_CONFIG', 'No user found, or invalid session');
}
},
[
'modules_shelly_config' => 'Get shelly config'
]
);
$this->post('/shelly/config', function () {
global $response;
$this->requirePermission('modules_shelly_config');
$user = (new authentication())->get_user();
if ($user) {
(new logs_o())->add('shelly_config', 'global', 1, $user->id, 'SHELLY_CONFIG', 'Successfully updated shelly config');
$response->success(
(new \classes\shelly())->config->postConfigRequest()
);
} else {
(new logs_o())->add('shelly_config', 'global', 1, 0, 'SHELLY_CONFIG', 'No user found, or invalid session');
}
});
}
}