diff --git a/server/ControlScripts/Common.php b/server/ControlScripts/Common.php index c15cf4b..e1e6b60 100644 --- a/server/ControlScripts/Common.php +++ b/server/ControlScripts/Common.php @@ -6,120 +6,19 @@ trait Common { public function register_global_device_sync_map() { - $this -> add_sync_connection([ - ["type" => "relay", "alias" => "spotlight_main_back_1", "channel" => 0], - ["type" => "button", "alias" => "buttons_backdoor", "channel" => 2], - ["type" => "button", "alias" => "master_door_btns", "channel" => 1], - ["type" => "button", "alias" => "bed_btns_left", "channel" => 0], - ]); + $sync_map_path = __DIR__ . "/sync-map.json"; + if (!file_exists($sync_map_path)) { + return; + } - $this -> add_sync_connection([ - ["type" => "relay", "alias" => "spotlight_main_back_2", "channel" => 0], - ["type" => "button", "alias" => "buttons_backdoor", "channel" => 1], - ["type" => "button", "alias" => "master_door_btns", "channel" => 0], - ]); + $connections = json_decode(file_get_contents($sync_map_path), true); + if (!is_array($connections)) { + return; + } - $this -> add_sync_connection([ - ["type" => "relay", "alias" => "spotlight_main_front_1", "channel" => 0], - ["type" => "button", "alias" => "buttons_backdoor", "channel" => 0], - ["type" => "button", "alias" => "master_door_btns", "channel" => 3], - ]); - - $this -> add_sync_connection([ - ["type" => "relay", "alias" => "light_hub_1", "channel" => 0], - ["type" => "button", "alias" => "buttons_office_room", "channel" => 3], - ]); - - $this -> add_sync_connection([ - ["type" => "relay", "alias" => "craft_table_lamp", "channel" => 0], - ["type" => "button", "alias" => "buttons_office_room", "channel" => 2], - ]); - - $this -> add_sync_connection([ - ["type" => "relay", "alias" => "computer_table_lamp", "channel" => 0], - ["type" => "button", "alias" => "buttons_office_room", "channel" => 1], - ]); - - $this -> add_sync_connection([ - ["type" => "relay", "alias" => "light_hub_1", "channel" => 2], - ["type" => "button", "alias" => "buttons_office_room", "channel" => 0], - ["type" => "button", "alias" => "master_room_btns", "channel" => 1], - ["type" => "button", "alias" => "btns_hall2_1", "channel" => 0], - ["type" => "button", "alias" => "hall_secondary", "channel" => 0], - ["type" => "button", "alias" => "bed_btns_right_1", "channel" => 0], - ]); - - $this -> add_sync_connection([ - ["type" => "relay", "alias" => "light_hub_1", "channel" => 1], - ["type" => "button", "alias" => "master_room_btns", "channel" => 0], - ["type" => "button", "alias" => "bed_btns_right_1", "channel" => 1], - ["type" => "button", "alias" => "bed_btns_left", "channel" => 1], - ]); - - $this -> add_sync_connection([ - ["type" => "relay", "alias" => "bathroom_2_light", "channel" => 0], - ["type" => "button", "alias" => "hall_secondary", "channel" => 1], - ]); - - // 14 - down, 12 - left, 13 - top, 15 - right - // 3 - top - // 14->1 12->3 13->0 - $this -> add_sync_connection([ - ["type" => "relay", "alias" => "plants_room_light", "channel" => 0], - ["type" => "button", "alias" => "plants_room_btns", "channel" => 3], - ]); - - $this -> add_sync_connection([ - ["type" => "relay", "alias" => "italy_lamp_relay", "channel" => 0], - ["type" => "button", "alias" => "plants_room_btns", "channel" => 2], - ]); - - $this -> add_sync_connection([ - ["type" => "relay", "alias" => "floor_lamp_relay", "channel" => 0], - ["type" => "button", "alias" => "plants_room_btns", "channel" => 0], - ]); - - $this -> add_sync_connection([ - ["type" => "relay", "alias" => "server_room_light", "channel" => 0], - ["type" => "button", "alias" => "btns_hall2_1", "channel" => 1], - ]); - - - - - // --- - - $this -> add_sync_connection([ - ["type" => "relay", "alias" => "fisrt_floor_big_relay", "channel" => 0], - ["type" => "button", "alias" => "kitchen_buttons_1", "channel" => 0], - ["type" => "button", "alias" => "kitchen_buttons_2", "channel" => 0], - ]); - - $this -> add_sync_connection([ - ["type" => "relay", "alias" => "fisrt_floor_big_relay", "channel" => 1], - ["type" => "button", "alias" => "kitchen_buttons_1", "channel" => 1], - ["type" => "button", "alias" => "kitchen_buttons_2", "channel" => 1], - ]); - - // --- - - $this -> add_sync_connection([ - ["type" => "relay", "alias" => "fisrt_floor_big_relay", "channel" => 2], - ["type" => "button", "alias" => "first_hall_buttons1", "channel" => 0], - ]); - - $this -> add_sync_connection([ - ["type" => "relay", "alias" => "fisrt_floor_big_relay", "channel" => 3], - ["type" => "button", "alias" => "first_hall_buttons1", "channel" => 1], - ["type" => "button", "alias" => "first_hall_buttons2", "channel" => 0], - ]); - - $this -> add_sync_connection([ - ["type" => "relay", "alias" => "fisrt_floor_big_relay", "channel" => 4], - ["type" => "button", "alias" => "first_hall_buttons1", "channel" => 2], - ["type" => "button", "alias" => "first_hall_buttons2", "channel" => 1], - ]); - + foreach ($connections as $connection) { + $this -> add_sync_connection($connection); + } } public function btn_on_online(String $alias, Array $muted = []): void { diff --git a/server/ControlScripts/Scopes/OfficeRoomScope.php b/server/ControlScripts/Scopes/OfficeRoomScope.php index 63dc8df..8d6d36a 100644 --- a/server/ControlScripts/Scopes/OfficeRoomScope.php +++ b/server/ControlScripts/Scopes/OfficeRoomScope.php @@ -68,32 +68,4 @@ ]; } - // protected function btns_online(String $button_alias): void { - // $this -> add_event_handler("button@{$button_alias}.online", function(Device $btns_block, Array $data) { - // $btns_block_api = $btns_block -> device_api(); - // $this -> helper() -> sync_btn_channels($this -> sync_map(), $btns_block -> alias); - // }); - // } - - // protected function btns_handlers(String $button_alias): void { - // $buttons_channels = $this -> helper() -> prepare_sync_map_by_alias($this -> sync_map(), $button_alias); - // foreach($buttons_channels 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@{$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($relay_channel); - // $this -> helper() -> sync_relay_to_btn_channel($relay_api, $btns_block_api, $relay_channel, $btn_channel); - // } - // }); - // } - // } } diff --git a/server/ControlScripts/Scopes/SpotlightsScope.php b/server/ControlScripts/Scopes/SpotlightsScope.php index ba9c211..269c19d 100644 --- a/server/ControlScripts/Scopes/SpotlightsScope.php +++ b/server/ControlScripts/Scopes/SpotlightsScope.php @@ -67,15 +67,6 @@ "description" => "Управление уличными прожекторами по времени", "author" => "Eugene Sukhodolskiy" ], function () { - // $tz = new \DateTimeZone('Europe/Kyiv'); - - // $now = new \DateTime('now', $tz); - // $from = new \DateTime('9:00', $tz); - // $to = new \DateTime('16:30', $tz); - - // if ($now >= $from && $now <= $to) { - // $this -> all_spotlight_switch(false); - // } }); } @@ -123,39 +114,4 @@ ]; } - // EVENTS HANDLERS - - // 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); - // } - - // $this -> helper() -> sync_btn_channels($this -> sync_map(), $btns_block -> alias); - // }); - // } - - // 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) { - // if($entry[0]["type"] != "relay") { - // continue; - // } - - // $relay_alias = $entry[0]["alias"]; - // $relay_channel = $entry[0]["channel"]; - - // $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($relay_channel); - // $this -> helper() -> sync_relay_to_btns($this -> sync_map(), $relay_alias); - // } - // }); - // } - // } } diff --git a/server/ControlScripts/Scopes/TestScriptsScope.php b/server/ControlScripts/Scopes/TestScriptsScope.php index 803a6a4..1fa3994 100644 --- a/server/ControlScripts/Scopes/TestScriptsScope.php +++ b/server/ControlScripts/Scopes/TestScriptsScope.php @@ -6,7 +6,6 @@ class TestScriptsScope extends \SHServ\Middleware\ControlScripts implements \SHServ\Implements\ControlScriptsInterface { public function register_events_handlers(): void { - // $this -> stand_btn_pressed_to_stand_relay(); } public function register_sync_map(): void { @@ -29,44 +28,6 @@ } public function register_regular_scripts(): void { - // $this -> add_regular_script([ - // "alias" => "regular_script_alias2", - // "name" => "regular script name 2", - // "description" => "regular script description 2", - // "author" => "Eugene Sukhodolskiy" - // ], function() { - // try { - // $button = $this -> devices() -> by_alias("backdoor_buttons"); - // $btn_api = $button -> device_api(); - - // if($btn_api instanceof \SHServ\Tools\DeviceAPI\Button) { - // if(($btn_api -> get_status())["channels"][2]["indicator"] != "error") { - // $btn_api -> set_channel_state("error", 2); - // } else { - // $btn_api -> set_channel_state("mute", 2); - // } - // } - // } catch(\Exception $e) { - // echo $e -> getMessage(); - // } - // }); } - // EVENTS HANDLERS - - // protected function stand_btn_pressed_to_stand_relay() { - // $this -> add_event_handler("button@backdoor_buttons(1).press", function(Device $device, Array $data) { - // $relay = $this -> devices() -> by_alias("stand_relay"); - // $relay -> device_api() -> toggle_channel(0); - // $relay_channels = ($relay -> device_api() -> get_status())["channels"]; - - // $device_api = $device -> device_api(); - // if($device_api instanceof \SHServ\Tools\DeviceAPI\Button) { - // $device_api -> set_channel_state( - // $relay_channels[0]["state"] == "on" ? "enabled" : "disabled", - // $data["channel"] - // ); - // } - // }); - // } } \ No newline at end of file diff --git a/server/ControlScripts/sync-map.json b/server/ControlScripts/sync-map.json new file mode 100644 index 0000000..02e0879 --- /dev/null +++ b/server/ControlScripts/sync-map.json @@ -0,0 +1,88 @@ +[ + [ + {"type": "relay", "alias": "spotlight_main_back_1", "channel": 0}, + {"type": "button", "alias": "buttons_backdoor", "channel": 2}, + {"type": "button", "alias": "master_door_btns", "channel": 1}, + {"type": "button", "alias": "bed_btns_left", "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": 0} + ], + [ + {"type": "relay", "alias": "spotlight_main_front_1", "channel": 0}, + {"type": "button", "alias": "buttons_backdoor", "channel": 0}, + {"type": "button", "alias": "master_door_btns", "channel": 3} + ], + [ + {"type": "relay", "alias": "light_hub_1", "channel": 0}, + {"type": "button", "alias": "buttons_office_room", "channel": 3} + ], + [ + {"type": "relay", "alias": "craft_table_lamp", "channel": 0}, + {"type": "button", "alias": "buttons_office_room", "channel": 2} + ], + [ + {"type": "relay", "alias": "computer_table_lamp", "channel": 0}, + {"type": "button", "alias": "buttons_office_room", "channel": 1} + ], + [ + {"type": "relay", "alias": "light_hub_1", "channel": 2}, + {"type": "button", "alias": "buttons_office_room", "channel": 0}, + {"type": "button", "alias": "master_room_btns", "channel": 1}, + {"type": "button", "alias": "btns_hall2_1", "channel": 0}, + {"type": "button", "alias": "hall_secondary", "channel": 0}, + {"type": "button", "alias": "bed_btns_right_1", "channel": 0} + ], + [ + {"type": "relay", "alias": "light_hub_1", "channel": 1}, + {"type": "button", "alias": "master_room_btns", "channel": 0}, + {"type": "button", "alias": "bed_btns_right_1", "channel": 1}, + {"type": "button", "alias": "bed_btns_left", "channel": 1} + ], + [ + {"type": "relay", "alias": "bathroom_2_light", "channel": 0}, + {"type": "button", "alias": "hall_secondary", "channel": 1} + ], + [ + {"type": "relay", "alias": "plants_room_light", "channel": 0}, + {"type": "button", "alias": "plants_room_btns", "channel": 3} + ], + [ + {"type": "relay", "alias": "italy_lamp_relay", "channel": 0}, + {"type": "button", "alias": "plants_room_btns", "channel": 2} + ], + [ + {"type": "relay", "alias": "floor_lamp_relay", "channel": 0}, + {"type": "button", "alias": "plants_room_btns", "channel": 0} + ], + [ + {"type": "relay", "alias": "server_room_light", "channel": 0}, + {"type": "button", "alias": "btns_hall2_1", "channel": 1} + ], + [ + {"type": "relay", "alias": "fisrt_floor_big_relay", "channel": 0}, + {"type": "button", "alias": "kitchen_buttons_1", "channel": 0}, + {"type": "button", "alias": "kitchen_buttons_2", "channel": 0} + ], + [ + {"type": "relay", "alias": "fisrt_floor_big_relay", "channel": 1}, + {"type": "button", "alias": "kitchen_buttons_1", "channel": 1}, + {"type": "button", "alias": "kitchen_buttons_2", "channel": 1} + ], + [ + {"type": "relay", "alias": "fisrt_floor_big_relay", "channel": 2}, + {"type": "button", "alias": "first_hall_buttons1", "channel": 0} + ], + [ + {"type": "relay", "alias": "fisrt_floor_big_relay", "channel": 3}, + {"type": "button", "alias": "first_hall_buttons1", "channel": 1}, + {"type": "button", "alias": "first_hall_buttons2", "channel": 0} + ], + [ + {"type": "relay", "alias": "fisrt_floor_big_relay", "channel": 4}, + {"type": "button", "alias": "first_hall_buttons1", "channel": 2}, + {"type": "button", "alias": "first_hall_buttons2", "channel": 1} + ] +] \ No newline at end of file diff --git a/server/Fury/Kernel/Logging.php b/server/Fury/Kernel/Logging.php index 3e2a60d..bae8d20 100644 --- a/server/Fury/Kernel/Logging.php +++ b/server/Fury/Kernel/Logging.php @@ -85,14 +85,36 @@ 'logs' => $this -> storage ]; - if(!file_exists($path_to_log_file)){ - file_put_contents($path_to_log_file, ''); - chmod($path_to_log_file, 0755); - return file_put_contents($path_to_log_file, json_encode([$session], JSON_UNESCAPED_SLASHES|JSON_PRETTY_PRINT)); + if(!is_dir($this -> logs_folder)){ + mkdir($this -> logs_folder, 0750, true); } - $logs = json_decode(file_get_contents($path_to_log_file), true); + $fp = fopen($path_to_log_file, 'c+'); + if($fp === false) { + return false; + } + + if(!flock($fp, LOCK_EX)) { + fclose($fp); + return false; + } + + $raw = stream_get_contents($fp); + $logs = $raw ? json_decode($raw, true) : []; + if(!is_array($logs)) { + $logs = []; + } $logs[] = $session; - return file_put_contents($path_to_log_file, json_encode($logs, JSON_UNESCAPED_SLASHES|JSON_PRETTY_PRINT)); + + ftruncate($fp, 0); + rewind($fp); + $result = fwrite($fp, json_encode($logs, JSON_UNESCAPED_SLASHES|JSON_PRETTY_PRINT)); + fflush($fp); + flock($fp, LOCK_UN); + fclose($fp); + + chmod($path_to_log_file, 0640); + + return $result !== false; } } \ No newline at end of file diff --git a/server/SHServ/App.php b/server/SHServ/App.php index b1f39bb..de9e06e 100644 --- a/server/SHServ/App.php +++ b/server/SHServ/App.php @@ -32,8 +32,6 @@ $this -> console_flag = isset($argv) ? true : false; $this -> app_init(); - $scripts = new \SHServ\Models\Scripts(); - $scripts -> set_script_state("action", "spotlights_off", true); } public function app_init(): void { @@ -103,8 +101,7 @@ } public function root_folder(): String { - list($root) = explode('SHServ', __DIR__); - return $root; + return dirname(__DIR__, 2); } protected function router_json_to_post_emulate(): void { @@ -129,9 +126,10 @@ public function control_scripts_init(): void { $this -> required_control_scripts_instance = new \SHServ\RequiredControlScriptsScope(); - $scripts_dir = scandir(__DIR__ . "/../ControlScripts/Scopes/"); - $scripts = array_filter($scripts_dir, function($item) { - return !is_dir($item) and (pathinfo($item))["extension"] == "php"; + $scopes_dir = __DIR__ . "/../ControlScripts/Scopes/"; + $scripts_dir = scandir($scopes_dir); + $scripts = array_filter($scripts_dir, function($item) use ($scopes_dir) { + return !is_dir($scopes_dir . $item) and (pathinfo($item))["extension"] == "php"; }); foreach($scripts as $script_name) { diff --git a/server/SHServ/Controllers/AreasRESTAPIController.php b/server/SHServ/Controllers/AreasRESTAPIController.php index a8e3b84..975a264 100644 --- a/server/SHServ/Controllers/AreasRESTAPIController.php +++ b/server/SHServ/Controllers/AreasRESTAPIController.php @@ -110,12 +110,11 @@ * @return String JSON. Вернёт ошибку или положительный результат */ public function place_in_area($target_id, $place_in_area_id) { - if($target_id != intval($target_id) or intval($target_id) < 1) { - return $this -> utils() -> response_error("invalid_id", ["target_id"]); - } - - if($place_in_area_id != intval($place_in_area_id) or intval($place_in_area_id) < 1) { - return $this -> utils() -> response_error("invalid_id", ["place_in_area_id"]); + if ($error = $this -> validate_positive_int_ids([ + 'target_id' => $target_id, + 'place_in_area_id' => $place_in_area_id, + ])) { + return $error; } $target_area = new Area(intval($target_id)); diff --git a/server/SHServ/Controllers/DevicesRESTAPIController.php b/server/SHServ/Controllers/DevicesRESTAPIController.php index 0ee2818..cddb6e2 100644 --- a/server/SHServ/Controllers/DevicesRESTAPIController.php +++ b/server/SHServ/Controllers/DevicesRESTAPIController.php @@ -252,12 +252,11 @@ } public function place_in_area($target_id, $place_in_area_id) { - if($target_id != intval($target_id) or intval($target_id) < 1) { - return $this -> utils() -> response_error("invalid_id", ["target_id"]); - } - - if($place_in_area_id != intval($place_in_area_id) or intval($place_in_area_id) < 1) { - return $this -> utils() -> response_error("invalid_id", ["place_in_area_id"]); + if ($error = $this -> validate_positive_int_ids([ + 'target_id' => $target_id, + 'place_in_area_id' => $place_in_area_id, + ])) { + return $error; } $device = new Device(intval($target_id)); @@ -279,8 +278,8 @@ } public function unassign_from_area($target_id) { - if($target_id != intval($target_id) or intval($target_id) < 1) { - return $this -> utils() -> response_error("invalid_id", ["target_id"]); + if ($error = $this -> validate_positive_int_ids(['target_id' => $target_id])) { + return $error; } $device = new Device(intval($target_id)); diff --git a/server/SHServ/Controllers/ScriptsRESTAPIController.php b/server/SHServ/Controllers/ScriptsRESTAPIController.php index 9021c35..9007db8 100644 --- a/server/SHServ/Controllers/ScriptsRESTAPIController.php +++ b/server/SHServ/Controllers/ScriptsRESTAPIController.php @@ -164,18 +164,18 @@ return $this -> utils() -> response_error("invalid_id", ["place_in_area_id"]); } - $device = new Script(intval($target_id)); + $script = new Script(intval($target_id)); $place_area = new Area(intval($place_in_area_id)); - if(!$device) { - return $this -> utils() -> response_error("device_not_found"); + if(!$script) { + return $this -> utils() -> response_error("script_not_exists"); } if(!$place_area) { return $this -> utils() -> response_error("area_not_exists"); } - if(!$device -> place_in_area($place_area)) { + if(!$script -> place_in_area($place_area)) { return $this -> utils() -> response_error("undefined_error"); } diff --git a/server/SHServ/Entities/User.php b/server/SHServ/Entities/User.php index 45bf131..8d17d63 100644 --- a/server/SHServ/Entities/User.php +++ b/server/SHServ/Entities/User.php @@ -11,15 +11,23 @@ "id", "role", "nickname", "password", "create_at", "update_at" ]; - protected Profile $profile; - + protected ?Profile $profile = null; + public function __construct(Int $uid, Array $data = []) { parent::__construct(self::$table_name, $uid, $data); - // TODO: `uid` - is fail, need `profile_id` - $this -> profile = new Profile($uid); - } - public function profile(): Profile { + $profile_data = app() -> thin_builder -> select( + Profile::$table_name, + Profile::get_fields(), + [["uid", "=", $uid]] + ); + + if($profile_data) { + $this -> profile = new Profile($profile_data[0]["id"], $profile_data[0]); + } + } + + public function profile(): ?Profile { return $this -> profile; } diff --git a/server/SHServ/Middleware/Controller.php b/server/SHServ/Middleware/Controller.php index 7fe5ecd..2cc7e46 100644 --- a/server/SHServ/Middleware/Controller.php +++ b/server/SHServ/Middleware/Controller.php @@ -16,4 +16,19 @@ public function utils() { return app() -> utils; } + + /** + * Валидирует, что переданные ID — положительные целые числа. + * + * @param array $ids Ассоциативный массив [имя_параметра => значение] + * @return array|null Ошибка response_error или null если всё ок + */ + protected function validate_positive_int_ids(array $ids): ?array { + foreach ($ids as $name => $value) { + if ($value != intval($value) || intval($value) < 1) { + return $this -> utils() -> response_error("invalid_id", [$name]); + } + } + return null; + } } \ No newline at end of file diff --git a/server/SHServ/Models/Areas.php b/server/SHServ/Models/Areas.php index 3579865..1b9b87f 100644 --- a/server/SHServ/Models/Areas.php +++ b/server/SHServ/Models/Areas.php @@ -5,6 +5,8 @@ use \SHServ\Entities\Area; class Areas extends \SHServ\Middleware\Model { + private const MAX_LIMIT = 1000; + public function create_new_area(String $type, String $alias, String $display_name): Area | null { if(!$this -> alias_is_uniq($alias)) { return null; @@ -89,7 +91,7 @@ Area::$table_name, Area::get_fields(), [], - [], "DESC", [ 1000 ] + [], "DESC", [ self::MAX_LIMIT ] ); $areas = []; diff --git a/server/SHServ/Tools/DeviceAPI/Hatch.php b/server/SHServ/Tools/DeviceAPI/Hatch.php index af5ca05..3aa7e98 100644 --- a/server/SHServ/Tools/DeviceAPI/Hatch.php +++ b/server/SHServ/Tools/DeviceAPI/Hatch.php @@ -10,7 +10,7 @@ return null; } - return $status_response["hatch"]["state"]; + return $state; } public function is_opened(): Bool | null { @@ -18,7 +18,7 @@ return is_null($state) ? null - : $status_response["hatch"]["state"] == "open"; + : $state == "open"; } public function is_closed(): Bool | null { @@ -26,7 +26,7 @@ return is_null($state) ? null - : $status_response["hatch"]["state"] == "closed"; + : $state == "closed"; } public function is_opening(): Bool | null { @@ -34,7 +34,7 @@ return is_null($state) ? null - : $status_response["hatch"]["state"] == "opening"; + : $state == "opening"; } public function is_closing(): Bool { @@ -42,7 +42,7 @@ return is_null($state) ? null - : $status_response["hatch"]["state"] == "closing"; + : $state == "closing"; } public function open(int $percent = 100) { diff --git a/server/SHServ/config.php b/server/SHServ/config.php index ecd670f..62ea1bd 100644 --- a/server/SHServ/config.php +++ b/server/SHServ/config.php @@ -30,7 +30,7 @@ "app_file" => "App.php", "templates_folder" => "Templates", "logs_enable" => true, - "logs_folder" => "SHServ/Logs", + "logs_folder" => dirname(__DIR__, 2) . "/Logs", "devmode" => ($env['DEVMODE'] ?? "false") === "true", "controllers_folder" => "Controllers",