diff options
author | Evgeny Zinoviev <me@ch1p.io> | 2022-12-11 01:25:29 +0300 |
---|---|---|
committer | Evgeny Zinoviev <me@ch1p.io> | 2022-12-11 01:25:29 +0300 |
commit | 16d47968b4938f3b60b97f374d45ad39bb0071b1 (patch) | |
tree | aca9209fc72c4a662822b8a53e7b04db67e30715 | |
parent | 769a66f21d6d701dc72c849e98494a77adcf8024 (diff) |
lws: inverter: allow changing osp
-rw-r--r-- | localwebsite/handlers/InverterHandler.php | 48 | ||||
-rw-r--r-- | localwebsite/htdocs/index.php | 1 | ||||
-rw-r--r-- | localwebsite/templates-web/inverter_page.twig | 6 |
3 files changed, 38 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 diff --git a/localwebsite/htdocs/index.php b/localwebsite/htdocs/index.php index 0a4e8c5..d1fc0fd 100644 --- a/localwebsite/htdocs/index.php +++ b/localwebsite/htdocs/index.php @@ -19,6 +19,7 @@ $router->add('sms/', 'Modem sms'); // inverter $router->add('inverter/', 'Inverter status_page'); +$router->add('inverter/set-osp/', 'Inverter set_osp'); $router->add('inverter/status.ajax', 'Inverter status_ajax'); // misc diff --git a/localwebsite/templates-web/inverter_page.twig b/localwebsite/templates-web/inverter_page.twig index 2c3f8dd..c51e1bf 100644 --- a/localwebsite/templates-web/inverter_page.twig +++ b/localwebsite/templates-web/inverter_page.twig @@ -9,6 +9,12 @@ {{ html|raw }} </div> +<div class="pt-3"> + <a href="/inverter/set-osp/?value={{ rated.output_source_priority == 'Solar-Battery-Utility' ? 'sub' : 'sbu' }}"> + <button type="button" class="btn btn-primary">Переключить на <b>{{ rated.output_source_priority == 'Solar-Battery-Utility' ? 'Solar-Utility-Battery' : 'Solar-Battery-Utility' }}</b></button> + </a> +</div> + {% js %} Inverter.poll(); {% endjs %}
\ No newline at end of file |