-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[matter_yamltests] Add supports for OTA_SuccessfulTransfer specific S…
…ystemCommands and DelayCommands
- Loading branch information
1 parent
02f35ec
commit 3439762
Showing
3 changed files
with
163 additions
and
62 deletions.
There are no files selected for viewing
109 changes: 109 additions & 0 deletions
109
.../py_matter_yamltests/matter_yamltests/pseudo_clusters/clusters/accessory_server_bridge.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
# | ||
# Copyright (c) 2023 Project CHIP Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the 'License'); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an 'AS IS' BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import sys | ||
import xmlrpc.client | ||
|
||
_DEFAULT_KEY = 'default' | ||
_IP = '127.0.0.1' | ||
_PORT = 9000 | ||
|
||
if sys.platform == 'linux': | ||
_IP = '10.10.10.5' | ||
|
||
|
||
def _make_url(): | ||
return f'http://{_IP}:{_PORT}/' | ||
|
||
|
||
def _get_option(request, item_name: str, default_value=None): | ||
if request.arguments: | ||
values = request.arguments['values'] | ||
for item in values: | ||
name = item['name'] | ||
value = item['value'] | ||
if name == item_name: | ||
return value | ||
|
||
return default_value | ||
|
||
|
||
def _get_start_options(request): | ||
options = [] | ||
|
||
if request.arguments: | ||
values = request.arguments['values'] | ||
for item in values: | ||
name = item['name'] | ||
value = item['value'] | ||
|
||
if name == 'discriminator': | ||
options.append('--discriminator') | ||
options.append(str(value)) | ||
elif name == 'port': | ||
options.append('--secured-device-port') | ||
options.append(str(value)) | ||
elif name == 'kvs': | ||
options.append('--KVS') | ||
options.append(str(value)) | ||
elif name == 'minCommissioningTimeout': | ||
options.append('--min_commissioning_timeout') | ||
options.append(str(value)) | ||
elif name == 'filepath': | ||
options.append('--filepath') | ||
options.append(str(value)) | ||
elif name == 'otaDownloadPath': | ||
options.append('--otaDownloadPath') | ||
options.append(str(value)) | ||
elif name == 'registerKey': | ||
pass | ||
else: | ||
raise KeyError(f'Unknown key: {name}') | ||
|
||
return options | ||
|
||
|
||
class AccessoryServerBridge(): | ||
def start(request): | ||
register_key = _get_option(request, 'registerKey', _DEFAULT_KEY) | ||
options = _get_start_options(request) | ||
|
||
with xmlrpc.client.ServerProxy(_make_url(), allow_none=True) as proxy: | ||
proxy.start(register_key, options) | ||
|
||
def stop(request): | ||
register_key = _get_option(request, 'registerKey', _DEFAULT_KEY) | ||
|
||
with xmlrpc.client.ServerProxy(_make_url(), allow_none=True) as proxy: | ||
proxy.stop(register_key) | ||
|
||
def reboot(request): | ||
register_key = _get_option(request, 'registerKey', _DEFAULT_KEY) | ||
|
||
with xmlrpc.client.ServerProxy(_make_url(), allow_none=True) as proxy: | ||
proxy.reboot(register_key) | ||
|
||
def factoryReset(request): | ||
register_key = _get_option(request, 'registerKey', _DEFAULT_KEY) | ||
|
||
with xmlrpc.client.ServerProxy(_make_url(), allow_none=True) as proxy: | ||
proxy.factoryReset(register_key) | ||
|
||
def waitForMessage(request): | ||
register_key = _get_option(request, 'registerKey', _DEFAULT_KEY) | ||
message = _get_option(request, 'message') | ||
|
||
with xmlrpc.client.ServerProxy(_make_url(), allow_none=True) as proxy: | ||
proxy.waitForMessage(register_key, [message]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters