diff --git a/server/ControlScripts/OfficeRoomScope.php b/server/ControlScripts/OfficeRoomScope.php index e42bafa..d4a054c 100644 --- a/server/ControlScripts/OfficeRoomScope.php +++ b/server/ControlScripts/OfficeRoomScope.php @@ -14,7 +14,7 @@ [ ["type" => "relay", "alias" => "craft_table_lamp", "channel" => 0], - ["type" => "button", "alias" => "buttons_office_room", "channel" => 0], + ["type" => "button", "alias" => "buttons_office_room", "channel" => 2], ], [ @@ -85,7 +85,7 @@ $this -> add_event_handler("button@{$button_alias}.online", function(Device $btns_block, Array $data) { $btns_block_api = $btns_block -> device_api(); if($btns_block_api instanceof \SHServ\Tools\DeviceAPI\Button) { - $btns_block_api -> set_channel_state("mute", 2); + $btns_block_api -> set_channel_state("mute", 0); } $this -> helper() -> sync_btn_channels($this -> sync_map, $btns_block -> alias); @@ -100,16 +100,17 @@ } $relay_alias = $entry[0]["alias"]; + $relay_channel = $entry[0]["channel"]; - $this -> add_event_handler("button@{$button_alias}({$btn_channel}).press", function(Device $btns_block, Array $data) use ($btn_channel, $relay_alias) { + $this -> add_event_handler("button@{$button_alias}({$btn_channel}).press", function(Device $btns_block, Array $data) use ($btn_channel, $relay_alias, $relay_channel) { $btns_block_api = $btns_block -> device_api(); $relay_api = $this -> devices() -> by_alias($relay_alias) -> device_api(); if($relay_api instanceof \SHServ\Tools\DeviceAPI\Relay and $btns_block_api instanceof \SHServ\Tools\DeviceAPI\Button) { - $relay_api -> toggle_channel(0); - $this -> helper() -> sync_relay_to_btn_channel($relay_api, $btns_block_api, 0, $btn_channel); + $relay_api -> toggle_channel($relay_channel); + $this -> helper() -> sync_relay_to_btn_channel($relay_api, $btns_block_api, $relay_channel, $btn_channel); } }); } } -} \ No newline at end of file +} diff --git a/server/ControlScripts/SpotlightsScope.php b/server/ControlScripts/SpotlightsScope.php index 8de1338..58e2505 100644 --- a/server/ControlScripts/SpotlightsScope.php +++ b/server/ControlScripts/SpotlightsScope.php @@ -10,23 +10,28 @@ [ ["type" => "relay", "alias" => "spotlight_main_back_1", "channel" => 0], ["type" => "button", "alias" => "buttons_backdoor", "channel" => 0], + ["type" => "button", "alias" => "master_door_btns", "channel" => 0], ], [ ["type" => "relay", "alias" => "spotlight_main_back_2", "channel" => 0], ["type" => "button", "alias" => "buttons_backdoor", "channel" => 1], + ["type" => "button", "alias" => "master_door_btns", "channel" => 1], ], [ ["type" => "relay", "alias" => "spotlight_main_front_1", "channel" => 0], ["type" => "button", "alias" => "buttons_backdoor", "channel" => 2], + ["type" => "button", "alias" => "master_door_btns", "channel" => 2], ], ] ]; public function register_events_handlers(): void { $this -> backdoor_btns_online(); - $this -> backdoor_btns_handlers(); + $this -> master_door_btns_online(); + $this -> btns_handlers("buttons_backdoor"); + $this -> btns_handlers("master_door_btns"); } public function register_actions_scripts(): void { @@ -137,8 +142,16 @@ // EVENTS HANDLERS + protected function master_door_btns_online(): void { + $this -> on_online("master_door_btns"); + } + protected function backdoor_btns_online(): void { - $this -> add_event_handler("button@buttons_backdoor.online", function(Device $btns_block, Array $data) { + $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(); if($btns_block_api instanceof \SHServ\Tools\DeviceAPI\Button) { $btns_block_api -> set_channel_state("mute", 3); @@ -148,23 +161,34 @@ }); } - protected function backdoor_btns_handlers(): void { - $buttons_backdoor = $this -> helper() -> prepare_sync_map_by_alias($this -> sync_map, "buttons_backdoor"); - foreach($buttons_backdoor as $btn_channel => $entry) { + protected function btns_handlers($alias): void { + $self = $this; + $buttons = $this -> helper() -> prepare_sync_map_by_alias($this -> sync_map, $alias); + foreach($buttons as $btn_channel => $entry) { if($entry[0]["type"] != "relay") { continue; } $relay_alias = $entry[0]["alias"]; + $relay_channel = $entry[0]["channel"]; - $this -> add_event_handler("button@buttons_backdoor({$btn_channel}).press", function(Device $btns_block, Array $data) use ($btn_channel, $relay_alias) { + $this -> add_event_handler("button@{$alias}({$btn_channel}).press", function(Device $btns_block, Array $data) use ($self, $btn_channel, $relay_alias, $relay_channel) { $btns_block_api = $btns_block -> device_api(); $relay_api = $this -> devices() -> by_alias($relay_alias) -> device_api(); if($relay_api instanceof \SHServ\Tools\DeviceAPI\Relay and $btns_block_api instanceof \SHServ\Tools\DeviceAPI\Button) { - $relay_api -> toggle_channel(0); + $relay_api -> toggle_channel($relay_channel); + $this -> helper() -> sync_relay_to_btn_channel($relay_api, $btns_block_api, $relay_channel, $btn_channel); - $this -> helper() -> sync_relay_to_btn_channel($relay_api, $btns_block_api, 0, $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"]); + } } }); } diff --git a/server/SHServ/config.php b/server/SHServ/config.php index 08e78b2..cdf4627 100644 --- a/server/SHServ/config.php +++ b/server/SHServ/config.php @@ -8,10 +8,10 @@ "db" => [ "dblib" => "mysql", "host" => "localhost", - "dbname" => "eugene", + "dbname" => "shome", "charset" => "utf8", - "user" => "smart-home-server", - "password" => "root" + "user" => "u_shome", + "password" => "halloween" ], "app_file" => "App.php", "templates_folder" => "Templates",