<?php
namespace ControlScripts;
use \SHServ\Entities\Device;
class LightHubScope extends \SHServ\Middleware\ControlScripts implements \SHServ\Implements\ControlScriptsInterface {
protected $sync_map = [
"connections" => [
[
["type" => "relay", "alias" => "light_hub_1", "channel" => 0],
["type" => "button", "alias" => "buttons_office_room", "channel" => 0],
],
[
["type" => "relay", "alias" => "craft_table_lamp", "channel" => 0],
["type" => "button", "alias" => "buttons_office_room", "channel" => 1],
],
[
["type" => "relay", "alias" => "computer_table_lamp", "channel" => 0],
["type" => "button", "alias" => "buttons_office_room", "channel" => 2],
],
]
];
public function register_events_handlers(): void {
}
public function register_actions_scripts(): void {
$this -> add_action_script([
"alias" => "main_lamps_switcher",
"name" => "Осн. свет в кабинете",
"icon" => '<i class="ph ph-lightbulb"></i>',
"description" => "Включить/выключить основной свет в кабинете",
"author" => "Eugene Sukhodolskiy"
], function($params) {
return $this -> lamp_switch("light_hub_1", 0);
});
$this -> add_action_script([
"alias" => "master_room_lamp_switcher",
"name" => "Осн. свет в спальне",
"icon" => '<i class="ph ph-lightbulb"></i>',
"description" => "Включить/выключить основной свет в спальне",
"author" => "Eugene Sukhodolskiy"
], function($params) {
return $this -> lamp_switch("light_hub_1", 1);
});
$this -> add_action_script([
"alias" => "hallway2_lamp_switcher",
"name" => "Осн. свет в холе, эт2",
"icon" => '<i class="ph ph-lightbulb"></i>',
"description" => "Включить/выключить основной свет в холе на втором этаже",
"author" => "Eugene Sukhodolskiy"
], function($params) {
return $this -> lamp_switch("light_hub_1", 2);
});
$this -> add_action_script([
"alias" => "bathroom2_lamp_switcher",
"name" => "Осн. свет в ванной 2",
"icon" => '<i class="ph ph-lightbulb"></i>',
"description" => "Включить/выключить основной свет в ванной комнате на верху",
"author" => "Eugene Sukhodolskiy"
], function($params) {
return $this -> lamp_switch("light_hub_1", 3);
});
}
public function register_regular_scripts(): void {
}
// ACTIONS
protected function lamp_switch(String $relay_alias, int $channel): Array {
$btns_block_api = $this -> devices() -> by_alias("buttons_office_room") -> device_api();
$device_entries = $this -> helper() -> get_sync_entries_by_type($this -> sync_map, "relay");
$result = false;
if($relay_api instanceof \SHServ\Tools\DeviceAPI\Relay) {
$result = $relay_api -> toggle_channel($channel);
$this -> helper() -> sync_relay_to_btns($this -> sync_map, $relay_alias);
}
return [
"result" => $result
];
}
// protected function spotlight_switch(String $relay_alias, Bool $state = false) {
// $btns_block_api = $this -> devices() -> by_alias("buttons_backdoor") -> device_api();
// $device_entries = $this -> helper() -> get_sync_entries_by_type($this -> sync_map, "relay");
//
// $relay_api = $this -> devices() -> by_alias($relay_alias) -> device_api();
// $result = false;
// if($relay_api instanceof \SHServ\Tools\DeviceAPI\Relay) {
// $result = $relay_api -> set_state($state);
// $this -> helper() -> sync_relay_to_btns($this -> sync_map, $relay_alias);
// }
//
// return [
// "result" => $result
// ];
// }
}