Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start of python YAML test parsers and executer #23533

Merged
merged 11 commits into from
Nov 14, 2022
5 changes: 5 additions & 0 deletions src/controller/python/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,10 @@ chip_python_wheel_action("chip-core") {
"chip/storage/__init__.py",
"chip/utils/CommissioningBuildingBlocks.py",
"chip/utils/__init__.py",
"chip/yaml/DataModelLookup.py",
"chip/yaml/YamlParser.py",
"chip/yaml/YamlUtils.py",
"chip/yaml/__init__.py",
andy31415 marked this conversation as resolved.
Show resolved Hide resolved
]

if (chip_controller) {
Expand Down Expand Up @@ -269,6 +273,7 @@ chip_python_wheel_action("chip-core") {
"chip.internal",
"chip.interaction_model",
"chip.logging",
"chip.yaml",
"chip.native",
"chip.clusters",
"chip.setup_payload",
Expand Down
245 changes: 245 additions & 0 deletions src/controller/python/chip/clusters/Objects.py

Large diffs are not rendered by default.

55 changes: 55 additions & 0 deletions src/controller/python/chip/yaml/DataModelLookup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#
# Copyright (c) 2022 Project CHIP Authors
# All rights reserved.
#
# 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.
#

from abc import ABC, abstractmethod
import chip.clusters as Clusters


class DataModelLookup(ABC):
@abstractmethod
def get_cluster(self, cluster: str):
pass

@abstractmethod
def get_command(self, cluster: str, command: str):
pass

@abstractmethod
def get_attribute(self, cluster: str, attribute: str):
pass


class PreDefinedDataModelLookup(DataModelLookup):
def get_cluster(self, cluster: str):
try:
return getattr(Clusters, cluster, None)
except AttributeError:
return None

def get_command(self, cluster: str, command: str):
try:
commands = getattr(Clusters, cluster, None).Commands
return getattr(commands, command, None)
except AttributeError:
return None

def get_attribute(self, cluster: str, attribute: str):
try:
attributes = getattr(Clusters, cluster, None).Attributes
return getattr(attributes, attribute, None)
except AttributeError:
return None
Loading