lws: inverter: allow changing osp
This commit is contained in:
parent
769a66f21d
commit
16d47968b4
@ -3,37 +3,45 @@
|
|||||||
class InverterHandler extends RequestHandler
|
class InverterHandler extends RequestHandler
|
||||||
{
|
{
|
||||||
|
|
||||||
public function __construct()
|
public function __construct() {
|
||||||
{
|
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
$this->tpl->add_static('inverter.js');
|
$this->tpl->add_static('inverter.js');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function GET_status_page()
|
public function GET_status_page() {
|
||||||
{
|
$inv = $this->getClient();
|
||||||
global $config;
|
|
||||||
$inv = new InverterdClient($config['inverterd_host'], $config['inverterd_port']);
|
|
||||||
$inv->setFormat('json');
|
|
||||||
$status = jsonDecode($inv->exec('get-status'))['data'];
|
$status = jsonDecode($inv->exec('get-status'))['data'];
|
||||||
|
$rated = jsonDecode($inv->exec('get-rated'))['data'];
|
||||||
|
|
||||||
$this->tpl->set([
|
$this->tpl->set([
|
||||||
'status' => $status,
|
'status' => $status,
|
||||||
'html' => $this->renderStatusHtml($status)
|
'rated' => $rated,
|
||||||
|
'html' => $this->renderStatusHtml($status, $rated)
|
||||||
]);
|
]);
|
||||||
$this->tpl->set_title('Инвертор');
|
$this->tpl->set_title('Инвертор');
|
||||||
$this->tpl->render_page('inverter_page.twig');
|
$this->tpl->render_page('inverter_page.twig');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function GET_status_ajax() {
|
public function GET_set_osp() {
|
||||||
global $config;
|
list($osp) = $this->input('e:value(=sub|sbu)');
|
||||||
$inv = new InverterdClient($config['inverterd_host'], $config['inverterd_port']);
|
$inv = $this->getClient();
|
||||||
$inv->setFormat('json');
|
try {
|
||||||
$status = jsonDecode($inv->exec('get-status'))['data'];
|
$inv->exec('set-output-source-priority', [strtoupper($osp)]);
|
||||||
ajax_ok(['html' => $this->renderStatusHtml($status)]);
|
} catch (Exception $e) {
|
||||||
|
die('Ошибка: '.jsonDecode($e->getMessage())['message']);
|
||||||
|
}
|
||||||
|
redirect('/inverter/');
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function renderStatusHtml(array $status)
|
public function GET_status_ajax() {
|
||||||
{
|
$inv = $this->getClient();
|
||||||
|
$status = jsonDecode($inv->exec('get-status'))['data'];
|
||||||
|
$rated = jsonDecode($inv->exec('get-rated'))['data'];
|
||||||
|
ajax_ok(['html' => $this->renderStatusHtml($status, $rated)]);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function renderStatusHtml(array $status, array $rated) {
|
||||||
$power_direction = strtolower($status['battery_power_direction']);
|
$power_direction = strtolower($status['battery_power_direction']);
|
||||||
$power_direction = preg_replace('/ge$/', 'ging', $power_direction);
|
$power_direction = preg_replace('/ge$/', 'ging', $power_direction);
|
||||||
|
|
||||||
@ -77,12 +85,18 @@ class InverterHandler extends RequestHandler
|
|||||||
$status['grid_freq']['unit']);
|
$status['grid_freq']['unit']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$html .= "\n".sprintf('<b>Priority:</b> %s',
|
||||||
|
$rated['output_source_priority']);
|
||||||
|
|
||||||
return nl2br($html);
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -19,6 +19,7 @@ $router->add('sms/', 'Modem sms');
|
|||||||
|
|
||||||
// inverter
|
// inverter
|
||||||
$router->add('inverter/', 'Inverter status_page');
|
$router->add('inverter/', 'Inverter status_page');
|
||||||
|
$router->add('inverter/set-osp/', 'Inverter set_osp');
|
||||||
$router->add('inverter/status.ajax', 'Inverter status_ajax');
|
$router->add('inverter/status.ajax', 'Inverter status_ajax');
|
||||||
|
|
||||||
// misc
|
// misc
|
||||||
|
@ -9,6 +9,12 @@
|
|||||||
{{ html|raw }}
|
{{ html|raw }}
|
||||||
</div>
|
</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 %}
|
{% js %}
|
||||||
Inverter.poll();
|
Inverter.poll();
|
||||||
{% endjs %}
|
{% endjs %}
|
Loading…
x
Reference in New Issue
Block a user