diff --git a/.github/workflows/style.yml b/.github/workflows/style.yml index 373be34..e11e82a 100644 --- a/.github/workflows/style.yml +++ b/.github/workflows/style.yml @@ -7,20 +7,7 @@ jobs: style: runs-on: ubuntu-latest steps: - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: 8.2 - - name: Checkout module - uses: actions/checkout@master - - run: git submodule update --init -- .style - shell: bash - - run: wget https://cs.symfony.com/download/php-cs-fixer-v3.phar - shell: bash - - run: php php-cs-fixer-v3.phar fix --config=.style/.php-cs-fixer.php -v --dry-run --allow-risky=yes --path-mode=intersection . - shell: bash - - run: | - if [[ -f ".style/json-check.php" ]]; then - php .style/json-check.php fix . - fi - shell: bash \ No newline at end of file + - name: Checkout module + uses: actions/checkout@master + - name: Check style + uses: ubittner/action-style@master \ No newline at end of file diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index cf7f84f..5773940 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -5,16 +5,16 @@ on: [push, pull_request] jobs: test: - + runs-on: ubuntu-latest - + steps: - - uses: actions/checkout@master - with: + - uses: actions/checkout@master + with: submodules: true - - name: Install PHPUnit - run: wget https://phar.phpunit.de/phpunit-9.6.3.phar + - name: Install PHPUnit + run: wget https://phar.phpunit.de/phpunit-10.1.3.phar - - name: Run Tests - run: phpdbg -qrr phpunit-9.6.3.phar tests --configuration tests/phpunit.xml \ No newline at end of file + - name: Run Tests + run: phpdbg -qrr phpunit-10.1.3.phar tests --configuration tests/phpunit.xml \ No newline at end of file diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..c10692f --- /dev/null +++ b/.gitmodules @@ -0,0 +1,6 @@ +[submodule ".style"] + path = .style + url = https://github.com/ubittner/StylePHP +[submodule "tests/stubs"] + path = tests/stubs + url = https://github.com/ubittner/SymconStubs diff --git a/.style b/.style new file mode 160000 index 0000000..ec73bf7 --- /dev/null +++ b/.style @@ -0,0 +1 @@ +Subproject commit ec73bf742e18b049ad5c90de09033987d3ce671e diff --git a/.style/.php-cs-fixer.php b/.style/.php-cs-fixer.php deleted file mode 100644 index b89b920..0000000 --- a/.style/.php-cs-fixer.php +++ /dev/null @@ -1,185 +0,0 @@ -exclude('tests/stubs') // exclude the tests-stubs, but not the tests for this module - ->notPath('/libs\/.*\//') // regex, exclude only dirs in libs, not the files - ->in(__DIR__.'/../'); // fix path to run, __DIR__ point to /.style -> so no checks are running :( - -$config = new PhpCsFixer\Config(); - return $config->setRules([ - 'align_multiline_comment' => [ - 'comment_type' => 'all_multiline' - ], - 'array_indentation' => true, - 'array_syntax' => [ - 'syntax' => 'short' - ], - //backtick_to_shell_exec - 'binary_operator_spaces' => [ - 'operators' => [ - '=>' => 'align' - ] - ], - 'blank_line_after_namespace' => true, - 'blank_line_after_opening_tag' => true, - 'blank_line_before_statement' => false, - 'braces' => [ - 'position_after_anonymous_constructs' => 'next', - 'position_after_control_structures' => 'same', - 'position_after_functions_and_oop_constructs' => 'next' - ], - 'cast_spaces' => true, - 'class_attributes_separation' => false, - 'class_definition' => true, - //class_keyword_remove - //combine_consecutive_issets - //combine_consecutive_unsets - //combine_nested_dirname - //comment_to_phpdoc - //compact_nullable_typehint - 'concat_space' => [ - 'spacing' => 'one' - ], - //date_time_immutable - 'declare_strict_types' => true, - 'declare_equal_normalize' => true, - 'declare_strict_types' => true, - //dir_constant - 'elseif' => true, - 'encoding' => true, - //ereg_to_preg - //error_suppression - //escape_implicit_backslashes - //explicit_indirect_variable - //explicit_string_variable - //final_class - //final_internal_class - //fopen_flag_order - //fopen_flags - 'full_opening_tag' => true, - //fully_qualified_strict_types - 'function_declaration' => true, - //function_to_constant - 'function_typehint_space' => true, - //header_comment - 'implode_call' => true, - 'include' => true, - //increment_style - 'indentation_type' => true, - //is_null - 'line_ending' => true, - 'linebreak_after_opening_tag' => true, - //list_syntax - 'logical_operators' => true, - 'lowercase_cast' => true, - 'constant_case' => true, - 'lowercase_keywords' => true, - 'lowercase_static_reference' => true, - 'magic_constant_casing' => true, - 'magic_method_casing' => true, - //mb_str_functions - 'method_argument_space' => true, - 'method_chaining_indentation' => true, - //modernize_types_casting - 'multiline_comment_opening_closing' => true, - 'multiline_whitespace_before_semicolons' => true, - //native_constant_invocation - 'native_function_casing' => true, - //native_function_invocation - 'native_function_type_declaration_casing' => true, - 'new_with_braces' => true, - 'no_alias_functions' => true, - 'no_alternative_syntax' => true, - //no_binary_string - 'no_blank_lines_after_class_opening' => true, - 'no_blank_lines_after_phpdoc' => true, - 'no_blank_lines_before_namespace' => false, - 'no_break_comment' => [ - 'comment_text' => 'No break. Add additional comment above this line if intentional' - ], - 'no_closing_tag' => true, - 'no_empty_comment' => true, - 'no_empty_phpdoc' => true, - 'no_empty_statement' => true, - 'no_extra_blank_lines' => true, - //no_homoglyph_names - //no_leading_import_slash - 'no_leading_namespace_whitespace' => true, - 'no_mixed_echo_print' => true, - 'no_multiline_whitespace_around_double_arrow' => true, - //no_null_property_initialization - //no_short_bool_cast - 'echo_tag_syntax' => true, - 'no_singleline_whitespace_before_semicolons'=> true, - 'no_spaces_after_function_name' => true, - 'no_spaces_around_offset' => true, - 'no_spaces_inside_parenthesis' => true, - //no_superfluous_elseif - //no_superfluous_phpdoc_tags - 'no_trailing_comma_in_list_call' => true, - 'no_trailing_comma_in_singleline_array' => true, - 'no_trailing_whitespace' => true, - 'no_trailing_whitespace_in_comment' => true, - 'no_unneeded_control_parentheses' => true, - 'no_unneeded_curly_braces' => false, - //no_unneeded_final_method - //no_unset_cast - //no_unset_on_property - //no_unused_imports - 'no_useless_else' => false, - 'no_useless_return' => false, - 'no_whitespace_before_comma_in_array' => true, - 'no_whitespace_in_blank_line' => true, - //non_printable_character - 'normalize_index_brace'=> true, - 'not_operator_with_space' => false, - 'not_operator_with_successor_space' => false, - 'object_operator_without_whitespace' => true, - 'ordered_class_elements' => true, - 'ordered_imports' => true, - 'ordered_interfaces' => true, - //php_unit_* - //php_doc_* - 'pow_to_exponentiation' => false, - 'protected_to_private' => false, - //psr0 - //psr4 - //random_api_migration - //return_assignment - 'return_type_declaration' => true, - 'self_accessor' => true, - 'semicolon_after_instruction' => true, - //set_type_to_cast - //short_scalar_cast - //simple_to_complex_string_variable - //simplified_null_return - //single_blank_line_at_eof - 'single_blank_line_before_namespace' => true, - 'single_class_element_per_statement' => true, - 'single_import_per_statement' => true, - 'single_line_after_imports' => true, - //single_line_comment_style - 'single_quote' => true, - 'single_trait_insert_per_statement' => true, - 'space_after_semicolon' => true, - //standardize_increment - 'standardize_not_equals' => true, - //static_lambda - //strict_comparison - //strict_param - //string_line_ending - 'switch_case_semicolon_to_colon' => true, - 'switch_case_space' => true, - 'ternary_operator_spaces' => true, - //ternary_to_null_coalescing - 'trailing_comma_in_multiline' => false, - 'trim_array_spaces' => true, - 'unary_operator_spaces' => true, - 'visibility_required' => true, - //void_return - 'whitespace_after_comma_in_array' => true, - //yoda_style - ]) - ->setFinder($finder) - ->setIndent(" ") - ->setLineEnding("\n"); diff --git a/.style/json-check.php b/.style/json-check.php deleted file mode 100644 index 896110e..0000000 --- a/.style/json-check.php +++ /dev/null @@ -1,85 +0,0 @@ -RegisterPropertyBoolean('UseKeypad', false); $this->RegisterPropertyBoolean('UseProtocol', true); $this->RegisterPropertyInteger('ProtocolMaximumEntries', 5); + $this->RegisterPropertyBoolean('UseEventVariables', false); ##### Variables @@ -236,6 +237,42 @@ public function ApplyChanges(): void $this->WriteAttributeString('Protocol', '[]'); } $this->UpdateProtocol(); + + //Event variables + $keep = true; + if (!$this->ReadPropertyBoolean('UseEventVariables')) { + $keep = false; + } + //Lock action + $id = @$this->GetIDForIdent('EventLockAction'); + $this->MaintainVariable('EventLockAction', $this->Translate('Lock Action'), 1, '', 200, $keep); + if (!$id && $keep) { + IPS_SetIcon($this->GetIDForIdent('EventLockAction'), 'Information'); + } + //Event trigger + $id = @$this->GetIDForIdent('EventTrigger'); + $this->MaintainVariable('EventTrigger', $this->Translate('Trigger'), 1, '', 210, $keep); + if (!$id && $keep) { + IPS_SetIcon($this->GetIDForIdent('EventTrigger'), 'Information'); + } + //Auth ID + $id = @$this->GetIDForIdent('EventAuthID'); + $this->MaintainVariable('EventAuthID', $this->Translate('Auth-ID'), 1, '', 220, $keep); + if (!$id && $keep) { + IPS_SetIcon($this->GetIDForIdent('EventAuthID'), 'Information'); + } + //Code ID + $id = @$this->GetIDForIdent('EventCodeID'); + $this->MaintainVariable('EventCodeID', $this->Translate('Code-ID'), 1, '', 230, $keep); + if (!$id && $keep) { + IPS_SetIcon($this->GetIDForIdent('EventCodeID'), 'Information'); + } + //Auto unlock + $id = @$this->GetIDForIdent('EventAutoUnlock'); + $this->MaintainVariable('EventAutoUnlock', $this->Translate('Auto Unlock'), 1, '', 240, $keep); + if (!$id && $keep) { + IPS_SetIcon($this->GetIDForIdent('EventAutoUnlock'), 'Information'); + } } public function Destroy(): void @@ -623,9 +660,9 @@ public function ReceiveData($JSONString): string */ $this->SendDebug(__FUNCTION__, 'lockActionEvent: ' . $payload, 0); $this->WriteAttributeString('LockActionEvent', $payload); + $data = explode(',', $payload); if ($this->ReadPropertyBoolean('UseProtocol')) { $existingData = json_decode($this->ReadAttributeString('Protocol'), true); - $data = explode(',', $payload); $newData = [ 'timestamp' => date('d.m.Y H:i:s'), 'lockAction' => $data[0], @@ -637,6 +674,14 @@ public function ReceiveData($JSONString): string $this->WriteAttributeString('Protocol', json_encode($existingData)); $this->UpdateProtocol(); } + //Event variables + if ($this->ReadPropertyBoolean('UseEventVariables')) { + $this->SetValue('EventLockAction', $data[0]); + $this->SetValue('EventTrigger', $data[1]); + $this->SetValue('EventAuthID', $data[2]); + $this->SetValue('EventCodeID', $data[3]); + $this->SetValue('EventAutoUnlock', $data[4]); + } break; } } else { @@ -676,7 +721,7 @@ public function Lock(): void $Data['QualityOfService'] = 0; $Data['Retain'] = false; $Data['Topic'] = $this->ReadPropertyString('MQTTTopic') . '/lock'; - $Data['Payload'] = 'true'; + $Data['Payload'] = bin2hex('true'); $DataJSON = json_encode($Data, JSON_UNESCAPED_SLASHES); $this->SendDebug(__FUNCTION__ . ' Topic', $Data['Topic'], 0); $this->SendDebug(__FUNCTION__ . ' Data', $DataJSON, 0); @@ -701,7 +746,7 @@ public function UnLock(): void $Data['QualityOfService'] = 0; $Data['Retain'] = false; $Data['Topic'] = $this->ReadPropertyString('MQTTTopic') . '/unlock'; - $Data['Payload'] = 'true'; + $Data['Payload'] = bin2hex('true'); $DataJSON = json_encode($Data, JSON_UNESCAPED_SLASHES); $this->SendDebug(__FUNCTION__ . ' Topic', $Data['Topic'], 0); $this->SendDebug(__FUNCTION__ . ' Data', $DataJSON, 0); @@ -743,7 +788,7 @@ public function SetLockAction(int $Action): void $Data['QualityOfService'] = 0; $Data['Retain'] = false; $Data['Topic'] = $this->ReadPropertyString('MQTTTopic') . '/lockAction'; - $Data['Payload'] = strval($Action); + $Data['Payload'] = bin2hex(strval($Action)); $DataJSON = json_encode($Data, JSON_UNESCAPED_SLASHES); $this->SendDebug(__FUNCTION__ . ' Topic', $Data['Topic'], 0); $this->SendDebug(__FUNCTION__ . ' Data', $DataJSON, 0); diff --git a/library.json b/library.json index dc515b6..8c68ca7 100644 --- a/library.json +++ b/library.json @@ -7,6 +7,6 @@ "version": "7.0" }, "version": "1.0", - "build": 7, - "date": 1698527349 + "build": 8, + "date": 1706948336 } \ No newline at end of file diff --git a/tests/stubs b/tests/stubs new file mode 160000 index 0000000..858e2b2 --- /dev/null +++ b/tests/stubs @@ -0,0 +1 @@ +Subproject commit 858e2b224485b1b4eb18875a54d07ef17c0f6d76 diff --git a/tests/stubs/.github/workflows/style.yml b/tests/stubs/.github/workflows/style.yml deleted file mode 100644 index 714b5b5..0000000 --- a/tests/stubs/.github/workflows/style.yml +++ /dev/null @@ -1,13 +0,0 @@ -name: Check Style - -on: [push, pull_request] - -jobs: - - style: - runs-on: ubuntu-latest - steps: - - name: Checkout module - uses: actions/checkout@master - - name: Check style - uses: symcon/action-style@master \ No newline at end of file diff --git a/tests/stubs/.github/workflows/tests.yml b/tests/stubs/.github/workflows/tests.yml deleted file mode 100644 index 1c9d116..0000000 --- a/tests/stubs/.github/workflows/tests.yml +++ /dev/null @@ -1,15 +0,0 @@ -name: Run Tests - -on: [push, pull_request] - -jobs: - - test: - runs-on: ubuntu-latest - steps: - - name: Checkout module - uses: actions/checkout@master - with: - submodules: true - - name: Run tests - uses: symcon/action-tests@master \ No newline at end of file diff --git a/tests/stubs/.gitignore b/tests/stubs/.gitignore deleted file mode 100644 index c013e4b..0000000 --- a/tests/stubs/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -.DS_Store -.idea/ -.phpunit.* -.php_cs.cache \ No newline at end of file diff --git a/tests/stubs/.gitmodules b/tests/stubs/.gitmodules deleted file mode 100644 index 1c392fb..0000000 --- a/tests/stubs/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule ".style"] - path = .style - url = https://github.com/symcon/StylePHP diff --git a/tests/stubs/ConstantStubs.php b/tests/stubs/ConstantStubs.php deleted file mode 100644 index fcd9058..0000000 --- a/tests/stubs/ConstantStubs.php +++ /dev/null @@ -1,71 +0,0 @@ -GetLoggingStatus($VariableID)) { - throw new Exception('Adding aggregated data requires active logging'); - } - usort($AggregationData, function ($a, $b) - { - return $a['TimeStamp'] <=> $b['TimeStamp']; - }); - $archivedData = $this->GetVariableData($VariableID); - $aggregatedArchiveData = $archivedData['AggregatedValues'][$AggregationSpan]; - if ((count($aggregatedArchiveData) > 0) && (count($AggregationData) > 0) && - ($AggregationData[0]['TimeStamp'] < $aggregatedArchiveData[count($aggregatedArchiveData) - 1]['TimeStamp'])) { - throw new Exception('It is not yet possible to add aggregated values before the newest'); - } - $archivedData['AggregatedValues'][$AggregationSpan] = array_merge($aggregatedArchiveData, $AggregationData); - $this->SetVariableData($VariableID, $archivedData); - } - - public function AddLoggedValues(int $VariableID, array $NewData) - { - if (!$this->GetLoggingStatus($VariableID)) { - throw new Exception('Adding logged data requires active logging'); - } - usort($NewData, function ($a, $b) - { - return $a['TimeStamp'] <=> $b['TimeStamp']; - }); - $archivedData = $this->GetVariableData($VariableID); - $loggedArchiveData = $archivedData['Values']; - if ((count($loggedArchiveData) > 0) && (count($NewData) > 0) && - ($NewData[0]['TimeStamp'] < $loggedArchiveData[count($loggedArchiveData) - 1]['TimeStamp'])) { - throw new Exception('It is not yet possible to add values before the newest'); - } - - $archivedData['Values'] = array_merge($loggedArchiveData, $NewData); - $this->SetVariableData($VariableID, $archivedData); - } - - public function ChangeVariableID(int $OldVariableID, int $NewVariableID) - { - throw new Exception("'ChangeVariableID' is not yet implemented"); - } - - public function DeleteVariableData(int $VariableID, int $StartTime, int $EndTime) - { - $archivedData = $this->GetVariableData($VariableID); - $Values = $archivedData['Values']; - - if ($StartTime === 0 && $EndTime === 0) { - $this->SetLoggingStatus($VariableID, false); - } - - //The array is empty, nothing to delete - if (count($Values) === 0) { - return 0; - } - - //Get the first and last timestamp if it is necessary - if (array_key_exists('TimeStamp', $Values)) { - if ($EndTime === 0 || $EndTime < end($Values)['TimeStamp']) { - $EndTime = end($Values)['TimeStamp']; - } - if ($StartTime === 0 || $StartTime > reset($Values)['TimeStamp']) { - $StartTime = reset($Values)['TimeStamp']; - } - } - - //Get the Start and endkey and delete the values between them - $endKey = count($Values); - reset($Values); - $startKey = key($Values); - - foreach ($Values as $key => $value) { - if ($value['TimeStamp'] < $StartTime) { - $startKey = $key + 1; - } else { - break; - } - } - foreach ($Values as $key => $value) { - if ($value['TimeStamp'] > $EndTime) { - $endKey = $key; - break; - } - } - - $slicedData = array_slice($Values, $startKey, $endKey - $startKey, true); - //Only keep the values that are not in the sliced Data - $callback = function ($key) use ($slicedData) - { - return !array_key_exists($key, $slicedData); - }; - $loggedValues = array_filter($Values, $callback, ARRAY_FILTER_USE_KEY); - - $archivedData['Values'] = array_values($loggedValues); - $this->SetVariableData($VariableID, $archivedData); - - return count($slicedData); - } - - public function GetAggregatedValues(int $VariableID, int $AggregationSpan, int $StartTime, int $EndTime, int $Limit) - { - if (empty($this->Archive[$VariableID]['AggregatedValues'][$AggregationSpan])) { - throw new Exception('Aggregated data has to be added through the function AC_StubsAddAggregatedValues()'); - } - if ($Limit > 10000 || $Limit == 0) { - $Limit = 10000; - } - $archivedData = $this->GetVariableData($VariableID); - $aggregatedArchiveData = $archivedData['AggregatedValues'][$AggregationSpan]; - $return = []; - foreach (array_reverse($aggregatedArchiveData) as $data) { - if (count($return) < $Limit) { - if (($data['TimeStamp'] >= $StartTime) && ($EndTime == 0 || (($data['TimeStamp'] + $data['Duration'] - 1) <= $EndTime))) { - $return[] = $data; - } - } else { - return $return; - } - } - return $return; - } - - public function GetAggregationType(int $VariableID) - { - return $this->GetVariableData($VariableID)['AggregationType']; - } - - //Only AggregationActive, AggregationType and VariableID work properly - public function GetAggregationVariables(bool $DatabaseRequest) - { - $aggregationVariables = []; - foreach ($this->Archive as $id => $data) { - $recordCount = 0; - foreach ($data['AggregatedValues'] as $values) { - $recordCount += count($values); - } - $aggregationVariables[] = [ - 'FirstTime' => 0, - 'LastTime' => 0, - 'RecordCount' => $recordCount, - 'RecordSize' => 0, - 'VariableID' => $id, - 'AggregationType' => $data['AggregationType'], - 'AggregationVisible' => false, - 'AggregationActive' => $data['AggregationActive'] - ]; - } - - //display hint that this function is not fully implemented - echo PHP_EOL . 'AC_GetAggregationVariables NOT FULLY IMPLEMENTED' . PHP_EOL; - - return $aggregationVariables; - } - - public function GetGraphStatus(int $VariableID) - { - throw new Exception("'GetGraphStatus' is not yet implemented"); - } - - public function GetLoggedValues(int $VariableID, int $StartTime, int $EndTime, int $Limit = 10000) - { - if ($Limit > 10000 || $Limit == 0) { - $Limit = 10000; - } - $archivedData = array_reverse($this->GetVariableData($VariableID)['Values']); - $return = []; - foreach ($archivedData as $data) { - if (count($return) < $Limit) { - if (($data['TimeStamp'] >= $StartTime) && ($data['TimeStamp'] <= $EndTime)) { - $return[] = $data; - } - } else { - return $return; - } - } - return $return; - } - - public function GetLoggingStatus(int $VariableID) - { - return $this->GetVariableData($VariableID)['AggregationActive']; - } - - public function ReAggregateVariable(int $VariableID) - { - throw new Exception("'ReAggregateVariable' is not yet implemented"); - } - - public function SetAggregationType(int $VariableID, int $AggregationType) - { - $data = $this->GetVariableData($VariableID); - $data['AggregationType'] = $AggregationType; - $this->SetVariableData($VariableID, $data); - } - - public function SetGraphStatus(int $VariableID) - { - throw new Exception("'SetGraphStatus' is not yet implemented"); - } - - // Status will be updated without ApplyChanges() unlike current (5.4) IP-Symcon implementation - // However, this will change in IP-Symcon with the archive rebuild - public function SetLoggingStatus(int $VariableID, bool $Active) - { - $data = $this->GetVariableData($VariableID); - $data['AggregationActive'] = $Active; - $this->SetVariableData($VariableID, $data); - } - - private function GetVariableData($VariableID) - { - if (empty($this->Archive[$VariableID])) { - $this->Archive[$VariableID] = [ - 'AggregationActive' => false, - 'Values' => [], - 'AggregationType' => 0, - 'AggregatedValues' => [ - 0 /* Hourly */ => [], - 1 /* Daily */ => [], - 2 /* Weekly */ => [], - 3 /* Monthly */ => [], - 4 /* Yearly */ => [], - 5 /* 5-Minute */=> [], - 6 /* 1-Minute */=> [] - ] - ]; - } - return $this->Archive[$VariableID]; - } - - private function SetVariableData($VariableID, $Data) - { - $this->Archive[$VariableID] = $Data; - } -} diff --git a/tests/stubs/CoreStubs/ConnectControl/module.json b/tests/stubs/CoreStubs/ConnectControl/module.json deleted file mode 100644 index 5ec26ab..0000000 --- a/tests/stubs/CoreStubs/ConnectControl/module.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "id": "{9486D575-BE8C-4ED8-B5B5-20930E26DE6F}", - "name": "Connect Control", - "type": 0, - "vendor": "Symcon GmbH", - "aliases": [], - "url": "", - "parentRequirements": [], - "childRequirements": [], - "implemented": [], - "prefix": "CC" -} \ No newline at end of file diff --git a/tests/stubs/CoreStubs/ConnectControl/module.php b/tests/stubs/CoreStubs/ConnectControl/module.php deleted file mode 100644 index f835e28..0000000 --- a/tests/stubs/CoreStubs/ConnectControl/module.php +++ /dev/null @@ -1,46 +0,0 @@ -RegisterPropertyString('Services', '[]'); - } -} diff --git a/tests/stubs/CoreStubs/Util Control/module.json b/tests/stubs/CoreStubs/Util Control/module.json deleted file mode 100644 index 5a3a5a2..0000000 --- a/tests/stubs/CoreStubs/Util Control/module.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "id": "{B69010EA-96D5-46DF-B885-24821B8C8DBD}", - "name": "Util Control", - "type": 0, - "vendor": "Symcon GmbH", - "aliases": [], - "url": "https://www.symcon.de/service/dokumentation/modulreferenz/util-control/", - "parentRequirements": [], - "childRequirements": [], - "implemented": [], - "prefix": "UC" -} \ No newline at end of file diff --git a/tests/stubs/CoreStubs/Util Control/module.php b/tests/stubs/CoreStubs/Util Control/module.php deleted file mode 100644 index 638879a..0000000 --- a/tests/stubs/CoreStubs/Util Control/module.php +++ /dev/null @@ -1,16 +0,0 @@ -connections; - } - - public function StubsAnswerOutgoingCall(int $ConnectionID) - { - $this->setConnected($ConnectionID, true); - } - - public function StubsRejectOutgoingCall(int $ConnectionID) - { - $this->setConnected($ConnectionID, false); - } - - public function Create() - { - parent::Create(); - - $this->RegisterPropertyInteger('ProcessingScript', 0); - } - - public function AcceptCall(int $ConnectionID) - { - throw new Exception('Not implemented'); - } - - public function Connect(string $Number) - { - return $this->createCall($Number); - } - - public function Disconnect(int $ConnectionID) - { - if (!isset($this->connections[$ConnectionID])) { - throw new Exception(sprintf('Connection for ID %d does not exist', $ConnectionID)); - } - $this->setConnected($ConnectionID, false); - } - - public function GetConnection(int $ConnectionID) - { - return $this->connections[$ConnectionID]; - } - - public function GetData(int $ConnectionID) - { - throw new Exception('Not implemented'); - } - - public function PlayWave(int $ConnectionID, int $FileName) - { - throw new Exception('Not implemented'); - } - - public function RejectCall(int $ConnectionID) - { - throw new Exception('Not implemented'); - } - - public function SendDTMF(int $ConnectionID, string $DTMF) - { - throw new Exception('Not implemented'); - } - - public function SetData(int $ConnectionID, string $Data) - { - throw new Exception('Not implemented'); - } - - private function createCall(string $number) - { - $id = $this->newID; - $this->connections[$id] = [ - 'ID' => $id, - 'TimeStamp' => time(), - 'Number' => $number, - 'Direction' => 1, - 'Connected' => false, - 'Disconnected' => false - ]; - - //increment id - $this->newID++; - return $id; - } - - private function setConnected(int $connectionID, bool $connected) - { - $this->connections[$connectionID]['Connected'] = $connected; - $this->connections[$connectionID]['Disconnected'] = !$connected; - } -} \ No newline at end of file diff --git a/tests/stubs/CoreStubs/library.json b/tests/stubs/CoreStubs/library.json deleted file mode 100644 index 66f7f15..0000000 --- a/tests/stubs/CoreStubs/library.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "id": "{476D38F5-09FC-459A-BE64-D79D5A17085B}", - "author": "Michael Maroszek", - "name": "Core Stubs", - "url": "https://www.symcon.de/", - "version": "1.0", - "build": 0, - "date": 0 -} \ No newline at end of file diff --git a/tests/stubs/GlobalStubs.php b/tests/stubs/GlobalStubs.php deleted file mode 100644 index 4878a44..0000000 --- a/tests/stubs/GlobalStubs.php +++ /dev/null @@ -1,1416 +0,0 @@ - 0)) { - return $addPrefixSuffix(round(($Value - $profile['MinValue']) * 100 / ($profile['MaxValue'] - $profile['MinValue']))); - } - - return $addPrefixSuffix($Value); - - case 2: //Float - if ((trim($profile['Suffix']) === '%') && (($profile['MaxValue'] - $profile['MinValue']) > 0)) { - return $addPrefixSuffix(number_format(round(($Value - $profile['MinValue']) * 100 / ($profile['MaxValue'] - $profile['MinValue'])), $profile['Digits'])); - } - - return $addPrefixSuffix(number_format(round($Value), $profile['Digits'])); - - case 3: //String - return $addPrefixSuffix($Value); - - default: - throw new Exception('Format error: Invalid variable type'); - - } - } else { - switch ($profile['ProfileType']) { - case 0: //Boolean - if (count($profile['Associations']) < 2) { - throw new Exception('Profiles of type boolean need to have two associations'); - } - - if ($Value === true) { - return $profile['Associations'][1]['Name']; - } elseif ($Value === false) { - return $profile['Associations'][0]['Name']; - } - - return '-'; - - case 1: //Integer - case 2: //Float - for ($i = count($profile['Associations']) - 1; $i >= 0; $i--) { - if ($Value >= $profile['Associations'][$i]['Value']) { - return $profile['Prefix'] . sprintf($profile['Associations'][$i]['Name'], $Value) . $profile['Suffix']; - } - } - return '-'; - - case 3: //String - for ($i = count($profile['Associations']) - 1; $i >= 0; $i--) { - if ($Value == $profile['Associations'][$i]['Value']) { - return $profile['Prefix'] . sprintf($profile['Associations'][$i]['Name'], $Value) . $profile['Suffix']; - } - } - return '-'; - - } - } - } -} - -function HasAction(int $VariableID) -{ - $v = IPS\VariableManager::getVariable($VariableID); - if ($v['VariableCustomAction'] > 0) { - $actionID = $v['VariableCustomAction']; - } else { - $actionID = $v['VariableAction']; - } - return $actionID >= 10000; -} - -function RequestAction(int $VariableID, $Value) -{ - $v = IPS\VariableManager::getVariable($VariableID); - if ($v['VariableCustomAction'] > 0) { - $actionID = $v['VariableCustomAction']; - } else { - $actionID = $v['VariableAction']; - } - if (IPS_InstanceExists($actionID)) { - $o = IPS\ObjectManager::getObject($VariableID); - $interface = IPS\InstanceManager::getInstanceInterface($actionID); - $interface->RequestAction($o['ObjectIdent'], $Value); - } elseif (IPS_ScriptExists($actionID)) { - $result = IPS_RunScriptWaitEx($actionID, [ - 'VARIABLE' => $VariableID, - 'VALUE' => $Value, - 'SENDER' => 'Action' - ]); - if (strlen($result) > 0) { - echo $result; - } - } else { - throw new Exception('Action is invalid'); - } -} - -/* Object Manager */ -function IPS_SetParent(int $ID, int $ParentID) -{ - IPS\ObjectManager::setParent($ID, $ParentID); -} - -function IPS_SetIdent(int $ID, string $Ident) -{ - IPS\ObjectManager::setIdent($ID, $Ident); -} - -function IPS_SetName(int $ID, string $Name) -{ - IPS\ObjectManager::setName($ID, $Name); -} - -function IPS_SetInfo(int $ID, string $Info) -{ - IPS\ObjectManager::setInfo($ID, $Info); -} - -function IPS_SetIcon(int $ID, string $Icon) -{ - IPS\ObjectManager::setIcon($ID, $Icon); -} - -function IPS_SetPosition(int $ID, int $Position) -{ - IPS\ObjectManager::setPosition($ID, $Position); -} - -function IPS_SetHidden(int $ID, bool $Hidden) -{ - IPS\ObjectManager::setHidden($ID, $Hidden); -} - -function IPS_SetDisabled(int $ID, bool $Disabled) -{ - IPS\ObjectManager::setDisabled($ID, $Disabled); -} - -function IPS_ObjectExists(int $ID) -{ - return IPS\ObjectManager::objectExists($ID); -} - -function IPS_GetObject(int $ID) -{ - return IPS\ObjectManager::getObject($ID); -} - -function IPS_GetObjectList() -{ - return IPS\ObjectManager::getObjectList(); -} - -function IPS_GetObjectIDByName(string $Name, int $ParentID) -{ - return IPS\ObjectManager::getObjectIDByName($Name, $ParentID); -} - -function IPS_GetObjectIDByIdent(string $Ident, int $ParentID) -{ - return IPS\ObjectManager::getObjectIDByIdent($Ident, $ParentID); -} - -function IPS_HasChildren(int $ID) -{ - return IPS\ObjectManager::hasChildren($ID); -} - -function IPS_IsChild(int $ID, int $ParentID, bool $Recursive) -{ - return IPS\ObjectManager::isChild($ID, $ParentID, $Recursive); -} - -function IPS_GetChildrenIDs(int $ID) -{ - return IPS\ObjectManager::getChildrenIDs($ID); -} - -function IPS_GetName(int $ID) -{ - return IPS\ObjectManager::getName($ID); -} - -function IPS_GetParent(int $ID) -{ - return IPS\ObjectManager::getParent($ID); -} - -function IPS_GetLocation(int $ID) -{ - return IPS\ObjectManager::getLocation($ID); -} - -/* Category Manager */ -function IPS_CreateCategory() -{ - $id = IPS\ObjectManager::registerObject(0 /* Category */); - IPS\CategoryManager::createCategory($id); - - return $id; -} - -function IPS_DeleteCategory(int $CategoryID) -{ - IPS\CategoryManager::deleteCategory($CategoryID); - IPS\ObjectManager::unregisterObject($CategoryID); -} - -function IPS_CategoryExists(int $CategoryID) -{ - return IPS\CategoryManager::categoryExists($CategoryID); -} - -function IPS_GetCategory(int $CategoryID) -{ - return IPS\CategoryManager::getCategory($CategoryID); -} - -function IPS_GetCategoryList() -{ - return IPS\CategoryManager::getCategoryList(); -} - -function IPS_GetCategoryIDByName(string $Name, int $ParentID) -{ - return IPS\ObjectManager::getObjectIDByNameEx($Name, $ParentID, 0 /* Category */); -} - -/* Instance Manager */ -function IPS_CreateInstance(string $ModuleID) -{ - $module = IPS\ModuleLoader::getModule($ModuleID); - $id = IPS\ObjectManager::registerObject(1 /* Instance */); - IPS\InstanceManager::createInstance($id, $module); - - return $id; -} - -function IPS_DeleteInstance(int $InstanceID) -{ - IPS\InstanceManager::deleteInstance($InstanceID); - IPS\ObjectManager::unregisterObject($InstanceID); -} - -function IPS_InstanceExists(int $InstanceID) -{ - return IPS\InstanceManager::instanceExists($InstanceID); -} - -function IPS_GetInstance(int $InstanceID) -{ - return IPS\InstanceManager::getInstance($InstanceID); -} - -function IPS_GetInstanceList() -{ - return IPS\InstanceManager::getInstanceList(); -} - -function IPS_GetInstanceIDByName(string $Name, int $ParentID) -{ - return IPS\ObjectManager::getObjectIDByNameEx($Name, $ParentID, 1 /* Instance */); -} - -function IPS_GetInstanceListByModuleType(int $ModuleType) -{ - return IPS\InstanceManager::getInstanceListByModuleType($ModuleType); -} - -function IPS_GetInstanceListByModuleID(string $ModuleID) -{ - return IPS\InstanceManager::getInstanceListByModuleID($ModuleID); -} - -function IPS_GetReferenceList(int $InstanceID) -{ - return IPS\InstanceManager::getReferenceList($InstanceID); -} - -/* Instance Manager - Configuration */ -function IPS_HasChanges(int $InstanceID) -{ - return IPS\InstanceManager::getInstanceInterface($InstanceID)->HasChanges(); -} - -function IPS_ResetChanges(int $InstanceID) -{ - IPS\InstanceManager::getInstanceInterface($InstanceID)->ResetChanges(); -} - -function IPS_ApplyChanges(int $InstanceID) -{ - IPS\InstanceManager::getInstanceInterface($InstanceID)->ApplyChanges(); -} - -function IPS_GetProperty(int $InstanceID, string $Name) -{ - return IPS\InstanceManager::getInstanceInterface($InstanceID)->GetProperty($Name); -} - -function IPS_GetConfiguration(int $InstanceID) -{ - return IPS\InstanceManager::getInstanceInterface($InstanceID)->GetConfiguration(); -} - -function IPS_GetConfigurationForParent(int $InstanceID) -{ - return IPS\InstanceManager::getInstanceInterface($InstanceID)->GetConfigurationForParent(); -} - -function IPS_GetConfigurationForm(int $InstanceID) -{ - return IPS\InstanceManager::getInstanceInterface($InstanceID)->GetConfigurationForm(); -} - -function IPS_SetProperty(int $InstanceID, string $Name, $Value) -{ - IPS\InstanceManager::getInstanceInterface($InstanceID)->SetProperty($Name, $Value); -} - -function IPS_SetConfiguration(int $InstanceID, string $Configuration) -{ - IPS\InstanceManager::getInstanceInterface($InstanceID)->SetConfiguration($Configuration); -} - -/* Instance Manager - Connections */ -function IPS_ConnectInstance(int $InstanceID, int $ParentID) -{ - IPS\InstanceManager::connectInstance($InstanceID, $ParentID); -} - -function IPS_DisconnectInstance(int $InstanceID) -{ - IPS\InstanceManager::disconnectInstance($InstanceID); -} - -/* Instance Manager - Searching */ -function IPS_StartSearch(int $InstanceID) -{ - throw new Exception('Not implemented'); -} - -function IPS_StopSearch(int $InstanceID) -{ - throw new Exception('Not implemented'); -} - -function IPS_SupportsSearching(int $InstanceID) -{ - throw new Exception('Not implemented'); -} - -function IPS_IsSearching(int $InstanceID) -{ - throw new Exception('Not implemented'); -} - -/* Instance Manager - Debugging */ -function IPS_DisableDebug(int $ID) -{ - IPS\DebugServer::disableDebug($ID); -} - -function IPS_EnableDebug(int $ID, int $Duration) -{ - IPS\DebugServer::enableDebug($ID, $Duration); -} - -function IPS_SendDebug(int $SenderID, string $Message, string $Data, int $Format) -{ - IPS\DebugServer::sendDebug($SenderID, $Message, $Data, $Format); -} - -/* Instance Manager - Actions */ -function IPS_RequestAction(int $InstanceID, string $VariableIdent, $Value) -{ - throw new Exception('Not implemented'); -} - -/* Variable Manager */ -function IPS_CreateVariable(int $VariableType) -{ - $id = IPS\ObjectManager::registerObject(2 /* Variable */); - IPS\VariableManager::createVariable($id, $VariableType); - - return $id; -} - -function IPS_DeleteVariable(int $VariableID) -{ - IPS\VariableManager::deleteVariable($VariableID); - IPS\ObjectManager::unregisterObject($VariableID); -} - -function IPS_VariableExists(int $VariableID) -{ - return IPS\VariableManager::variableExists($VariableID); -} - -function IPS_GetVariable(int $VariableID) -{ - return IPS\VariableManager::getVariable($VariableID); -} - -function IPS_GetVariableEventList(int $VariableID) -{ - return []; //FIXME -} - -function IPS_GetVariableIDByName(string $Name, int $ParentID) -{ - return IPS\ObjectManager::getObjectIDByNameEx($Name, $ParentID, 2 /* Variable */); -} - -function IPS_GetVariableList() -{ - return IPS\VariableManager::getVariableList(); -} - -function IPS_SetVariableCustomAction(int $VariableID, int $ScriptID) -{ - IPS\VariableManager::setVariableCustomAction($VariableID, $ScriptID); -} - -function IPS_SetVariableCustomProfile(int $VariableID, string $ProfileName) -{ - IPS\VariableManager::setVariableCustomProfile($VariableID, $ProfileName); -} - -/* Script Manager */ -function IPS_CreateScript(int $ScriptType) -{ - $id = IPS\ObjectManager::registerObject(3 /* Script */); - IPS\ScriptManager::createScript($id, $ScriptType); - - return $id; -} - -function IPS_DeleteScript(int $ScriptID, bool $DeleteFile) -{ - IPS\ScriptManager::deleteScript($ScriptID, $DeleteFile); - IPS\ObjectManager::unregisterObject($ScriptID); -} - -function IPS_ScriptExists(int $ScriptID) -{ - return IPS\ScriptManager::scriptExists($ScriptID); -} - -function IPS_SetScriptContent(int $ScriptID, string $Content) -{ - IPS\ScriptManager::setScriptContent($ScriptID, $Content); -} - -function IPS_SetScriptFile(int $ScriptID, string $FilePath) -{ - IPS\ScriptManager::setScriptFile($ScriptID, $FilePath); -} - -function IPS_GetScript(int $ScriptID) -{ - return IPS\ScriptManager::getScript($ScriptID); -} - -function IPS_GetScriptContent(int $ScriptID) -{ - return IPS\ScriptManager::getScriptContent($ScriptID); -} - -function IPS_GetScriptEventList(int $ScriptID) -{ - throw new Exception('Not implemented'); -} - -function IPS_GetScriptFile(int $ScriptID) -{ - IPS\ScriptManager::getScriptFile($ScriptID); -} - -function IPS_GetScriptIDByFile(string $FilePath) -{ - throw new Exception('Not implemented'); -} - -function IPS_GetScriptIDByName(string $Name, int $ParentID) -{ - return IPS\ObjectManager::getObjectIDByNameEx($Name, $ParentID, 3 /* Script */); -} - -function IPS_GetScriptList() -{ - return IPS\ScriptManager::getScriptList(); -} - -/* Event Manager */ -function IPS_CreateEvent(int $EventType) -{ - return 0; -} - -function IPS_DeleteEvent(int $EventID) -{ - return true; -} - -function IPS_EventExists(int $EventID) -{ - return true; -} - -function IPS_GetEvent(int $EventID) -{ - return []; -} - -function IPS_GetEventIDByName(string $Name, int $ParentID) -{ - return 0; -} - -function IPS_GetEventList() -{ - return []; -} - -function IPS_GetEventListByType(int $EventType) -{ - return []; -} - -function IPS_SetEventActive(int $EventID, bool $Active) -{ - return true; -} - -function IPS_SetEventCyclic(int $EventID, int $DateType, int $DateValue, int $DateDay, int $DateDayValue, int $TimeType, int $TimeValue) -{ - return true; -} - -function IPS_SetEventCyclicDateFrom(int $EventID, int $Day, int $Month, int $Year) -{ - return true; -} - -function IPS_SetEventCyclicDateTo(int $EventID, int $Day, int $Month, int $Year) -{ - return true; -} - -function IPS_SetEventCyclicTimeFrom(int $EventID, int $Hour, int $Minute, int $Second) -{ - return true; -} - -function IPS_SetEventCyclicTimeTo(int $EventID, int $Hour, int $Minute, int $Second) -{ - return true; -} - -function IPS_SetEventLimit(int $EventID, int $Count) -{ - return true; -} - -function IPS_SetEventScheduleAction(int $EventID, int $ActionID, string $Name, int $Color, string $ScriptText) -{ - return true; -} - -function IPS_SetEventScheduleGroup(int $EventID, int $GroupID, int $Days) -{ - return true; -} - -function IPS_SetEventScheduleGroupPoint(int $EventID, int $GroupID, int $PointID, int $StartHour, int $StartMinute, int $StartSecond, int $ActionID) -{ - return true; -} - -function IPS_SetEventScript(int $EventID, string $EventScript) -{ - return true; -} - -function IPS_SetEventTrigger(int $EventID, int $TriggerType, int $TriggerVariableID) -{ - return true; -} - -function IPS_SetEventTriggerSubsequentExecution(int $EventID, bool $AllowSubsequentExecutions) -{ - return true; -} - -function IPS_SetEventTriggerValue(int $EventID, $TriggerValue) -{ - return true; -} - -function IPS_IsConditionPassing(string $Conditions) -{ - return true; -} - -function IPS_GetScriptTimer(int $ScriptID) -{ - return 0; -} - -function IPS_SetScriptTimer(int $ScriptID, int $Interval) -{ - return true; -} - -/* Media Manager */ -function IPS_CreateMedia(int $MediaType) -{ - $id = IPS\ObjectManager::registerObject(5 /* Media */); - IPS\MediaManager::createMedia($id, $MediaType); - return $id; -} - -function IPS_DeleteMedia(int $MediaID, bool $DeleteFile) -{ - IPS\MediaManager::deleteMedia($MediaID, $DeleteFile); - IPS\ObjectManager::unregisterObject($MediaID); -} - -function IPS_MediaExists(int $MediaID) -{ - return IPS\MediaManager::mediaExists($MediaID); -} - -function IPS_GetMedia(int $MediaID) -{ - return []; -} - -function IPS_GetMediaContent(int $MediaID) -{ - return ''; -} - -function IPS_GetMediaIDByFile(string $FilePath) -{ - return 0; -} - -function IPS_GetMediaIDByName(string $Name, int $ParentID) -{ - return 0; -} - -function IPS_GetMediaList() -{ - return []; -} - -function IPS_GetMediaListByType(int $MediaType) -{ - return []; -} - -function IPS_SetMediaCached(int $MediaID, bool $Cached) -{ - return true; -} - -function IPS_SetMediaContent(int $MediaID, string $Content) -{ - return true; -} - -function IPS_SetMediaFile(int $MediaID, string $FilePath, bool $FileMustExists) -{ - return true; -} - -function IPS_SendMediaEvent(int $MediaID) -{ - return true; -} - -/* Link Manager */ -function IPS_CreateLink() -{ - $id = IPS\ObjectManager::registerObject(6 /* Link */); - IPS\LinkManager::createLink($id); - return $id; -} - -function IPS_DeleteLink(int $LinkID) -{ - IPS\LinkManager::deleteLink($LinkID); - IPS\ObjectManager::unregisterObject($LinkID); -} - -function IPS_LinkExists(int $LinkID) -{ - return IPS\LinkManager::linkExists($LinkID); -} - -function IPS_GetLink(int $LinkID) -{ - return IPS\LinkManager::getLink($LinkID); -} - -function IPS_GetLinkIDByName(string $Name, int $ParentID) -{ - return IPS\LinkManager::getLinkIdByName($Name, $ParentID); -} - -function IPS_GetLinkList() -{ - return IPS\LinkManager::getLinkList(); -} - -function IPS_SetLinkTargetID(int $LinkID, int $ChildID) -{ - IPS\LinkManager::setLinkTargetID($LinkID, $ChildID); -} - -/* Profile Manager */ -function IPS_CreateVariableProfile(string $ProfileName, int $ProfileType) -{ - IPS\ProfileManager::createVariableProfile($ProfileName, $ProfileType); -} - -function IPS_DeleteVariableProfile(string $ProfileName) -{ - IPS\ProfileManager::deleteVariableProfile($ProfileName); -} - -function IPS_VariableProfileExists(string $ProfileName) -{ - return IPS\ProfileManager::variableProfileExists($ProfileName); -} - -function IPS_GetVariableProfile(string $ProfileName) -{ - return IPS\ProfileManager::getVariableProfile($ProfileName); -} - -function IPS_GetVariableProfileList() -{ - return IPS\ProfileManager::getVariableProfileList(); -} - -function IPS_GetVariableProfileListByType(int $ProfileType) -{ - return IPS\ProfileManager::getVariableProfileListByType($ProfileType); -} - -function IPS_SetVariableProfileAssociation(string $ProfileName, $AssociationValue, string $AssociationName, string $AssociationIcon, int $AssociationColor) -{ - IPS\ProfileManager::setVariableProfileAssociation($ProfileName, $AssociationValue, $AssociationName, $AssociationIcon, $AssociationColor); -} - -function IPS_SetVariableProfileDigits(string $ProfileName, int $Digits) -{ - IPS\ProfileManager::setVariableProfileDigits($ProfileName, $Digits); -} - -function IPS_SetVariableProfileIcon(string $ProfileName, string $Icon) -{ - IPS\ProfileManager::setVariableProfileIcon($ProfileName, $Icon); -} - -function IPS_SetVariableProfileText(string $ProfileName, string $Prefix, string $Suffix) -{ - IPS\ProfileManager::setVariableProfileText($ProfileName, $Prefix, $Suffix); -} - -function IPS_SetVariableProfileValues(string $ProfileName, float $MinValue, float $MaxValue, float $StepSize) -{ - IPS\ProfileManager::setVariableProfileValues($ProfileName, $MinValue, $MaxValue, $StepSize); -} - -/* Kernel */ -function IPS_GetKernelDir() -{ - return sys_get_temp_dir(); -} - -function IPS_GetKernelDirEx() -{ - return sys_get_temp_dir(); -} - -function IPS_GetKernelRunlevel() -{ - return 10103 /* KR_READY */; -} - -function IPS_GetKernelStartTime() -{ - return time(); -} - -function IPS_GetKernelPlatform() -{ - return 'Stubs'; -} - -function IPS_GetKernelVersion() -{ - return '5.2'; -} - -function IPS_GetKernelRevision() -{ - return 'e4b85ff1670f4c936db014d8b6540b2a38776e50'; -} - -function IPS_GetKernelDate() -{ - return 1566980315; -} - -function IPS_GetLogDir() -{ - return sys_get_temp_dir() . '/logs'; -} - -function IPS_LogMessage(string $Sender, string $Message) -{ - return true; -} - -/* License Pool */ -function IPS_GetLicensee() -{ - return 'max@mustermann.de'; -} - -function IPS_GetLimitDemo() -{ - return 0; -} - -function IPS_GetLimitServer() -{ - return ''; -} - -function IPS_GetLimitVariables() -{ - return 0; -} - -function IPS_GetLimitWebFront() -{ - return 0; -} - -function IPS_GetDemoExpiration() -{ - return 0; -} - -function IPS_GetLiveConsoleCRC() -{ - throw new Exception('Not implemented'); -} - -function IPS_GetLiveConsoleFile() -{ - throw new Exception('Not implemented'); -} - -function IPS_GetLiveDashboardCRC() -{ - throw new Exception('Not implemented'); -} - -function IPS_GetLiveDashboardFile() -{ - throw new Exception('Not implemented'); -} - -function IPS_GetLiveUpdateVersion() -{ - throw new Exception('Not implemented'); -} - -function IPS_SetLicense(string $Licensee, string $LicenseContent) -{ - throw new Exception('Not implemented'); -} - -/* Script Engine */ -function IPS_RunScript(int $ScriptID) -{ - IPS\ScriptEngine::runScript($ScriptID); - return true; -} - -function IPS_RunScriptEx(int $ScriptID, array $Parameters) -{ - IPS\ScriptEngine::runScriptEx($ScriptID, $Parameters); - return true; -} - -function IPS_RunScriptWait(int $ScriptID) -{ - return IPS\ScriptEngine::runScriptWait($ScriptID); -} - -function IPS_RunScriptWaitEx(int $ScriptID, array $Parameters) -{ - return IPS\ScriptEngine::runScriptWaitEx($ScriptID, $Parameters); -} - -function IPS_RunScriptText(string $ScriptText) -{ - IPS\ScriptEngine::runScriptText($ScriptText); - return true; -} - -function IPS_RunScriptTextEx(string $ScriptText, array $Parameters) -{ - IPS\ScriptEngine::runScriptTextEx($ScriptText, $Parameters); - return true; -} - -function IPS_RunScriptTextWait(string $ScriptText) -{ - return IPS\ScriptEngine::IPS_RunScriptTextWait($ScriptText); -} - -function IPS_RunScriptTextWaitEx(string $ScriptText, array $Parameters) -{ - return IPS\ScriptEngine::runScriptTextWaitEx($ScriptText, $Parameters); -} - -function IPS_SemaphoreEnter(string $Name, int $Milliseconds) -{ - return IPS\ScriptEngine::semaphoreEnter($Name, $Milliseconds); -} - -function IPS_SemaphoreLeave(string $Name) -{ - return IPS\ScriptEngine::semaphoreLeave($Name); -} - -function IPS_ScriptThreadExists(int $ThreadID) -{ - return IPS\ScriptEngine::scriptThreadExists($ThreadID); -} - -function IPS_GetScriptThread(int $ThreadID) -{ - return IPS\ScriptEngine::getScriptThread($ThreadID); -} - -function IPS_GetScriptThreadList() -{ - return IPS\ScriptEngine::getScriptThreadList(); -} - -// This function is only usable via JSON-RPC and is only "implemented" in Gluegen but not in the script engine -function IPS_GetScriptThreads(array $Parameter) -{ - throw new Exception('Not implemented'); -} - -/* Data Server */ -function IPS_FunctionExists(string $FunctionName) -{ - return IPS\DataServer::functionExists($FunctionName); -} - -function IPS_GetFunction(string $FunctionName) -{ - return IPS\DataServer::getFunction($FunctionName); -} - -function IPS_GetFunctionList(int $InstanceID) -{ - return IPS\DataServer::getFunctionList($InstanceID); -} - -function IPS_GetFunctionListByModuleID(string $ModuleID) -{ - return IPS\DataServer::getFunctionListByModuleID($ModuleID); -} - -function IPS_GetFunctions(array $Parameter) -{ - return IPS\DataServer::getFunctions($Parameter); -} - -function IPS_GetFunctionsMap(array $Parameter) -{ - return IPS\DataServer::getFunctionsMap($Parameter); -} - -/* Timer Pool */ -function IPS_TimerExists(int $TimerID) -{ - throw new Exception('Not implemented'); -} - -function IPS_GetTimer(int $TimerID) -{ - throw new Exception('Not implemented'); -} - -function IPS_GetTimerList() -{ - throw new Exception('Not implemented'); -} - -function IPS_GetTimers(array $Parameter) -{ - throw new Exception('Not implemented'); -} - -/* Module Loader */ -function IPS_LibraryExists(string $LibraryID) -{ - return IPS\ModuleLoader::libraryExists($LibraryID); -} - -function IPS_GetLibrary(string $LibraryID) -{ - return IPS\ModuleLoader::getLibrary($LibraryID); -} - -function IPS_GetLibraryList() -{ - return IPS\ModuleLoader::getLibraryList(); -} - -function IPS_GetLibraryModules(string $LibraryID) -{ - return IPS\ModuleLoader::getLibraryModules($LibraryID); -} - -function IPS_ModuleExists(string $ModuleID) -{ - return IPS\ModuleLoader::moduleExists($ModuleID); -} - -function IPS_GetModule(string $ModuleID) -{ - return IPS\ModuleLoader::getModule($ModuleID); -} - -function IPS_GetModuleList() -{ - return IPS\ModuleLoader::getModuleList(); -} - -function IPS_GetModuleListByType(int $ModuleType) -{ - return IPS\ModuleLoader::getModuleListByType($ModuleType); -} - -function IPS_IsModuleCompatible(string $ModuleID, string $ParentModuleID) -{ - throw new Exception('Not implemented'); -} - -function IPS_GetCompatibleModules(string $ModuleID) -{ - throw new Exception('Not implemented'); -} - -function IPS_IsInstanceCompatible(int $InstanceID, int $ParentInstanceID) -{ - throw new Exception('Not implemented'); -} - -function IPS_GetCompatibleInstances(int $InstanceID) -{ - throw new Exception('Not implemented'); -} - -/* Module Loader - Helper */ -function IPS_GetModules(array $Parameter) -{ - if (count($Parameter) == 0) { - $Parameter = IPS_GetModuleList(); - } - $result = []; - foreach ($Parameter as $ModuleID) { - $result[] = IPS_GetModule($ModuleID); - } - return $result; -} - -function IPS_GetLibraries(array $Parameter) -{ - if (count($Parameter) == 0) { - $Parameter = IPS_GetLibraryList(); - } - $result = []; - foreach ($Parameter as $LibraryID) { - $result[] = IPS_GetLibrary($LibraryID); - } - return $result; -} - -/* ActionPool */ -function IPS_GetActions() -{ - return IPS\ActionPool::getActions(); -} - -function IPS_GetActionsByEnvironment(int $TargetID, string $Environment, bool $IncludeDefault) -{ - return IPS\ActionPool::getActionsByEnvironment($TargetID, $Environment, $IncludeDefault); -} - -function IPS_GetActionForm(string $ActionID, array $Parameters) -{ - return IPS\ActionPool::getActionForm($ActionID, $Parameters); -} - -function IPS_GetActionReadableCode(string $ActionID, array $Parameters) -{ - return IPS\ActionPool::getActionReadableCode($ActionID, $Parameters); -} - -function IPS_RunAction(string $ActionID, array $Parameters) -{ - IPS\ActionPool::runAction($ActionID, $Parameters); - return true; -} - -function IPS_RunActionWait(string $ActionID, array $Parameters) -{ - return IPS\ActionPool::runActionWait($ActionID, $Parameters); -} - -function IPS_UpdateFormField(string $Name, string $Parameter, $Value, string $SessionID) -{ - return IPS\ActionPool::updateFormField($Name, $Parameter, $Value, $SessionID); -} - -/* Settings */ -function IPS_GetOption(string $Option) -{ - throw new Exception('Not implemented'); -} - -function IPS_GetSecurityMode() -{ - throw new Exception('Not implemented'); -} - -function IPS_GetSnapshot() -{ - throw new Exception('Not implemented'); -} - -function IPS_GetSnapshotChanges(int $LastTimestamp) -{ - throw new Exception('Not implemented'); -} - -function IPS_SetOption(string $Option, int $Value) -{ - throw new Exception('Not implemented'); -} - -function IPS_SetSecurity(int $Mode, string $Password) -{ - throw new Exception('Not implemented'); -} - -/* Additional */ -function IPS_Execute(string $Filename, string $Parameter, bool $ShowWindow, bool $WaitResult) -{ - throw new Exception('Not implemented'); -} - -function IPS_ExecuteEx(string $Filename, string $Parameter, bool $ShowWindow, bool $WaitResult, int $SessionID) -{ - throw new Exception('Not implemented'); -} - -function IPS_Sleep(int $Milliseconds) -{ - usleep($Milliseconds * 1000); -} - -/* System Information */ -function Sys_GetBattery() -{ - return [ - 'OnBattery' => false, - 'IsCharging' => false, - 'BatteryLevel' => -1, - 'BatteryRemainingTime' => -1, - 'BatteryMaxTime' => -1 - ]; -} - -function Sys_GetCPUInfo() -{ - return [ - 'CPU_0' => 3, - 'CPU_AVG' => 3 - ]; -} - -function Sys_GetHardDiskInfo() -{ - return [ - 0 => [ - 'LETTER' => 'c:\\', - 'LABEL' => '', - 'TOTAL' => 53684989952, - 'FREE' => 23275171840 - ], - 'NUMDRIVES' => 1 - ]; -} - -function Sys_GetMemoryInfo() -{ - return [ - 'TOTALPHYSICAL' => 1072467968, - 'AVAILPHYSICAL' => 526647296, - 'TOTALPAGEFILE' => 2420019200, - 'AVAILPAGEFILE' => 1386422272, - 'TOTALVIRTUAL' => 2147352576, - 'AVAILVIRTUAL' => 1906978816 - ]; -} - -function Sys_GetNetworkInfo() -{ - return [ - 0 => [ - 'InterfaceIndex' => 10, - 'IP' => '192.168.1.2', - 'MAC' => '00:A0:03:AD:14:BD', - 'Description' => 'Siemens I BT USB Remote NDIS Network Device', - 'Speed' => 9728000, - 'InTotal' => 40236, - 'OutTotal' => 247248 - ], - 1 => [ - 'InterfaceIndex' => 13, - 'IP' => '172.12.1.200', - 'MAC' => '00:A0:03:AD:14:BD', - 'Description' => 'Qualcomm Atheros AR8151 PCI-E Gigabit Ethernet Controller (NDIS 6.30)', - 'Speed' => 1000000000, - 'InTotal' => 169987950, - 'OutTotal' => 86029648 - ] - ]; -} - -function Sys_GetProcessInfo() -{ - return [ - 'IPS_HANDLECOUNT' => 635, - 'IPS_NUMTHREADS' => 53, - 'IPS_VIRTUALSIZE' => 240373760, - 'IPS_WORKINGSETSIZE' => 32706560, - 'IPS_PAGEFILE' => 52719616, - 'PROCESSCOUNT' => 53 - ]; -} - -function Sys_GetSpooler() -{ - return []; -} - -function Sys_GetURLContent(string $URL) -{ - return ''; -} - -function Sys_GetURLContentEx(string $URL, array $Parameter) -{ - return ''; -} - -function Sys_Ping(string $Host, int $Timeout) -{ - return true; -} - diff --git a/tests/stubs/IOStubs/ClientSocket/module.json b/tests/stubs/IOStubs/ClientSocket/module.json deleted file mode 100644 index eaa5eb2..0000000 --- a/tests/stubs/IOStubs/ClientSocket/module.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "id": "{3CFF0FD9-E306-41DB-9B5A-9D06D38576C3}", - "name": "ClientSocket", - "type": 1, - "vendor": "Symcon GmbH", - "aliases": [ - "Client Socket" - ], - "url": "https://www.symcon.de/service/dokumentation/modulreferenz/io/clientsocket/", - "parentRequirements": [], - "childRequirements": [ - "{018EF6B5-AB94-40C6-AA53-46943E824ACF}" - ], - "implemented": [ - "{79827379-F36E-4ADA-8A95-5F8D1DC92FA9}" - ], - "prefix": "CSCK" -} \ No newline at end of file diff --git a/tests/stubs/IOStubs/ClientSocket/module.php b/tests/stubs/IOStubs/ClientSocket/module.php deleted file mode 100644 index 7dd05fe..0000000 --- a/tests/stubs/IOStubs/ClientSocket/module.php +++ /dev/null @@ -1,8 +0,0 @@ -RegisterPropertyString('MulticastIP', ''); - $this->RegisterPropertyBoolean('EnableBroadcast', false); - $this->RegisterPropertyBoolean('EnableReuseAddress', false); - $this->RegisterPropertyBoolean('EnableLoopback', false); - } -} diff --git a/tests/stubs/IOStubs/SSEClient/module.json b/tests/stubs/IOStubs/SSEClient/module.json deleted file mode 100644 index 3983e36..0000000 --- a/tests/stubs/IOStubs/SSEClient/module.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "id": "{2FADB4B7-FDAB-3C64-3E2C-068A4809849A}", - "name": "SSE Client", - "type": 1, - "vendor": "Symcon GmbH", - "aliases": [ - "SSE Client", - "Server-Sent Events Client" - ], - "url": "https://www.symcon.de/service/dokumentation/modulreferenz/io/serversenteventclient/", - "parentRequirements": [], - "childRequirements": [ - "{018EF6B5-AB94-40C6-AA53-46943E824ACF}" - ], - "implemented": [ - "{79827379-F36E-4ADA-8A95-5F8D1DC92FA9}" - ], - "prefix": "SSE" -} \ No newline at end of file diff --git a/tests/stubs/IOStubs/SSEClient/module.php b/tests/stubs/IOStubs/SSEClient/module.php deleted file mode 100644 index ca25946..0000000 --- a/tests/stubs/IOStubs/SSEClient/module.php +++ /dev/null @@ -1,8 +0,0 @@ -RegisterPropertyString('Port', ''); - $this->RegisterPropertyString('BaudRate', '9600'); - $this->RegisterPropertyString('DataBits', '8'); - $this->RegisterPropertyString('StopBits', '1'); - $this->RegisterPropertyString('Parity', 'None'); - } -} diff --git a/tests/stubs/IOStubs/ServerSocket/module.json b/tests/stubs/IOStubs/ServerSocket/module.json deleted file mode 100644 index f3d12fc..0000000 --- a/tests/stubs/IOStubs/ServerSocket/module.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "id": "{8062CF2B-600E-41D6-AD4B-1BA66C32D6ED}", - "name": "ServerSocket", - "type": 1, - "vendor": "Symcon GmbH", - "aliases": [ - "Server Socket" - ], - "url": "https://www.symcon.de/service/dokumentation/modulreferenz/io/serversocket/", - "parentRequirements": [], - "childRequirements": [ - "{7A1272A4-CBDB-46EF-BFC6-DCF4A53D2FC7}", - "{018EF6B5-AB94-40C6-AA53-46943E824ACF}" - ], - "implemented": [ - "{C8792760-65CF-4C53-B5C7-A30FCC84FEFE}", - "{79827379-F36E-4ADA-8A95-5F8D1DC92FA9}" - ], - "prefix": "SSCK" -} \ No newline at end of file diff --git a/tests/stubs/IOStubs/ServerSocket/module.php b/tests/stubs/IOStubs/ServerSocket/module.php deleted file mode 100644 index 0e374a7..0000000 --- a/tests/stubs/IOStubs/ServerSocket/module.php +++ /dev/null @@ -1,96 +0,0 @@ -packetQueue[] = [ - 'Type' => isset($data['Type']) ? $data['Type'] : 0 /* Data */, - 'Buffer' => utf8_decode($data['Buffer']), - 'ClientIP' => $data['ClientIP'], - 'ClientPort' => $data['ClientPort'] - ]; - return; - } - - parent::ForwardData($JSONString); - } - - public function HasPacket() - { - return count($this->packetQueue) > 0; - } - - public function PeekPacket() - { - if (!$this->HasPacket()) { - throw new Exception('There is not data available'); - } - - return $this->packetQueue[0]; - } - - public function PopPacket() - { - $result = $this->PeekPacket(); - array_shift($this->packetQueue); - - return $result; - } - - public function PushConnect(string $ClientIP, int $ClientPort) - { - $this->SendDataToChildren(json_encode([ - 'DataID' => '{7A1272A4-CBDB-46EF-BFC6-DCF4A53D2FC7}', - 'Type' => 1 /* Connect */, - 'Buffer' => '', - 'ClientIP' => $ClientIP, - 'ClientPort' => $ClientPort - ])); - } - - public function PushDisconnect(string $ClientIP, int $ClientPort) - { - $this->SendDataToChildren(json_encode([ - 'DataID' => '{7A1272A4-CBDB-46EF-BFC6-DCF4A53D2FC7}', - 'Type' => 2 /* Disconnect */, - 'Buffer' => '', - 'ClientIP' => $ClientIP, - 'ClientPort' => $ClientPort - ])); - } - - public function PushPacket(string $Text, string $ClientIP, int $ClientPort) - { - $this->SendDataToChildren(json_encode([ - 'DataID' => '{7A1272A4-CBDB-46EF-BFC6-DCF4A53D2FC7}', - 'Type' => 0 /* Data */, - 'Buffer' => utf8_encode($Text), - 'ClientIP' => $ClientIP, - 'ClientPort' => $ClientPort - ])); - } -} - -class ServerSocket extends ServerSocketBase -{ - public function Create() - { - parent::Create(); - - $this->RegisterPropertyString('Port', ''); - $this->RegisterPropertyInteger('Limit', 0); - } -} diff --git a/tests/stubs/IOStubs/UDPSocket/module.json b/tests/stubs/IOStubs/UDPSocket/module.json deleted file mode 100644 index e6a6b12..0000000 --- a/tests/stubs/IOStubs/UDPSocket/module.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "id": "{82347F20-F541-41E1-AC5B-A636FD3AE2D8}", - "name": "UDPSocket", - "type": 1, - "vendor": "Symcon GmbH", - "aliases": [ - "UDP Socket" - ], - "url": "https://www.symcon.de/service/dokumentation/modulreferenz/io/udpsocket/", - "parentRequirements": [], - "childRequirements": [ - "{7A1272A4-CBDB-46EF-BFC6-DCF4A53D2FC7}", - "{018EF6B5-AB94-40C6-AA53-46943E824ACF}" - ], - "implemented": [ - "{C8792760-65CF-4C53-B5C7-A30FCC84FEFE}", - "{79827379-F36E-4ADA-8A95-5F8D1DC92FA9}" - ], - "prefix": "USCK" -} \ No newline at end of file diff --git a/tests/stubs/IOStubs/UDPSocket/module.php b/tests/stubs/IOStubs/UDPSocket/module.php deleted file mode 100644 index b163863..0000000 --- a/tests/stubs/IOStubs/UDPSocket/module.php +++ /dev/null @@ -1,19 +0,0 @@ -RegisterPropertyString('Host', ''); - $this->RegisterPropertyInteger('Port', 0); - $this->RegisterPropertyString('BindIP', ''); - $this->RegisterPropertyInteger('BindPort', 0); - $this->RegisterPropertyBoolean('EnableBroadcast', false); - $this->RegisterPropertyBoolean('EnableReuseAddress', false); - } -} diff --git a/tests/stubs/IOStubs/VirtualIO/module.json b/tests/stubs/IOStubs/VirtualIO/module.json deleted file mode 100644 index 20f5af0..0000000 --- a/tests/stubs/IOStubs/VirtualIO/module.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "id": "{6179ED6A-FC31-413C-BB8E-1204150CF376}", - "name": "VirtualIO", - "type": 1, - "vendor": "Symcon GmbH", - "aliases": [ - "Virtual IO" - ], - "url": "https://www.symcon.de/service/dokumentation/modulreferenz/io/", - "parentRequirements": [], - "childRequirements": [ - "{018EF6B5-AB94-40C6-AA53-46943E824ACF}" - ], - "implemented": [ - "{79827379-F36E-4ADA-8A95-5F8D1DC92FA9}" - ], - "prefix": "VIO" -} \ No newline at end of file diff --git a/tests/stubs/IOStubs/VirtualIO/module.php b/tests/stubs/IOStubs/VirtualIO/module.php deleted file mode 100644 index c7c8bf9..0000000 --- a/tests/stubs/IOStubs/VirtualIO/module.php +++ /dev/null @@ -1,62 +0,0 @@ -RegisterPropertyBoolean('Open', false); - } - - public function ForwardData($JSONString) - { - parent::ForwardData($JSONString); - - $data = json_decode($JSONString, true); - - if (!isset($data['DataID'])) { - throw new Exception('Invalid Data packet received'); - } - - if ($data['DataID'] == '{79827379-F36E-4ADA-8A95-5F8D1DC92FA9}') { - $this->textQueue[] = utf8_decode($data['Buffer']); - return; - } - - throw new Exception('Unsupported DataID received'); - } - - public function HasText() - { - return count($this->textQueue) > 0; - } - - public function PeekText() - { - if (!$this->HasText()) { - throw new Exception('There is not data available'); - } - - return $this->textQueue[0]; - } - - public function PopText() - { - $result = $this->PeekText(); - array_shift($this->textQueue); - - return $result; - } - - public function PushText(string $Text) - { - $this->SendDataToChildren(json_encode([ - 'DataID' => '{018EF6B5-AB94-40C6-AA53-46943E824ACF}', - 'Buffer' => utf8_encode($Text) - ])); - } -} diff --git a/tests/stubs/IOStubs/WWWReader/module.json b/tests/stubs/IOStubs/WWWReader/module.json deleted file mode 100644 index f7894ec..0000000 --- a/tests/stubs/IOStubs/WWWReader/module.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "id": "{4CB91589-CE01-4700-906F-26320EFCF6C4}", - "name": "WWWReader", - "type": 1, - "vendor": "Symcon GmbH", - "aliases": [ - "WWW Reader" - ], - "url": "https://www.symcon.de/service/dokumentation/modulreferenz/io/wwwreader/", - "parentRequirements": [], - "childRequirements": [ - "{018EF6B5-AB94-40C6-AA53-46943E824ACF}" - ], - "implemented": [ - "{D4C1D08F-CD3B-494B-BE18-B36EF73B8F43}" - ], - "prefix": "WWW" -} \ No newline at end of file diff --git a/tests/stubs/IOStubs/WWWReader/module.php b/tests/stubs/IOStubs/WWWReader/module.php deleted file mode 100644 index 683eb0a..0000000 --- a/tests/stubs/IOStubs/WWWReader/module.php +++ /dev/null @@ -1,6 +0,0 @@ - $library['id'], - 'Author' => $library['author'], - 'URL' => $library['url'], - 'Name' => $library['name'], - 'Version' => $library['version'], - 'Build' => $library['build'], - 'Date' => $library['date'], - ]; - self::loadModules(dirname($file), $library['id']); - } - - public static function reset() - { - self::$libraries = []; - self::$modules = []; - } - - private static function checkLibrary(string $LibraryID): void - { - if (!self::libraryExists($LibraryID)) { - throw new \Exception(sprintf('Library #%s does not exist', $LibraryID)); - } - } - - private static function checkModule(string $ModuleID): void - { - if (!self::moduleExists($ModuleID)) { - throw new \Exception(sprintf('Module #%s does not exist', $ModuleID)); - } - } - - private static function loadModules(string $folder, string $libraryID): void - { - $modules = glob($folder . '/*', GLOB_ONLYDIR); - $filter = ['libs', 'docs', 'imgs', 'tests', 'actions']; - foreach ($modules as $module) { - if (!in_array(basename($module), $filter)) { - self::loadModule($module, $libraryID); - } - } - } - - private static function loadModule(string $folder, string $libraryID): void - { - $module = json_decode(file_get_contents($folder . '/module.json'), true); - self::$modules[$module['id']] = [ - 'ModuleID' => $module['id'], - 'ModuleName' => $module['name'], - 'ModuleType' => $module['type'], - 'Vendor' => $module['vendor'], - 'Aliases' => $module['aliases'], - 'ParentRequirements' => $module['parentRequirements'], - 'ChildRequirements' => $module['childRequirements'], - 'Implemented' => $module['implemented'], - 'LibraryID' => $libraryID, - 'Prefix' => $module['prefix'], - 'Class' => str_replace(' ', '', $module['name']) - ]; - - //Include module class file - require_once $folder . '/module.php'; - - self::registerFunctions($module['name'], $module['prefix']); - } - - private static function registerFunctions($moduleName, $modulePrefix) - { - $class = new \ReflectionClass(str_replace(' ', '', $moduleName)); - foreach ($class->GetMethods() as $method) { - if (!$method->isPublic()) { - continue; - } - if (in_array($method->GetName(), ['__construct', '__destruct', '__call', '__callStatic', '__get', '__set', '__isset', '__sleep', '__wakeup', '__toString', '__invoke', '__set_state', '__clone', '__debuginfo', 'Create', 'Destroy', 'ApplyChanges', 'ReceiveData', 'ForwardData', 'RequestAction', 'MessageSink', 'GetConfigurationForm', 'GetConfigurationForParent', 'Translate'])) { - continue; - } - $params = ['int $InstanceID']; - $fwdparams = []; - foreach ($method->getParameters() as $parameter) { - $type = @$parameter->GetClass(); - if ($type !== false && $type !== null) { - $type = strtolower($type->GetName()); - } else { - $type = $parameter->GetType(); - if ($type !== null) { - $type = $type->GetName(); - } - } - $params[] = $type . ' $' . $parameter->GetName(); - $fwdparams[] = '$' . $parameter->GetName(); - } - $function = sprintf('function %s_%s(%s){return IPS\InstanceManager::getInstanceInterface($InstanceID)->%s(%s);}', $modulePrefix, $method->GetName(), implode(', ', $params), $method->GetName(), implode(', ', $fwdparams)); - if (!\function_exists($modulePrefix . '_' . $method->GetName())) { - eval($function); - } - } - } - } - - class ObjectManager - { - private static $availableIDs = []; - - private static $objects = []; - - public static function registerObject(int $ObjectType): int - { - if (count(self::$objects) == 0) { - throw new \Exception('Reset was not called on Kernel.'); - } - - //Initialize - if (count(self::$availableIDs) == 0 && count(self::$objects) == 1) { - for ($i = 10000; $i < 60000; $i++) { - self::$availableIDs[] = $i; - } - shuffle(self::$availableIDs); - } - - //Check for availability - if (count(self::$availableIDs) == 0) { - throw new \Exception('No usable IDs left. Please contact support.'); - } - - //Fetch first. The array is already randomized - $id = array_shift(self::$availableIDs); - - //Add object - self::$objects[$id] = [ - 'ObjectID' => $id, - 'ObjectType' => $ObjectType, - 'ObjectName' => sprintf('Unnamed Object (ID: %d)', $id), - 'ObjectIcon' => '', - 'ObjectInfo' => '', - 'ObjectIdent' => '', - 'ObjectSummary' => '', - 'ObjectIsHidden' => false, - 'ObjectIsDisabled' => false, - 'ObjectIsLocked' => false, - 'ObjectIsReadOnly' => false, - 'ObjectPosition' => 0, - 'ParentID' => 0, - 'ChildrenIDs' => [], - 'HasChildren' => false - ]; - - //Add to root - self::$objects[0]['ChildrendIDs'][] = $id; - self::$objects[0]['HasChildren'] = true; - - return $id; - } - - public static function unregisterObject(int $ID): void - { - self::checkObject($ID); - - if (self::hasChildren($ID)) { - throw new \Exception('Cannot call UnregisterObject if a children is present'); - } - - //Delete ID from Children array - $ParentID = self::$objects[$ID]['ParentID']; - if (($key = array_search($ID, self::$objects[$ParentID]['ChildrenIDs'])) !== false) { - unset(self::$objects[$ParentID]['ChildrenIDs'][$key]); - } - - //Readd ID to available pool - self::$availableIDs[] = $ID; - } - - public static function setParent(int $ID, int $ParentID): void - { - self::checkRoot($ID); - self::checkObject($ID); - - self::$objects[self::$objects[$ID]['ParentID']]['ChildrenIDs'] = array_diff(self::$objects[self::$objects[$ID]['ParentID']]['ChildrenIDs'], [$ID]); - self::$objects[$ID]['ParentID'] = $ParentID; - self::$objects[$ParentID]['ChildrenIDs'][] = $ID; - } - - public static function setIdent(int $ID, string $Ident): void - { - self::checkObject($ID); - - if (!preg_match('/[a-zA-Z0-9_]*/', $Ident)) { - throw new \Exception('Ident may contain only letters and numbers'); - } - - if ($Ident != '') { - $ParentID = self::$objects[$ID]['ParentID']; - foreach (self::$objects[$ParentID]['ChildrenIDs'] as $ChildID) { - if (self::$objects[$ChildID]['ObjectIdent'] == $Ident) { - if ($ChildID != $ID) { - throw new \Exception('Ident must be unique for each category'); - } - } - } - } - - self::$objects[$ID]['ObjectIdent'] = $Ident; - } - - public static function setName(int $ID, string $Name): void - { - self::checkObject($ID); - - if ($Name == '') { - $Name = sprintf('Unnamed Object (ID: %d)', $ID); - } - - self::$objects[$ID]['ObjectName'] = $Name; - } - - public static function setInfo(int $ID, string $Info): void - { - self::checkObject($ID); - - self::$objects[$ID]['ObjectInfo'] = $Info; - } - - public static function setIcon(int $ID, string $Icon): void - { - self::checkObject($ID); - - self::$objects[$ID]['ObjectIcon'] = $Icon; - } - - public static function setSummary(int $ID, string $Summary): void - { - self::checkRoot($ID); - - self::$objects[$ID]['ObjectSummary'] = $Summary; - } - - public static function setPosition(int $ID, int $Position): void - { - self::checkRoot($ID); - self::checkObject($ID); - - self::$objects[$ID]['ObjectPosition'] = $Position; - } - - public static function setReadOnly(int $ID, bool $ReadOnly): void - { - self::checkRoot($ID); - self::checkObject($ID); - - self::$objects[$ID]['ObjectIsReadOnly'] = $ReadOnly; - } - - public static function setHidden(int $ID, bool $Hidden): void - { - self::checkRoot($ID); - self::checkObject($ID); - - self::$objects[$ID]['ObjectIsHidden'] = $Hidden; - } - - public static function setDisabled(int $ID, bool $Disabled): void - { - self::checkRoot($ID); - self::checkObject($ID); - - self::$objects[$ID]['ObjectIsDisabled'] = $Disabled; - } - - public static function objectExists(int $ID): bool - { - return isset(self::$objects[$ID]); - } - - public static function getObject(int $ID): array - { - self::checkObject($ID); - - return self::$objects[$ID]; - } - - public static function getObjectList(): array - { - return array_keys(self::$objects); - } - - public static function getObjectIDByName(string $Name, int $ParentID): array - { - if ($Name == '') { - throw new \Exception('Name cannot be empty'); - } - - self::checkObject($ParentID); - foreach (self::$objects[$ParentID]['ChildrenIDs'] as $ChildID) { - self::checkObject($ChildID); - if (self::$objects[$ChildID]['ObjectName'] == $Name) { - return $ChildID; - } - } - - throw new \Exception(sprintf('Object with name %s could not be found', $Name)); - } - - public static function getObjectIDByNameEx(string $Name, int $ParentID, int $ObjectType): int - { - if ($Name == '') { - throw new \Exception('Name cannot be empty'); - } - - self::checkObject($ParentID); - foreach (self::$objects[$ParentID]['ChildrenIDs'] as $ChildID) { - self::checkObject($ChildID); - if (self::$objects[$ChildID]['ObjectType'] == $ObjectType) { - if (self::$objects[$ChildID]['ObjectName'] == $Name) { - return $ChildID; - } - } - } - - throw new \Exception(sprintf('Object with name %s could not be found', $Name)); - } - - public static function getObjectIDByIdent(string $Ident, int $ParentID) - { - if ($Ident == '') { - throw new \Exception('Ident cannot be empty'); - } - - self::checkObject($ParentID); - foreach (self::$objects[$ParentID]['ChildrenIDs'] as $ChildID) { - self::checkObject($ChildID); - if (self::$objects[$ChildID]['ObjectIdent'] == $Ident) { - return $ChildID; - } - } - - trigger_error(sprintf('Object with ident %s could not be found', $Ident)); - return false; - } - - public static function hasChildren(int $ID): bool - { - return count(self::getChildrenIDs($ID)) > 0; - } - - public static function isChild(int $ID, int $ParentID, bool $Recursive): bool - { - throw new \Exception('FIXME: Not implemented'); - } - - public static function getChildrenIDs(int $ID): array - { - self::checkObject($ID); - - return self::$objects[$ID]['ChildrenIDs']; - } - - public static function getName(int $ID): string - { - return self::$objects[$ID]['ObjectName']; - } - - public static function getParent(int $ID): int - { - return self::$objects[$ID]['ParentID']; - } - - public static function getLocation(int $ID): string - { - $result = self::getName($ID); - $parentID = self::getParent($ID); - - while ($parentID > 0) { - $result = self::getName($parentID) . '\\' . $result; - $parentID = self::getParent($parentID); - } - - return $result; - } - - public static function reset() - { - self::$availableIDs = []; - self::$objects = [ - 0 => [ - 'ObjectID' => 0, - 'ObjectType' => 0 /* Category */, - 'ObjectName' => 'IP-Symcon', - 'ObjectIcon' => '', - 'ObjectInfo' => '', - 'ObjectIdent' => '', - 'ObjectSummary' => '', - 'ObjectIsHidden' => false, - 'ObjectIsDisabled' => false, - 'ObjectIsLocked' => false, - 'ObjectIsReadOnly' => false, - 'ObjectPosition' => 0, - 'ParentID' => 0, - 'ChildrenIDs' => [], - 'HasChildren' => false - ] - ]; - } - - private static function checkRoot(int $ID): void - { - if ($ID == 0) { - throw new \Exception('Cannot change root'); - } - } - - private static function checkObject(int $ID): void - { - if (!self::objectExists($ID)) { - throw new \Exception(sprintf('Object #%d does not exist', $ID)); - } - } - } - - class CategoryManager - { - private static $categories = []; - - public static function createCategory(int $CategoryID): void - { - self::$categories[$CategoryID] = []; - } - - public static function deleteCategory(int $CategoryID): void - { - self::checkCategory($CategoryID); - unset(self::$categories[$CategoryID]); - } - - public static function categoryExists(int $CategoryID): bool - { - return isset(self::$categories[$CategoryID]); - } - - public static function getCategory(int $CategoryID): array - { - self::checkCategory($CategoryID); - - return []; - } - - public static function getCategoryList(): array - { - return array_keys(self::$categories); - } - - public static function reset() - { - self::$categories = []; - } - - private static function checkCategory(int $CategoryID): void - { - if (!self::categoryExists($CategoryID)) { - throw new \Exception(sprintf('Category #%d does not exist', $CategoryID)); - } - } - } - - class InstanceManager - { - private static $instances = []; - private static $interfaces = []; - - public static function createInstance(int $InstanceID, array $Module): void - { - if (!class_exists($Module['Class'])) { - throw new \Exception(sprintf('Cannot find class %s', $Module['Class'])); - } - - if (!in_array('IPSModule', class_parents($Module['Class'])) && !in_array('IPSModuleStrict', class_parents($Module['Class']))) { - throw new \Exception(sprintf('Class %s does not inherit from IPSModule or IPSModuleStrict', $Module['Class'])); - } - - self::$instances[$InstanceID] = [ - 'InstanceID' => $InstanceID, - 'ConnectionID' => 0, - 'InstanceStatus' => 100 /* IS_CREATING */, - 'InstanceChanged' => time(), - 'ModuleInfo' => [ - 'ModuleID' => $Module['ModuleID'], - 'ModuleName' => $Module['ModuleName'], - 'ModuleType' => $Module['ModuleType'] - ], - ]; - - $interface = new $Module['Class']($InstanceID); - - self::$interfaces[$InstanceID] = $interface; - - if (($interface instanceof \IPSModule) || ($interface instanceof \IPSModuleStrict)) { - $interface->Create(); - $interface->ApplyChanges(); - } - } - - public static function deleteInstance(int $InstanceID): void - { - self::checkInstance($InstanceID); - unset(self::$instances[$InstanceID]); - unset(self::$interfaces[$InstanceID]); - } - - public static function instanceExists(int $InstanceID): bool - { - return isset(self::$instances[$InstanceID]); - } - - public static function getInstance(int $InstanceID): array - { - self::checkInstance($InstanceID); - - return self::$instances[$InstanceID]; - } - - public static function getInstanceInterface(int $InstanceID): mixed - { - self::checkInstance($InstanceID); - - return self::$interfaces[$InstanceID]; - } - - public static function getInstanceList(): array - { - return array_keys(self::$instances); - } - - public static function getInstanceListByModuleType(int $ModuleType): array - { - $result = []; - foreach (self::$instances as $instance) { - if ($instance['ModuleInfo']['ModuleType'] == $ModuleType) { - $result[] = $instance['InstanceID']; - } - } - - return $result; - } - - public static function getInstanceListByModuleID(string $ModuleID): array - { - $result = []; - foreach (self::$instances as $instance) { - if ($instance['ModuleInfo']['ModuleID'] == $ModuleID) { - $result[] = $instance['InstanceID']; - } - } - - return $result; - } - - public static function setStatus($InstanceID, $Status): void - { - self::checkInstance($InstanceID); - - self::$instances[$InstanceID]['InstanceStatus'] = $Status; - } - - public static function getStatus($InstanceID): int - { - self::checkInstance($InstanceID); - - return self::$instances[$InstanceID]['InstanceStatus']; - } - - public static function connectInstance(int $InstanceID, int $ParentID): void - { - self::checkInstance($InstanceID); - self::$instances[$InstanceID]['ConnectionID'] = $ParentID; - } - - public static function disconnectInstance(int $InstanceID): void - { - self::checkInstance($InstanceID); - self::$instances[$InstanceID]['ConnectionID'] = 0; - } - - public static function getReferenceList($InstanceID) - { - self::checkInstance($InstanceID); - - return self::$interfaces[$InstanceID]->GetReferenceList(); - } - - public static function reset() - { - self::$instances = []; - self::$interfaces = []; - } - - private static function checkInstance(int $InstanceID): void - { - if (!self::instanceExists($InstanceID)) { - throw new \Exception(sprintf('Instance #%d does not exist', $InstanceID)); - } - } - } - - class VariableManager - { - private static $variables = []; - - public static function createVariable(int $VariableID, int $VariableType): void - { - switch ($VariableType) { - case 0: /* Boolean */ - $VariableValue = false; - break; - case 1: /* Integer */ - $VariableValue = 0; - break; - case 2: /* Float */ - $VariableValue = 0.0; - break; - case 3: /* String */ - $VariableValue = ''; - break; - default: - throw new \Exception('Unsupported VariableType!'); - } - - self::$variables[$VariableID] = [ - 'VariableID' => $VariableID, - 'VariableProfile' => '', - 'VariableAction' => 0, - 'VariableCustomProfile' => '', - 'VariableCustomAction' => 0, - 'VariableUpdated' => 0, - 'VariableChanged' => 0, - 'VariableType' => $VariableType, - 'VariableValue' => $VariableValue, - 'VariableIsLocked' => false - ]; - } - - public static function deleteVariable(int $VariableID): void - { - self::checkVariable($VariableID); - unset(self::$variables[$VariableID]); - } - - public static function readVariableBoolean(int $VariableID): bool - { - self::checkVariable($VariableID); - - return self::$variables[$VariableID]['VariableValue']; - } - - public static function writeVariableBoolean(int $VariableID, bool $VariableValue): void - { - self::checkVariable($VariableID); - - self::$variables[$VariableID]['VariableUpdated'] = time(); - if (self::$variables[$VariableID]['VariableValue'] != $VariableValue) { - self::$variables[$VariableID]['VariableChanged'] = time(); - } - self::$variables[$VariableID]['VariableValue'] = $VariableValue; - } - - public static function readVariableInteger(int $VariableID): int - { - self::checkVariable($VariableID); - - return self::$variables[$VariableID]['VariableValue']; - } - - public static function writeVariableInteger(int $VariableID, int $VariableValue): void - { - self::checkVariable($VariableID); - - self::$variables[$VariableID]['VariableUpdated'] = time(); - if (self::$variables[$VariableID]['VariableValue'] != $VariableValue) { - self::$variables[$VariableID]['VariableChanged'] = time(); - } - self::$variables[$VariableID]['VariableValue'] = $VariableValue; - } - - public static function readVariableFloat(int $VariableID): float - { - self::checkVariable($VariableID); - - return self::$variables[$VariableID]['VariableValue']; - } - - public static function writeVariableFloat(int $VariableID, float $VariableValue): void - { - self::checkVariable($VariableID); - - self::$variables[$VariableID]['VariableUpdated'] = time(); - if (self::$variables[$VariableID]['VariableValue'] != $VariableValue) { - self::$variables[$VariableID]['VariableChanged'] = time(); - } - self::$variables[$VariableID]['VariableValue'] = $VariableValue; - } - - public static function readVariableString(int $VariableID): string - { - self::checkVariable($VariableID); - - return self::$variables[$VariableID]['VariableValue']; - } - - public static function writeVariableString(int $VariableID, string $VariableValue): void - { - self::checkVariable($VariableID); - - self::$variables[$VariableID]['VariableUpdated'] = time(); - if (self::$variables[$VariableID]['VariableValue'] != $VariableValue) { - self::$variables[$VariableID]['VariableChanged'] = time(); - } - self::$variables[$VariableID]['VariableValue'] = $VariableValue; - } - - public static function variableExists(int $VariableID): bool - { - return isset(self::$variables[$VariableID]); - } - - public static function checkVariable(int $VariableID): void - { - if (!self::variableExists($VariableID)) { - throw new \Exception(sprintf('Variable #%d does not exist', $VariableID)); - } - } - - public static function getVariable(int $VariableID): array - { - self::checkVariable($VariableID); - - return self::$variables[$VariableID]; - } - - public static function getVariableList(): array - { - return array_keys(self::$variables); - } - - public static function setVariableCustomProfile(int $VariableID, string $ProfileName): void - { - self::checkVariable($VariableID); - - self::$variables[$VariableID]['VariableCustomProfile'] = $ProfileName; - } - - public static function setVariableCustomAction(int $VariableID, int $ScriptID): void - { - self::checkVariable($VariableID); - - self::$variables[$VariableID]['VariableCustomAction'] = $ScriptID; - } - - public static function setVariableProfile(int $VariableID, string $ProfileName): void - { - self::checkVariable($VariableID); - - self::$variables[$VariableID]['VariableProfile'] = $ProfileName; - } - - public static function setVariableAction(int $VariableID, int $InstanceID): void - { - self::checkVariable($VariableID); - - self::$variables[$VariableID]['VariableAction'] = $InstanceID; - } - - public static function reset() - { - self::$variables = []; - } - } - - class ScriptManager - { - private static $scripts = []; - private static $content = []; - - public static function createScript(int $ScriptID, int $ScriptType): void - { - self::$scripts[$ScriptID] = [ - 'ScriptID' => $ScriptID, - 'ScriptType' => $ScriptType, - 'ScriptFile' => $ScriptID . '.ips.php', - 'ScriptExecuted' => 0, - 'ScriptIsBroken' => false - ]; - - self::$content[$ScriptID] = ''; - } - - public static function deleteScript(int $ScriptID, bool $DeleteFile): void - { - self::checkScript($ScriptID); - unset(self::$scripts[$ScriptID]); - } - - public static function setScriptFile(int $ScriptID, string $FilePath): void - { - self::$scripts[$ScriptID]['ScriptFile'] = $FilePath; - } - - public static function setScriptContent(int $ScriptID, string $Content): void - { - self::$content[$ScriptID] = $Content; - } - - public static function scriptExists(int $ScriptID): bool - { - return isset(self::$scripts[$ScriptID]); - } - - public static function checkScript(int $ScriptID): void - { - if (!self::scriptExists($ScriptID)) { - throw new \Exception(sprintf('Script #%d does not exist', $ScriptID)); - } - } - - public static function getScript(int $ScriptID): array - { - self::checkScript($ScriptID); - - return self::$scripts[$ScriptID]; - } - - public static function getScriptList(): array - { - return array_keys(self::$scripts); - } - - public static function getScriptFile(int $ScriptID): string - { - self::checkScript($ScriptID); - - return self::$scripts[$ScriptID]['ScriptFile']; - } - - public static function getScriptContent(int $ScriptID): string - { - return self::$content[$ScriptID]; - } - - public static function reset() - { - self::$scripts = []; - } - } - - class ScriptEngine - { - public static function runScript(int $ScriptID): void - { - self::runScriptEx($ScriptID, []); - } - - public static function runScriptEx(int $ScriptID, array $Parameters): void - { - self::runScriptWaitEx($ScriptID, $Parameters); - } - - public static function IPS_RunScriptWait(int $ScriptID): string - { - return self::runScriptWaitEx($ScriptID, []); - } - - public static function runScriptWaitEx(int $ScriptID, array $Parameters): string - { - return self::runScriptTextWaitEx(ScriptManager::getScriptContent($ScriptID), $Parameters); - } - - public static function runScriptText(string $ScriptText): void - { - self::runScriptTextEx($ScriptText, []); - } - - public static function runScriptTextEx(string $ScriptText, array $Parameters): void - { - self::runScriptTextWaitEx($ScriptText, $Parameters); - } - - public static function runScriptTextWait(string $ScriptText): string - { - return self::runScriptTextWaitEx($ScriptText, []); - } - - public static function runScriptTextWaitEx(string $ScriptText, array $Parameters): string - { - $ScriptText = str_replace('', '', $ScriptText); - $ScriptText = '$_IPS = ' . var_export($Parameters, true) . ';' . PHP_EOL . $ScriptText; - ob_start(); - eval($ScriptText); - $out = ob_get_contents(); - ob_end_clean(); - return $out; - } - - public static function semaphoreEnter(string $Name, int $Milliseconds): bool - { - throw new Exception('Not implemented'); - } - - public static function semaphoreLeave(string $Name): bool - { - throw new Exception('Not implemented'); - } - - public static function scriptThreadExists(int $ThreadID): bool - { - throw new Exception('Not implemented'); - } - - public static function getScriptThread(int $ThreadID): array - { - throw new Exception('Not implemented'); - } - - public static function getScriptThreadList(): array - { - throw new Exception('Not implemented'); - } - } - - class DataServer - { - public static function functionExists(string $FunctionName): bool - { - throw new Exception('Not implemented'); - } - - public static function getFunction(string $FunctionName): array - { - throw new Exception('Not implemented'); - } - - public static function getFunctionList(int $InstanceID): array - { - throw new Exception('Not implemented'); - } - - public static function getFunctionListByModuleID(string $ModuleID): array - { - throw new Exception('Not implemented'); - } - - public static function getFunctions(array $Parameter): array - { - throw new Exception('Not implemented'); - } - - public static function getFunctionsMap(array $Parameter): array - { - throw new Exception('Not implemented'); - } - } - - class EventManager - { - private static $events = []; - - public static function reset() - { - self::$events = []; - } - } - - class MediaManager - { - private static $medias = []; - - public static function createMedia(int $MediaID, int $MediaType): void - { - self::$medias[$MediaID] = [ - 'MediaID' => $MediaID, - 'MediaType' => $MediaType, - 'MediaIsAvailable' => false, - 'MediaFile' => '', - 'MediaCRC' => '', - 'MediaIsCached' => false, - 'MediaSize' => 0, - 'MediaUpdated' => 0 - ]; - } - - public static function deleteMedia(int $MediaID, bool $DeleteFile): void - { - self::checkMedia($MediaID); - unset(self::$medias[$MediaID]); - } - - public static function mediaExists(int $MediaID): bool - { - return isset(self::$medias[$MediaID]); - } - - public static function checkMedia(int $MediaID): void - { - if (!self::mediaExists($MediaID)) { - throw new \Exception(sprintf('Media #%d does not exist', $MediaID)); - } - } - - public static function reset() - { - self::$medias = []; - } - } - - class LinkManager - { - private static $links = []; - - public static function createLink(int $LinkID) - { - self::$links[$LinkID] = [ - 'LinkID' => $LinkID, - 'TargetID' => 0 - ]; - } - - public static function deleteLink(int $LinkID) - { - self::checkLink($LinkID); - unset(self::$links[$LinkID]); - } - - public static function getLink(int $LinkID) - { - self::checkLink($LinkID); - return self::$links[$LinkID]; - } - - public static function getLinkIdByName(string $LinkName, int $ParentID) - { - throw new \Exception('Getting link by name is not implemented yet'); - } - - public static function getLinkList() - { - self::checkLink($LinkID); - return array_keys(self::$links); - } - - public static function linkExists(int $LinkID) - { - return isset(self::$links[$LinkID]); - } - - public static function setLinkTargetID(int $LinkID, int $TargetID) - { - self::checkLink($LinkID); - self::$links[$LinkID]['TargetID'] = $TargetID; - } - - public static function reset() - { - self::$links = []; - } - - private static function checkLink(int $LinkID) - { - if (!self::linkExists($LinkID)) { - throw new \Exception(sprintf('Link #%d does not exist', $LinkID)); - } - } - } - - class ProfileManager - { - private static $profiles = []; - - public static function createVariableProfile(string $ProfileName, int $ProfileType): void - { - self::$profiles[$ProfileName] = [ - 'ProfileName' => $ProfileName, - 'ProfileType' => $ProfileType, - 'Icon' => '', - 'Prefix' => '', - 'Suffix' => '', - 'MaxValue' => 0, - 'MinValue' => 0, - 'Digits' => 0, - 'StepSize' => 0, - 'IsReadOnly' => false, - 'Associations' => [] - ]; - } - - public static function deleteVariableProfile(string $ProfileName): void - { - self::checkVariableProfile($ProfileName); - unset(self::$profiles[$ProfileName]); - } - - public static function setVariableProfileText(string $ProfileName, string $Prefix, string $Suffix): void - { - self::checkVariableProfile($ProfileName); - - self::$profiles[$ProfileName]['Prefix'] = $Prefix; - self::$profiles[$ProfileName]['Suffix'] = $Suffix; - } - - public static function setVariableProfileValues(string $ProfileName, float $MinValue, float $MaxValue, float $StepSize): void - { - self::checkVariableProfile($ProfileName); - - self::$profiles[$ProfileName]['MinValue'] = $MinValue; - self::$profiles[$ProfileName]['MaxValue'] = $MaxValue; - self::$profiles[$ProfileName]['StepSize'] = $StepSize; - } - - public static function setVariableProfileDigits(string $ProfileName, int $Digits): void - { - self::checkVariableProfile($ProfileName); - - self::$profiles[$ProfileName]['Digits'] = $Digits; - } - - public static function setVariableProfileIcon(string $ProfileName, string $Icon): void - { - self::checkVariableProfile($ProfileName); - - self::$profiles[$ProfileName]['Icon'] = $Icon; - } - - public static function setVariableProfileAssociation(string $ProfileName, $AssociationValue, string $AssociationName, string $AssociationIcon, int $AssociationColor) - { - self::checkVariableProfile($ProfileName); - if (($AssociationName == '') && ($AssociationIcon == '')) { - unset($keyFound); - foreach (self::$profiles[$ProfileName]['Associations'] as $key => $association) { - if ($association['Value'] == $AssociationValue) { - $keyFound = $key; - break; - } - } - if (isset($keyFound)) { - unset(self::$profiles[$ProfileName]['Associations'][$keyFound]); - if (self::$profiles[$ProfileName]['ProfileType'] != VARIABLETYPE_STRING) { - usort(self::$profiles[$ProfileName]['Associations'], function ($a, $b) - { - return $a['Value'] - $b['Value']; - }); - } - } else { - trigger_error(sprintf('Cannot find association for deletion with value %f', $AssociationValue), E_USER_WARNING); - } - return; - } - - foreach (self::$profiles[$ProfileName]['Associations'] as &$association) { - if ($association['Value'] == $AssociationValue) { - $association['Name'] = $AssociationName; - $association['Icon'] = $AssociationIcon; - $association['Color'] = $AssociationColor; - return; - } - } - - self::$profiles[$ProfileName]['Associations'][] = [ - 'Value' => $AssociationValue, - 'Name' => $AssociationName, - 'Icon' => $AssociationIcon, - 'Color' => $AssociationColor - ]; - - if (self::$profiles[$ProfileName]['ProfileType'] != VARIABLETYPE_STRING) { - usort(self::$profiles[$ProfileName]['Associations'], function ($a, $b) - { - return $a['Value'] - $b['Value']; - }); - } - } - - public static function variableProfileExists(string $ProfileName): bool - { - return isset(self::$profiles[$ProfileName]); - } - - public static function checkVariableProfile(string $ProfileName): void - { - if (!self::variableProfileExists($ProfileName)) { - throw new \Exception(sprintf('Profile #%s does not exist', $ProfileName)); - } - } - - public static function getVariableProfile(string $ProfileName): array - { - self::checkVariableProfile($ProfileName); - - return self::$profiles[$ProfileName]; - } - - public static function getVariableProfileList(): array - { - return array_keys(self::$profiles); - } - - public static function getVariableProfileListByType(int $ProfileType): array - { - $result = []; - foreach (self::$profiles as $profile) { - if ($profile['ProfileType'] == $ProfileType) { - $result[] = $profile; - } - } - - return $result; - } - - public static function reset() - { - self::$profiles = []; - } - } - - class DebugServer - { - private static $debug = []; - private static $messages = []; - - public static function disableDebug(int $ID): void - { - self::$debug[$ID] = 0; - } - - public static function enableDebug(int $ID, int $Duration): void - { - self::$debug[$ID] = time() + $Duration; - } - - public static function sendDebug(int $SenderID, string $Message, string $Data, int $Format): void - { - self::$messages[$SenderID][] = [ - 'Message' => $Message, - 'Data' => $Data, - 'Format' => $Format - ]; - - if (!isset(self::$debug[$SenderID])) { - return; - } - - if (time() > self::$debug[$SenderID]) { - return; - } - - if ($Format == 1 /* Binary */) { - $Data = bin2hex($Data); - } - - echo 'DEBUG: ' . $Message . ' | ' . $Data . PHP_EOL; - } - - public static function getDebugMessages($SenderID): array - { - if (!isset(self::$messages[$SenderID])) { - return []; - } - return self::$messages[$SenderID]; - } - - public static function reset() - { - self::$debug = []; - } - } - - class ActionPool - { - private static $actions = []; - - public static function loadActions(string $ActionPath): void - { - if (substr($ActionPath, -1) !== '/') { - $ActionPath .= '/'; - } - - $handle = opendir($ActionPath); - - $file = readdir($handle); - while ($file !== false) { - if (is_file($ActionPath . $file) && (substr($file, -5) === '.json')) { - self::$actions[] = json_decode(file_get_contents($ActionPath . $file), true); - } - $file = readdir($handle); - } - - closedir($handle); - } - - public static function getActions(): string - { - return json_encode(self::$actions); - } - - public static function getActionsByEnvironment(int $ID, string $Environment, bool $IncludeDefault): string - { - throw new Exception('Not implemented'); - } - - public static function getActionForm(string $ActionID, array $Parameters): string - { - throw new Exception('Not implemented'); - } - - public static function getActionReadableCode(string $ActionID, array $Parameters): string - { - throw new Exception('Not implemented'); - } - - public static function runAction(string $ActionID, array $Parameters): void - { - self::runActionWait($ActionID, $Parameters); - } - - public static function runActionWait(string $ActionID, array $Parameters): string - { - foreach (self::$actions as $action) { - if ($action['id'] === $ActionID) { - $scriptText = $action['action']; - if (is_array($scriptText)) { - $scriptText = implode("\n", $scriptText); - } - // This will probably not work with included php files - return ScriptEngine::runScriptTextWaitEx($scriptText, $Parameters); - } - } - - throw new Exception('Action does not exist'); - } - - public static function updateFormField(string $Name, string $Parameter, $Value, $ID, string $SessionID): void - { - throw new Exception('Not implemented'); - } - - public static function reset(): void - { - self::$actions = []; - } - } - - class Kernel - { - public static function reset() - { - ModuleLoader::reset(); - ObjectManager::reset(); - CategoryManager::reset(); - InstanceManager::reset(); - VariableManager::reset(); - ScriptManager::reset(); - EventManager::reset(); - MediaManager::reset(); - LinkManager::reset(); - ProfileManager::reset(); - DebugServer::reset(); - ActionPool::reset(); - } - } -} diff --git a/tests/stubs/MessageStubs.php b/tests/stubs/MessageStubs.php deleted file mode 100644 index 2a6cba2..0000000 --- a/tests/stubs/MessageStubs.php +++ /dev/null @@ -1,147 +0,0 @@ -{$name}(...$arguments); - } -} - -class IPSModuleStrict -{ - private IPSModulePublic $module; - private array $protectedMethods; - - public function __construct(int $InstanceID) - { - $this->module = new IPSModulePublic($InstanceID); - } - - public function Create(): void - { - $this->module->Create(); - } - - public function Destroy(): void - { - $this->module->Destroy(); - } - - public function GetProperty(string $Name): mixed - { - return $this->module->GetProperty($Name); - } - - public function SetProperty(string $Name, mixed $Value): void - { - $this->module->SetProperty($Name, $Value); - } - - public function GetConfiguration(): string - { - return $this->module->GetConfiguration(); - } - - public function SetConfiguration(string $Configuration): void - { - $this->module->SetConfiguration($Configuration); - } - - public function MessageSink(int $TimeStamp, int $SenderID, int $Message, array $Data): void - { - $this->module->MessageSink($TimeStamp, $SenderID, $Message, $Data); - } - - public function HasChanges(): bool - { - return $this->module->HasChanges(); - } - - public function ResetChanges(): void - { - $this->module->ResetChanges(); - } - - public function ApplyChanges(): void - { - $this->module->ApplyChanges(); - } - - public function GetReceiveDataFilter(): string - { - return $this->module->GetReceiveDataFilter(); - } - - public function ReceiveData(string $JSONString): string - { - return $this->module->ReceiveData($JSONString); - } - - public function ForwardData(string $JSONString): string - { - return $this->module->ForwardData($JSONString); - } - - public function GetForwardDataFilter(): string - { - return $this->module->GetForwardDataFilter(); - } - - public function RequestAction(string $Ident, mixed $Value): void - { - $this->module->RequestAction($Ident, $Value); - } - - public function GetConfigurationForm(): string - { - return $this->module->GetConfigurationForm(); - } - - public function GetConfigurationForParent(): string - { - return $this->module->GetConfigurationForParent(); - } - - public function Translate(string $Text): string - { - return $this->module->Translate($Text); - } - - public function GetReferenceList(): array - { - return $this->module->GetReferenceList(); - } - - protected function GetIDForIdent(string $Ident): int - { - return $this->module->GetIDForIdent($Ident); - } - - protected function RegisterPropertyBoolean(string $Name, bool $DefaultValue): bool - { - $this->module->RegisterPropertyBoolean($Name, $DefaultValue); - return true; - } - - protected function RegisterPropertyInteger(string $Name, int $DefaultValue): bool - { - $this->module->RegisterPropertyInteger($Name, $DefaultValue); - return true; - } - - protected function RegisterPropertyFloat(string $Name, float $DefaultValue): bool - { - $this->module->RegisterPropertyFloat($Name, $DefaultValue); - return true; - } - - protected function RegisterPropertyString(string $Name, string $DefaultValue): bool - { - $this->module->RegisterPropertyString($Name, $DefaultValue); - return true; - } - - protected function RegisterAttributeBoolean(string $Name, bool $DefaultValue): bool - { - $this->module->RegisterAttributeBoolean($Name, $DefaultValue); - return true; - } - - protected function RegisterAttributeInteger(string $Name, int $DefaultValue): bool - { - $this->module->RegisterAttributeInteger($Name, $DefaultValue); - return true; - } - - protected function RegisterAttributeFloat(string $Name, float $DefaultValue): bool - { - $this->module->RegisterAttributeFloat($Name, $DefaultValue); - return true; - } - - protected function RegisterAttributeString(string $Name, string $DefaultValue): bool - { - $this->module->RegisterAttributeString($Name, $DefaultValue); - return true; - } - - protected function RegisterOnceTimer(string $Ident, string $ScriptText): bool - { - $this->module->RegisterOnceTimer($Ident, $ScriptText); - return true; - } - - protected function RegisterTimer(string $Ident, int $Milliseconds, string $ScriptText): bool - { - $this->module->RegisterTimer($Ident, $Milliseconds, $ScriptText); - return true; - } - - protected function SetTimerInterval(string $Ident, int $Milliseconds): bool - { - $this->module->SetTimerInterval($Ident, $Milliseconds); - return true; - } - - protected function GetTimerInterval(string $Ident): int - { - return $this->module->GetTimerInterval($Ident); - } - - protected function RegisterScript(string $Ident, string $Name, string $Content = '', int $Position = 0): int - { - return $this->module->RegisterScript($Ident, $Name, $Content, $Position); - } - - protected function RegisterVariableBoolean(string $Ident, string $Name, string $Profile = '', int $Position = 0): bool - { - $variableExists = (@$this->module->GetIDForIdent($Ident) !== false); - $this->module->RegisterVariableBoolean($Ident, $Name, $Profile, $Position); - return !$variableExists; - } - - protected function RegisterVariableInteger(string $Ident, string $Name, string $Profile = '', int $Position = 0): bool - { - $variableExists = (@$this->module->GetIDForIdent($Ident) !== null); - $this->module->RegisterVariableInteger($Ident, $Name, $Profile, $Position); - return !$variableExists; - } - - protected function RegisterVariableFloat(string $Ident, string $Name, string $Profile = '', int $Position = 0): bool - { - $variableExists = (@$this->module->GetIDForIdent($Ident) !== null); - $this->module->RegisterVariableFloat($Ident, $Name, $Profile, $Position); - return !$variableExists; - } - - protected function RegisterVariableString(string $Ident, string $Name, string $Profile = '', int $Position = 0): bool - { - $variableExists = (@$this->module->GetIDForIdent($Ident) !== null); - $this->module->RegisterVariableString($Ident, $Name, $Profile, $Position); - return !$variableExists; - } - - protected function UnregisterVariable(string $Ident): bool - { - $this->module->UnregisterMessage($Ident); - return true; - } - - protected function MaintainVariable(string $Ident, string $Name, int $Type, string $Profile, int $Position, bool $Keep): bool - { - $this->module->MaintainVariable($Ident, $Name, $Type, $Profile, $Position, $Keep); - return true; - } - - protected function EnableAction(string $Ident): bool - { - $this->module->EnableAction($Ident); - return true; - } - - protected function DisableAction(string $Ident): bool - { - $this->module->DisableAction($Ident); - return true; - } - - protected function MaintainAction(string $Ident, bool $Keep): bool - { - $this->module->MaintainAction($Ident, $Keep); - return true; - } - - protected function ReadPropertyBoolean(string $Name): bool - { - return $this->module->ReadPropertyBoolean($Name); - } - - protected function ReadPropertyInteger(string $Name): int - { - return $this->module->ReadPropertyInteger($Name); - } - - protected function ReadPropertyFloat(string $Name): float - { - return $this->module->ReadPropertyFloat($Name); - } - - protected function ReadPropertyString(string $Name): string - { - return $this->module->ReadPropertyString($Name); - } - - protected function ReadAttributeBoolean(string $Name): bool - { - return $this->module->ReadAttributeBoolean($Name); - } - - protected function ReadAttributeInteger(string $Name): int - { - return $this->module->ReadAttributeInteger($Name); - } - - protected function ReadAttributeFloat(string $Name): float - { - return $this->module->ReadAttributeFloat($Name); - } - - protected function ReadAttributeString(string $Name): string - { - return $this->module->ReadAttributeString($Name); - } - - protected function WriteAttributeBoolean(string $Name, bool $Value): bool - { - $this->module->WriteAttributeBoolean($Name, $Value); - return true; - } - - protected function WriteAttributeInteger(string $Name, int $Value): bool - { - $this->module->WriteAttributeInteger($Name, $Value); - return true; - } - - protected function WriteAttributeFloat(string $Name, float $Value): bool - { - $this->module->WriteAttributeFloat($Name, $Value); - return true; - } - - protected function WriteAttributeString(string $Name, string $Value): bool - { - $this->module->WriteAttributeString($Name, $Value); - return true; - } - - protected function SendDataToParent(string $Data): string - { - return $this->module->SendDataToParent($Data) ?? ''; - } - - protected function SendDataToChildren(string $Data): array - { - return $this->module->SendDataToChildren($Data); - } - - protected function ConnectParent(string $ModuleID): bool - { - $this->module->ConnectParent($ModuleID); - return true; - } - - protected function RequireParent(string $ModuleID): bool - { - $this->module->RequireParent($ModuleID); - return true; - } - - protected function ForceParent(string $ModuleID): bool - { - $this->module->ForceParent($MduleID); - return true; - } - - protected function SetStatus(int $Status): bool - { - $this->module->SetStatus($Status); - return true; - } - - protected function GetStatus(): int - { - return $this->module->GetStatus(); - } - - protected function SetSummary(string $Summary): bool - { - $this->module->SetSummary($Summary); - return true; - } - - protected function SetBuffer(string $Name, string $Data): bool - { - $this->module->SetBuffer($Name, $Data); - return true; - } - - protected function GetBufferList(): array - { - return $this->module->GetBufferList($Name, $Data); - } - - protected function GetBuffer(string $Name): string - { - return $this->module->GetBuffer($Name); - } - - protected function SendDebug(string $Message, string $Data, int $Format): bool - { - $this->module->SendDebug($Message, $Data, $Format); - return true; - } - - protected function GetMessageList(): array - { - return $this->module->GetMessageList(); - } - - protected function RegisterMessage(int $SenderID, int $Message): bool - { - $this->module->RegisterMessage($SenderID, $Message); - return true; - } - - protected function UnregisterMessage(int $SenderID, int $Message): bool - { - $this->module->UnregisterMessage($SenderID, $Message); - return true; - } - - protected function SetReceiveDataFilter(string $RequiredRegexMatch): bool - { - $this->module->SetReceiveDataFilter($RequiredRegexMatch); - return true; - } - - protected function SetForwardDataFilter(string $RequiredRegexMatch): bool - { - $this->module->SetForwardDataFilter($RequiredRegexMatch); - return true; - } - - protected function RegisterReference(int $ID): bool - { - $this->module->RegisterReference($ID); - return true; - } - - protected function UnregisterReference(int $ID): bool - { - $this->module->UnregisterReference($ID); - return true; - } - - protected function ReloadForm(): bool - { - $this->module->ReloadForm(); - return true; - } - - protected function UpdateFormField(string $Field, string $Parameter, mixed $Value): bool - { - $this->module->UpdateFormField($Field, $Parameter, $Value); - return true; - } - - protected function GetValue(string $Ident): mixed - { - return $this->module->GetValue($Ident); - } - - protected function SetValue(string $Ident, mixed $Value): bool - { - return $this->module->SetValue($Ident, $Value); - } - - protected function LogMessage(string $Message, int $Type): bool - { - $this->module->LogMessage($Message, $Type); - return true; - } - - protected function HasActiveParent(): bool - { - return $this->module->HasActiveParent(); - } - - protected function RegisterHook(string $HookPath): void - { - } - - protected function RegisterOAuth(string $OAuthPath): void - { - } - - protected function getTime(): int - { - return $this->module->getTime(); - } -} diff --git a/tests/stubs/ModuleStubs.php b/tests/stubs/ModuleStubs.php deleted file mode 100644 index 04b4b5d..0000000 --- a/tests/stubs/ModuleStubs.php +++ /dev/null @@ -1,741 +0,0 @@ -InstanceID = $InstanceID; - } - - public function Create() - { - //Has to be overwritten by implementing module - } - - public function Destroy() - { - //Has to be overwritten by implementing module - } - - public function GetProperty($Name) - { - if (!isset($this->properties[$Name])) { - throw new Exception(sprintf('Property %s not found', $Name)); - } - - return $this->properties[$Name]['Current']; - } - - public function SetProperty($Name, $Value) - { - if (!isset($this->properties[$Name])) { - throw new Exception(sprintf('Property %s not found', $Name)); - } - - $this->properties[$Name]['Pending'] = $Value; - } - - public function GetConfiguration() - { - $result = []; - foreach ($this->properties as $name => $property) { - $result[$name] = $property['Current']; - } - - return json_encode($result); - } - - public function SetConfiguration($Configuration) - { - $json = json_decode($Configuration); - if ($json === null) { - throw new \Exception('Cannot parse configuration json'); - } - foreach ($json as $name => $value) { - if (isset($this->properties[$name])) { - $this->properties[$name]['Pending'] = $value; - } - } - } - - public function MessageSink($TimeStamp, $SenderID, $Message, $Data) - { - //Has to be overwritten by implementing module - } - - public function HasChanges() - { - foreach ($this->properties as &$property) { - if ($property['Current'] != $property['Pending']) { - return true; - } - } - - return false; - } - - public function ResetChanges() - { - foreach ($this->properties as &$property) { - $property['Pending'] = $property['Current']; - } - } - - public function ApplyChanges() - { - foreach ($this->properties as &$property) { - $property['Current'] = $property['Pending']; - } - - //If the module overrides ApplyChanges, it might change the status again - if (IPS_GetInstance($this->InstanceID)['InstanceStatus'] == 100 /* IS_CREATING */) { - $this->SetStatus(102 /* IS_ACTIVE */); - } - } - - public function GetReceiveDataFilter() - { - // This getter function is only availabe in Stub, not in PHP-SDK - // It is required to utilize the ReceiveDataFilter - return $this->receiveDataFilter; - } - - public function ReceiveData($JSONString) - { - //Has to be overwritten by implementing module - } - - public function ForwardData($JSONString) - { - //Has to be overwritten by implementing module - return ''; - } - - public function GetForwardDataFilter() - { - // This getter function is only availabe in Stub, not in PHP-SDK - // It is required to utilize the ForwardDataFilter - return $this->forwardDataFilter; - } - - public function RequestAction($Ident, $Value) - { - //Has to be overwritten by implementing module - } - - public function GetConfigurationForm() - { - return '{}'; - } - - public function GetConfigurationForParent() - { - return '{}'; - } - - public function Translate($Text) - { - return $Text; - } - - public function GetReferenceList() - { - return $this->references; - } - - protected function GetIDForIdent($Ident) - { - return IPS_GetObjectIDByIdent($Ident, $this->InstanceID); - } - - protected function RegisterPropertyBoolean($Name, $DefaultValue) - { - $this->RegisterProperty($Name, $DefaultValue, 0); - } - - protected function RegisterPropertyInteger($Name, $DefaultValue) - { - $this->RegisterProperty($Name, $DefaultValue, 1); - } - - protected function RegisterPropertyFloat($Name, $DefaultValue) - { - $this->RegisterProperty($Name, $DefaultValue, 2); - } - - protected function RegisterPropertyString($Name, $DefaultValue) - { - $this->RegisterProperty($Name, $DefaultValue, 3); - } - - protected function RegisterAttributeBoolean($Name, $DefaultValue) - { - $this->RegisterAttribute($Name, $DefaultValue, 0); - } - - protected function RegisterAttributeInteger($Name, $DefaultValue) - { - $this->RegisterAttribute($Name, $DefaultValue, 1); - } - - protected function RegisterAttributeFloat($Name, $DefaultValue) - { - $this->RegisterAttribute($Name, $DefaultValue, 2); - } - - protected function RegisterAttributeString($Name, $DefaultValue) - { - $this->RegisterAttribute($Name, $DefaultValue, 3); - } - - protected function RegisterOnceTimer(string $Ident, string $ScriptText) - { - IPS_RunScriptTextEx($ScriptText, ['TARGET' => $this->InstanceID]); - } - - protected function RegisterTimer(string $Ident, int $Milliseconds, string $ScriptText) - { - $this->timers[$Ident] = [ - 'millis' => $Milliseconds, - 'start' => $this->getTime() - ]; - } - - protected function SetTimerInterval(string $Ident, int $Milliseconds) - { - if (!isset($this->timers[$Ident])) { - throw new Exception('Timer is not registered'); - } - - $this->RegisterTimer($Ident, $Milliseconds, ''); - } - - protected function GetTimerInterval(string $Ident) - { - if (!isset($this->timers[$Ident])) { - throw new Exception('Timer is not registered'); - } - - return $this->timers[$Ident]['millis'] - ($this->getTime() - $this->timers[$Ident]['start']) * 1000; - } - - protected function RegisterScript($Ident, $Name, $Content = '', $Position = 0) - { - //How and why do we want to test this? - return 0; - } - - protected function RegisterVariableBoolean($Ident, $Name, $Profile = '', $Position = 0) - { - return $this->RegisterVariable($Ident, $Name, 0, $Profile, $Position); - } - - protected function RegisterVariableInteger($Ident, $Name, $Profile = '', $Position = 0) - { - return $this->RegisterVariable($Ident, $Name, 1, $Profile, $Position); - } - - protected function RegisterVariableFloat($Ident, $Name, $Profile = '', $Position = 0) - { - return $this->RegisterVariable($Ident, $Name, 2, $Profile, $Position); - } - - protected function RegisterVariableString($Ident, $Name, $Profile = '', $Position = 0) - { - return $this->RegisterVariable($Ident, $Name, 3, $Profile, $Position); - } - - protected function UnregisterVariable($Ident) - { - $vid = @IPS_GetObjectIDByIdent($Ident, $this->InstanceID); - if ($vid === false) { - return; - } - if (!IPS_VariableExists($vid)) { - return; - } //bail out - IPS_DeleteVariable($vid); - } - - protected function MaintainVariable($Ident, $Name, $Type, $Profile, $Position, $Keep) - { - if ($Keep) { - $this->RegisterVariable($Ident, $Name, $Type, $Profile, $Position); - } else { - $this->UnregisterVariable($Ident); - } - } - - protected function EnableAction($Ident) - { - IPS\VariableManager::setVariableAction(IPS_GetObjectIDByIdent($Ident, $this->InstanceID), $this->InstanceID); - } - - protected function DisableAction($Ident) - { - IPS\VariableManager::setVariableAction(IPS_GetObjectIDByIdent($Ident, $this->InstanceID), 0); - } - - protected function MaintainAction($Ident, $Keep) - { - if ($Keep) { - $this->EnableAction($Ident); - } else { - $this->DisableAction($Ident); - } - } - - protected function ReadPropertyBoolean($Name) - { - if (!isset($this->properties[$Name])) { - throw new Exception(sprintf('Property %s not found', $Name)); - } - - if ($this->properties[$Name]['Type'] != 0) { - throw new Exception(sprintf('Property %s is not of type Boolean', $Name)); - } - - return $this->properties[$Name]['Current']; - } - - protected function ReadPropertyInteger($Name) - { - if (!isset($this->properties[$Name])) { - throw new Exception(sprintf('Property %s not found', $Name)); - } - - if ($this->properties[$Name]['Type'] != 1) { - throw new Exception(sprintf('Property %s is not of type Integer', $Name)); - } - - return $this->properties[$Name]['Current']; - } - - protected function ReadPropertyFloat($Name) - { - if (!isset($this->properties[$Name])) { - throw new Exception(sprintf('Property %s not found', $Name)); - } - - if ($this->properties[$Name]['Type'] != 2) { - throw new Exception(sprintf('Property %s is not of type Float', $Name)); - } - - return $this->properties[$Name]['Current']; - } - - protected function ReadPropertyString($Name) - { - if (!isset($this->properties[$Name])) { - throw new Exception(sprintf('Property %s not found', $Name)); - } - - if ($this->properties[$Name]['Type'] != 3) { - throw new Exception(sprintf('Property %s is not of type String', $Name)); - } - - return $this->properties[$Name]['Current']; - } - - protected function ReadAttributeBoolean($Name) - { - if (!isset($this->attributes[$Name])) { - throw new Exception(sprintf('Attribute %s not found', $Name)); - } - - if ($this->attributes[$Name]['Type'] != 0) { - throw new Exception(sprintf('Attribute %s is not of type Boolean', $Name)); - } - - return $this->attributes[$Name]['Current']; - } - - protected function ReadAttributeInteger($Name) - { - if (!isset($this->attributes[$Name])) { - throw new Exception(sprintf('Attribute %s not found', $Name)); - } - - if ($this->attributes[$Name]['Type'] != 1) { - throw new Exception(sprintf('Attribute %s is not of type Integer', $Name)); - } - - return $this->attributes[$Name]['Current']; - } - - protected function ReadAttributeFloat($Name) - { - if (!isset($this->attributes[$Name])) { - throw new Exception(sprintf('Attribute %s not found', $Name)); - } - - if ($this->attributes[$Name]['Type'] != 2) { - throw new Exception(sprintf('Attribute %s is not of type Float', $Name)); - } - - return $this->attributes[$Name]['Current']; - } - - protected function ReadAttributeString($Name) - { - if (!isset($this->attributes[$Name])) { - throw new Exception(sprintf('Attribute %s not found', $Name)); - } - - if ($this->attributes[$Name]['Type'] != 3) { - throw new Exception(sprintf('Attribute %s is not of type String', $Name)); - } - - return $this->attributes[$Name]['Current']; - } - - protected function WriteAttributeBoolean($Name, bool $Value) - { - if (!isset($this->attributes[$Name])) { - throw new Exception(sprintf('Attribute %s not found', $Name)); - } - - if ($this->attributes[$Name]['Type'] != 0) { - throw new Exception(sprintf('Attribute %s is not of type Boolean', $Name)); - } - - $this->attributes[$Name]['Current'] = $Value; - } - - protected function WriteAttributeInteger($Name, int $Value) - { - if (!isset($this->attributes[$Name])) { - throw new Exception(sprintf('Attribute %s not found', $Name)); - } - - if ($this->attributes[$Name]['Type'] != 1) { - throw new Exception(sprintf('Attribute %s is not of type Integer', $Name)); - } - - $this->attributes[$Name]['Current'] = $Value; - } - - protected function WriteAttributeFloat($Name, float $Value) - { - if (!isset($this->attributes[$Name])) { - throw new Exception(sprintf('Attribute %s not found', $Name)); - } - - if ($this->attributes[$Name]['Type'] != 2) { - throw new Exception(sprintf('Attribute %s is not of type Float', $Name)); - } - - $this->attributes[$Name]['Current'] = $Value; - } - - protected function WriteAttributeString($Name, string $Value) - { - if (!isset($this->attributes[$Name])) { - throw new Exception(sprintf('Attribute %s not found', $Name)); - } - - if ($this->attributes[$Name]['Type'] != 3) { - throw new Exception(sprintf('Attribute %s is not of type String', $Name)); - } - - $this->attributes[$Name]['Current'] = $Value; - } - - protected function SendDataToParent($Data) - { - //FIXME: We could validate something here - $connectionID = IPS_GetInstance($this->InstanceID)['ConnectionID']; - $interface = IPS\InstanceManager::getInstanceInterface($connectionID); - // check if forwardDataFilter applys - if (preg_match('/' . $interface->GetForwardDataFilter() . '/', $Data) == 1) { - return $interface->ForwardData($Data); - } - return ''; - } - - protected function SendDataToChildren($Data) - { - //FIXME: We could validate something here - $ids = IPS_GetInstanceList(); - $return = []; - foreach ($ids as $id) { - if (IPS_GetInstance($id)['ConnectionID'] == $this->InstanceID) { - $interface = IPS\InstanceManager::getInstanceInterface($id); - // check if receiveDataFilter applys - if (preg_match('/' . $interface->GetReceiveDataFilter() . '/', $Data) == 1) { - $singleReturn = $interface->ReceiveData($Data); - if ($singleReturn != '') { - $return[] = $singleReturn; - } - } - } - } - return $return; - } - - protected function ConnectParent($ModuleID) - { - if (IPS_GetInstance($this->InstanceID)['ConnectionID'] == 0) { - $ids = IPS_GetInstanceListByModuleID($ModuleID); - if (count($ids) > 0) { - IPS_ConnectInstance($this->InstanceID, $ids[0]); - return; - } - - //Let this function create our parent - $this->RequireParent($ModuleID); - } - } - - protected function RequireParent($ModuleID) - { - if (IPS_GetInstance($this->InstanceID)['ConnectionID'] == 0) { - $id = IPS_CreateInstance($ModuleID); - $module = IPS_GetModule($ModuleID); - IPS_SetName($id, $module['ModuleName']); - IPS_ConnectInstance($this->InstanceID, $id); - } - } - - protected function ForceParent($ModuleID) - { - //Cleanup parent, if not correct - $connectionID = IPS_GetInstance($this->InstanceID)['ConnectionID']; - if ($connectionID != 0) { - $instance = IPS_GetInstance($connectionID); - if ($instance['ModuleInfo']['ModuleID'] != $ModuleID) { - IPS_DisconnectInstance($this->InstanceID); - - //Only clean up instance, if no other instance is connected - $ids = IPS_GetInstanceList(); - $inUse = false; - foreach ($ids as $id) { - if (IPS_GetInstance($id)['ConnectionID'] == $connectionID) { - $inUse = true; - break; - } - } - if (!$inUse) { - IPS_DeleteInstance($connectionID); - } - } - } - - //Let this function create our parent - $this->RequireParent($ModuleID); - } - - protected function SetStatus($Status) - { - IPS\InstanceManager::setStatus($this->InstanceID, $Status); - } - - protected function GetStatus() - { - return IPS\InstanceManager::getStatus($this->InstanceID); - } - - protected function SetSummary($Summary) - { - IPS\ObjectManager::setSummary($this->InstanceID, $Summary); - } - - protected function SetBuffer($Name, $Data) - { - $this->buffer[$Name] = $Data; - } - - protected function GetBufferList() - { - return array_keys($this->buffer); - } - - protected function GetBuffer($Name) - { - if (isset($this->buffer[$Name])) { - return $this->buffer[$Name]; - } else { - return ''; - } - } - - protected function SendDebug($Message, $Data, $Format) - { - IPS_SendDebug($this->InstanceID, $Message, $Data, $Format); - } - - protected function GetMessageList() - { - // TODO: Some implementation here would be nice, but this suffices for the time being - return []; - } - - protected function RegisterMessage($SenderID, $Message) - { - } - - protected function UnregisterMessage($SenderID, $Message) - { - } - - protected function SetReceiveDataFilter($RequiredRegexMatch) - { - $this->receiveDataFilter = $RequiredRegexMatch; - } - - protected function SetForwardDataFilter($RequiredRegexMatch) - { - $this->forwardDataFilter = $RequiredRegexMatch; - } - - protected function RegisterReference(int $ID) - { - if (!in_array($ID, $this->references)) { - $this->references[] = $ID; - } - } - - protected function UnregisterReference(int $ID) - { - if (in_array($ID, $this->references)) { - array_splice($this->references, array_search($ID, $this->references), 1); - } - } - - protected function ReloadForm() - { - } - - protected function UpdateFormField($Field, $Parameter, $Value) - { - } - - protected function GetValue(string $Ident) - { - return GetValue(IPS_GetObjectIDByIdent($Ident, $this->InstanceID)); - } - - protected function SetValue(string $Ident, $Value) - { - return SetValue(IPS_GetObjectIDByIdent($Ident, $this->InstanceID), $Value); - } - - protected function LogMessage($Message, $Type) - { - } - - protected function HasActiveParent() - { - $instanceID = IPS_GetInstance($this->InstanceID)['ConnectionID']; - if ($instanceID == 0) { - return false; - } - while (true) { - if ($instanceID == 0) { - break; - } - if (IPS_GetInstance($this->InstanceID)['InstanceStatus'] != IS_ACTIVE) { - return false; - } - $instanceID = IPS_GetInstance($instanceID)['ConnectionID']; - } - return IPS\InstanceManager::getStatus(IPS_GetInstance($this->InstanceID)['ConnectionID']) == IS_ACTIVE; - } - - protected function getTime() - { - throw new Exception('getTime needs to be implemented by module under test'); - } - - private function RegisterProperty($Name, $DefaultValue, $Type) - { - $this->properties[$Name] = [ - 'Type' => $Type, - 'Default' => $DefaultValue, - 'Current' => $DefaultValue, - 'Pending' => $DefaultValue - ]; - } - - private function RegisterAttribute($Name, $DefaultValue, $Type) - { - $this->attributes[$Name] = [ - 'Type' => $Type, - 'Default' => $DefaultValue, - 'Current' => $DefaultValue - ]; - } - - private function RegisterVariable($Ident, $Name, $Type, $Profile, $Position) - { - if ($Profile != '') { - //prefer system profiles - if (IPS_VariableProfileExists('~' . $Profile)) { - $Profile = '~' . $Profile; - } - if (!IPS_VariableProfileExists($Profile)) { - throw new Exception('Profile with name ' . $Profile . ' does not exist'); - } - - //make typecheck - if (IPS_GetVariableProfile($Profile)['ProfileType'] != $Type) { - throw new Exception('Profile with name ' . $Profile . ' is not of type ' . $Type); - } - } - - //search for already available variables with proper ident - $vid = @IPS_GetObjectIDByIdent($Ident, $this->InstanceID); - - //properly update variableID - if ($vid === false) { - $vid = 0; - } - - //we have a variable with the proper ident. check if it fits - if ($vid > 0) { - //check if we really have a variable - if (!IPS_VariableExists($vid)) { - throw new Exception('Ident with name ' . $Ident . ' is used for wrong object type'); - } //bail out - //check for type mismatch - if (IPS_GetVariable($vid)['VariableType'] != $Type) { - //mismatch detected. delete this one. we will create a new below - IPS_DeleteVariable($vid); - //this will ensure, that a new one is created - $vid = 0; - } - } - - //we need to create one - if ($vid == 0) { - $vid = IPS_CreateVariable($Type); - - //configure it - IPS_SetParent($vid, $this->InstanceID); - IPS_SetIdent($vid, $Ident); - IPS_SetName($vid, $Name); - IPS_SetPosition($vid, $Position); - //IPS_SetReadOnly($vid, true); - } - - //update variable profile. profiles may be changed in module development. - //this update does not affect any custom profile choices - IPS\VariableManager::setVariableProfile($vid, $Profile); - - return $vid; - } -} diff --git a/tests/stubs/README.md b/tests/stubs/README.md deleted file mode 100644 index ac9f626..0000000 --- a/tests/stubs/README.md +++ /dev/null @@ -1,7 +0,0 @@ -# Stubs für IP-Symcon 5.x - -[![IP-Symcon is awesome!](https://img.shields.io/badge/IP--Symcon-5.x-blue.svg)](https://www.symcon.de) -[![Check Style](https://github.com/symcon/SymconStubs/workflows/Check%20Style/badge.svg)](https://github.com/symcon/SymconStubs/actions) -[![Run Tests](https://github.com/symcon/SymconStubs/workflows/Run%20Tests/badge.svg)](https://github.com/symcon/SymconStubs/actions) - -_Dieses Repository enthält Stubs, welche zum automatisierten Testen von IP-Symcon PHP Modulen genutzt werden können._ diff --git a/tests/stubs/Validator.php b/tests/stubs/Validator.php deleted file mode 100644 index d2e0d38..0000000 --- a/tests/stubs/Validator.php +++ /dev/null @@ -1,158 +0,0 @@ -assertTrue(true); - } - - protected function validateLibrary($folder): void - { - $library = json_decode(file_get_contents($folder . '/library.json'), true); - - $this->assertArrayHasKey('id', $library); - $this->assertIsString($library['id']); - $this->assertTrue($this->isValidGUID($library['id']), 'library id is not a valid GUID'); - - $this->assertArrayHasKey('author', $library); - $this->assertIsString($library['author']); - - $this->assertArrayHasKey('name', $library); - $this->assertIsString($library['name']); - - $this->assertArrayHasKey('url', $library); - $this->assertIsString($library['url']); - $this->assertTrue($this->isValidURL($library['url']), 'library url is not a valid'); - - $this->assertArrayHasKey('version', $library); - $this->assertIsString($library['version']); - - $this->assertArrayHasKey('build', $library); - $this->assertIsInt($library['build']); - - $this->assertArrayHasKey('date', $library); - $this->assertIsInt($library['date']); - - //This is purely optional - if (!isset($library['compatibility'])) { - $this->assertCount(7, $library); - } else { - $this->assertCount(8, $library); - $this->assertIsArray($library['compatibility']); - if (isset($library['compatibility']['version'])) { - $this->assertIsString($library['compatibility']['version']); - } - if (isset($library['compatibility']['date'])) { - $this->assertIsInt($library['compatibility']['date']); - } - } - } - - protected function validateModule($folder): void - { - $module = json_decode(file_get_contents($folder . '/module.json'), true); - - $this->assertArrayHasKey('id', $module); - $this->assertIsString($module['id']); - $this->assertTrue($this->isValidGUID($module['id']), 'module id is not a valid GUID'); - - $this->assertArrayHasKey('name', $module); - $this->assertIsString($module['name']); - $this->assertTrue($this->isValidName($module['name']), 'module name is not valid'); - - $this->assertArrayHasKey('type', $module); - $this->assertIsInt($module['type']); - $this->assertGreaterThanOrEqual(0, $module['type']); - $this->assertLessThanOrEqual(5, $module['type']); - - $this->assertArrayHasKey('vendor', $module); - $this->assertIsString($module['vendor']); - - $this->assertArrayHasKey('aliases', $module); - $this->assertIsArray($module['aliases']); - - $this->assertArrayHasKey('url', $module); - $this->assertIsString($module['url']); - $this->assertTrue($this->isValidURL($module['url']), 'module url is not valid'); - - $this->assertArrayHasKey('parentRequirements', $module); - $this->assertIsArray($module['parentRequirements']); - foreach ($module['parentRequirements'] as $parentRequirement) { - $this->assertIsString($parentRequirement); - $this->assertTrue($this->isValidGUID($parentRequirement), 'module parent requirements guid is not valid'); - } - - $this->assertArrayHasKey('childRequirements', $module); - $this->assertIsArray($module['childRequirements']); - foreach ($module['childRequirements'] as $childRequirement) { - $this->assertIsString($childRequirement); - $this->assertTrue($this->isValidGUID($childRequirement), 'module child requirements guid is not valid'); - } - - $this->assertArrayHasKey('implemented', $module); - $this->assertIsArray($module['implemented']); - foreach ($module['implemented'] as $implemented) { - $this->assertIsString($implemented); - $this->assertTrue($this->isValidGUID($implemented), 'module implemented guid is not valid'); - } - - $this->assertArrayHasKey('prefix', $module); - $this->assertIsString($module['prefix']); - $this->assertTrue($this->isValidPrefix($module['prefix']), 'module prefix is not valid'); - - if (file_exists($folder . '/form.json')) { - $this->assertTrue(json_decode(file_get_contents($folder . '/form.json')) !== null, 'module form.json is invalid JSON'); - } - - if (file_exists($folder . '/locale.json')) { - $this->assertTrue(json_decode(file_get_contents($folder . '/locale.json')) !== null, 'module locale.json is invalid JSON'); - } - - //Check if parameter types are set - include_once "$folder/module.php"; - $class = new \ReflectionClass(str_replace(' ', '', $module['name'])); - foreach ($class->GetMethods() as $method) { - if (!$method->isPublic()) { - continue; - } - if (in_array($method->GetName(), ['__construct', '__destruct', '__call', '__callStatic', '__get', '__set', '__isset', '__sleep', '__wakeup', '__toString', '__invoke', '__set_state', '__clone', '__debuginfo', 'Create', 'Destroy', 'ApplyChanges', 'ReceiveData', 'ForwardData', 'RequestAction', 'MessageSink', 'GetConfigurationForm', 'GetConfigurationForParent', 'Translate', 'GetProperty', 'SetProperty', 'SetConfiguration'])) { - continue; - } - foreach ($method->getParameters() as $parameter) { - $this->assertTrue($parameter->hasType(), sprintf("Parameter '%s' on method '%s' is missing type hint definition", $parameter->getName(), $method->getName())); - } - } - } - - private function isValidGUID($guid): bool - { - return preg_match('/^\{?[A-Z0-9]{8}-[A-Z0-9]{4}-[A-Z0-9]{4}-[A-Z0-9]{4}-[A-Z0-9]{12}\}?$/', $guid) == 1; - } - - private function isValidName($name): bool - { - return preg_match('/^[A-Za-z0-9](?:[A-Za-z0-9 _]*[A-Za-z0-9])?$/', $name) == 1; - } - - private function isValidPrefix($name): bool - { - return preg_match('/^[A-Z0-9]+$/', $name) == 1; - } - - private function isValidURL($name): bool - { - return preg_match('/^(?:http:\/\/|https:\/\/)/', $name) == 1; - } - - private function ignoreFolders(): array - { - return ['..', '.', 'libs', 'docs', 'imgs', 'tests']; - } -} diff --git a/tests/stubs/autoload.php b/tests/stubs/autoload.php deleted file mode 100644 index 9f744b1..0000000 --- a/tests/stubs/autoload.php +++ /dev/null @@ -1,10 +0,0 @@ -validateLibrary(__DIR__ . '/../CoreStubs'); - } - - public function testValidateDNSSDControl(): void - { - $this->validateModule(__DIR__ . '/../CoreStubs/DNSSDControl'); - } -} diff --git a/tests/stubs/tests/IOStubsValidationTest.php b/tests/stubs/tests/IOStubsValidationTest.php deleted file mode 100644 index 7c4b7ed..0000000 --- a/tests/stubs/tests/IOStubsValidationTest.php +++ /dev/null @@ -1,48 +0,0 @@ -validateLibrary(__DIR__ . '/../IOStubs'); - } - - public function testValidateClientSocket(): void - { - $this->validateModule(__DIR__ . '/../IOStubs/ClientSocket'); - } - - public function testValidateMulticastSocket(): void - { - $this->validateModule(__DIR__ . '/../IOStubs/MulticastSocket'); - } - - public function testValidateSerialPort(): void - { - $this->validateModule(__DIR__ . '/../IOStubs/SerialPort'); - } - - public function testValidateServerSocket(): void - { - $this->validateModule(__DIR__ . '/../IOStubs/ServerSocket'); - } - - public function testValidateUDPSocket(): void - { - $this->validateModule(__DIR__ . '/../IOStubs/UDPSocket'); - } - - public function testValidateVirtualIO(): void - { - $this->validateModule(__DIR__ . '/../IOStubs/VirtualIO'); - } - - public function testValidateWWWReader(): void - { - $this->validateModule(__DIR__ . '/../IOStubs/WWWReader'); - } -} diff --git a/tests/stubs/tests/phpunit.xml b/tests/stubs/tests/phpunit.xml deleted file mode 100644 index 3407a08..0000000 --- a/tests/stubs/tests/phpunit.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - -