summaryrefslogtreecommitdiff
path: root/localwebsite/handlers
diff options
context:
space:
mode:
authorEvgeny Zinoviev <me@ch1p.io>2022-12-11 01:25:29 +0300
committerEvgeny Zinoviev <me@ch1p.io>2022-12-11 01:25:29 +0300
commit16d47968b4938f3b60b97f374d45ad39bb0071b1 (patch)
treeaca9209fc72c4a662822b8a53e7b04db67e30715 /localwebsite/handlers
parent769a66f21d6d701dc72c849e98494a77adcf8024 (diff)
lws: inverter: allow changing osp
Diffstat (limited to 'localwebsite/handlers')
-rw-r--r--localwebsite/handlers/InverterHandler.php48
1 files changed, 31 insertions, 17 deletions
diff --git a/localwebsite/handlers/InverterHandler.php b/localwebsite/handlers/InverterHandler.php
index 78fc1ab..7098e2c 100644
--- a/localwebsite/handlers/InverterHandler.php
+++ b/localwebsite/handlers/InverterHandler.php
@@ -3,37 +3,45 @@
class InverterHandler extends RequestHandler
{
- public function __construct()
- {
+ public function __construct() {
parent::__construct();
$this->tpl->add_static('inverter.js');
}
- public function GET_status_page()
- {
- global $config;
- $inv = new InverterdClient($config['inverterd_host'], $config['inverterd_port']);
- $inv->setFormat('json');
+ public function GET_status_page() {
+ $inv = $this->getClient();
+
$status = jsonDecode($inv->exec('get-status'))['data'];
+ $rated = jsonDecode($inv->exec('get-rated'))['data'];
$this->tpl->set([
'status' => $status,
- 'html' => $this->renderStatusHtml($status)
+ 'rated' => $rated,
+ 'html' => $this->renderStatusHtml($status, $rated)
]);
$this->tpl->set_title('Инвертор');
$this->tpl->render_page('inverter_page.twig');
}
+ public function GET_set_osp() {
+ list($osp) = $this->input('e:value(=sub|sbu)');
+ $inv = $this->getClient();
+ try {
+ $inv->exec('set-output-source-priority', [strtoupper($osp)]);
+ } catch (Exception $e) {
+ die('Ошибка: '.jsonDecode($e->getMessage())['message']);
+ }
+ redirect('/inverter/');
+ }
+
public function GET_status_ajax() {
- global $config;
- $inv = new InverterdClient($config['inverterd_host'], $config['inverterd_port']);
- $inv->setFormat('json');
+ $inv = $this->getClient();
$status = jsonDecode($inv->exec('get-status'))['data'];
- ajax_ok(['html' => $this->renderStatusHtml($status)]);
+ $rated = jsonDecode($inv->exec('get-rated'))['data'];
+ ajax_ok(['html' => $this->renderStatusHtml($status, $rated)]);
}
- protected function renderStatusHtml(array $status)
- {
+ protected function renderStatusHtml(array $status, array $rated) {
$power_direction = strtolower($status['battery_power_direction']);
$power_direction = preg_replace('/ge$/', 'ging', $power_direction);
@@ -77,12 +85,18 @@ class InverterHandler extends RequestHandler
$status['grid_freq']['unit']);
}
+ $html .= "\n".sprintf('<b>Priority:</b> %s',
+ $rated['output_source_priority']);
+
return nl2br($html);
}
- public function GET_status_page_update()
- {
-
+ protected function getClient(): InverterdClient {
+ global $config;
+ $inv = new InverterdClient($config['inverterd_host'], $config['inverterd_port']);
+ $inv->setFormat('json');
+ return $inv;
}
+
} \ No newline at end of file