diff --git a/server/ControlScripts/SpotlightsScope.php b/server/ControlScripts/SpotlightsScope.php index 58e2505..6c372ec 100644 --- a/server/ControlScripts/SpotlightsScope.php +++ b/server/ControlScripts/SpotlightsScope.php @@ -30,8 +30,10 @@ public function register_events_handlers(): void { $this -> backdoor_btns_online(); $this -> master_door_btns_online(); - $this -> btns_handlers("buttons_backdoor"); - $this -> btns_handlers("master_door_btns"); + $this -> btns_click_handlers("buttons_backdoor"); + $this -> btns_click_handlers("master_door_btns"); + $this -> on_online("buttons_backdoor"); + $this -> on_online("master_door_btns"); } public function register_actions_scripts(): void { @@ -142,14 +144,6 @@ // EVENTS HANDLERS - protected function master_door_btns_online(): void { - $this -> on_online("master_door_btns"); - } - - protected function backdoor_btns_online(): void { - $this -> on_online("buttons_backdoor"); - } - protected function on_online($alias) { $this -> add_event_handler("button@{$alias}.online", function(Device $btns_block, Array $data) { $btns_block_api = $btns_block -> device_api(); @@ -161,7 +155,7 @@ }); } - protected function btns_handlers($alias): void { + protected function btns_click_handlers($alias): void { $self = $this; $buttons = $this -> helper() -> prepare_sync_map_by_alias($this -> sync_map, $alias); foreach($buttons as $btn_channel => $entry) { @@ -178,17 +172,7 @@ if($relay_api instanceof \SHServ\Tools\DeviceAPI\Relay and $btns_block_api instanceof \SHServ\Tools\DeviceAPI\Button) { $relay_api -> toggle_channel($relay_channel); - $this -> helper() -> sync_relay_to_btn_channel($relay_api, $btns_block_api, $relay_channel, $btn_channel); - - $other_btns = $this -> helper() -> prepare_sync_map_by_alias($self -> sync_map, $relay_alias); - foreach($other_btns[$btn_channel] as $ent) { - if($ent["type"] != "button") { - continue; - } - - $btn = $this -> devices() -> by_alias($ent["alias"]) -> device_api(); - $this -> helper() -> sync_relay_to_btn_channel($relay_api, $btn, $relay_channel, $ent["channel"]); - } + $this -> helper() -> sync_relay_to_btns($this -> sync_map, $relay_alias); } }); } diff --git a/server/SHServ/Helpers/DeviceScriptsHelper.php b/server/SHServ/Helpers/DeviceScriptsHelper.php index 2420de0..315fb5f 100644 --- a/server/SHServ/Helpers/DeviceScriptsHelper.php +++ b/server/SHServ/Helpers/DeviceScriptsHelper.php @@ -166,4 +166,5 @@ return $result; } + } \ No newline at end of file