-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Valve cluster: refactor to make unit-testable #35631
Draft
cecille
wants to merge
35
commits into
project-chip:master
Choose a base branch
from
cecille:valve
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 27 commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
6f3357b
Valve: disco ball - Attribute getters
cecille 1ab57bb
Valve: Disco ball - Attribute Setters for client
cecille 6d4c366
Valve: Disco ball - Open command
cecille 30e6fd1
Valve: Disco ball - start of Remaining duration with Q
cecille 02906e1
Valve: Disco ball - Handle automatic close
cecille 8bf5e5a
Valve: disco ball - Handle close command
cecille 2e4f0ff
Valve: Disco ball - Access and command interfaces
cecille 83d5b79
Valve: Disco ball - add example app
cecille 100a967
Add endpoint marker to print
cecille 52449a3
add feature map and cluster revision
cecille 9e6b521
Merge remote-tracking branch 'upstream/master' into valve
cecille 58cfb19
Fix conformance
cecille 6be91cd
Add taglists to distinguish endpoints
cecille bc8f3d4
Use Node label instead of tags
cecille ab2b7bd
Valve: fix write to use KVS manager properly
cecille 0712293
TC-DESC-2.2: Fix comparison when mfg label is in the list
cecille 2710453
TC-VALCC-3.1: Allow immediate open of valve
cecille e0195d7
TC-VALCC-4.2: unconditionally write open duration
cecille eb2dcbf
VALCC: Remove top-level PICS
cecille 3e30568
controller start: not done or tested
cecille b994417
controller now tested
cecille f01c8f5
Add readme and additional functions for controller
cecille 84a0899
valve: Set target state to transitioning first
cecille bdadfb0
fixup for 3.1 test
cecille 847a8d7
another fixup for 3.1
cecille 8d1491e
Add close at start of test
cecille 31ed684
Fix tests to account for unconditional change to target and current a…
cecille 1a1d5c6
Add a mystery option to the controller
cecille 03c8e98
Merge remote-tracking branch 'upstream/master' into valve
cecille 6e354ba
Fix build file from bad merge
cecille b95be0a
python framework: Fix warning on asyncio not awaited
cecille 82e67de
Uncomment the attribute access interface registration - whoops
cecille e3a9b43
fix up some tests
cecille 90e41f5
Merge remote-tracking branch 'upstream/master' into valve
cecille a0c0737
Merge remote-tracking branch 'origin/valve' into valve_rebased
cecille File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# Running the drinks machine app and controller | ||
|
||
To run this example matter application, you need a version of the example app | ||
and a controller. The example app can be compiled with gn / ninja, the | ||
controller functions can be used through the chip-repl python shell | ||
|
||
## App | ||
|
||
### Compiling the app on linux | ||
|
||
From the root of the chip tree | ||
|
||
``` | ||
cd examples/valve/linux | ||
gn gen out/debug | ||
ninja -C out/debug | ||
``` | ||
|
||
### Running the app on linux | ||
|
||
From the root of the chip tree | ||
|
||
``` | ||
./examples/valve/linux/out/debug/valve-app --KVS /tmp/valve_kvs.json | ||
``` | ||
|
||
The KVS file is where the commissioning data is stored for the app, so be sure | ||
to start the app with the same kvs file if you do not want to re-commission it | ||
every time. All the standard linux app flags also work for this app. Use --help | ||
to see the available options. | ||
|
||
## Controller | ||
|
||
### Compiling the chip-repl | ||
|
||
To compile the chip-repl, from the root of the chip tree: | ||
|
||
``` | ||
. scripts/activate.sh | ||
./scripts/build_python.sh -i out/pyenv | ||
source out/pyenv/activate | ||
out/pyenv/chip-repl -- | ||
``` | ||
|
||
The chip-repl is a shell that lets you directly call python functions. It | ||
instantiates a controller object that can be used to communicate with devices. | ||
The controller is called devCtrl. By default, its KVS is at | ||
/tmp/repl-storage.json, but this can be changed on the command line if desired. | ||
Use --help to see options. | ||
|
||
### Commissioning the valve app | ||
|
||
As long as the controller and the application KVSs are kept constant, the app | ||
should only need to be commissioned once. | ||
|
||
To commission the device use: | ||
|
||
``` | ||
from chip import ChipDeviceCtrl | ||
await devCtrl.CommissionOnNetwork(nodeId=1, setupPinCode=20202021, filterType=ChipDeviceCtrl.DiscoveryFilterType.LONG_DISCRIMINATOR, filter=3840) | ||
``` | ||
|
||
### Interacting with teh valve app | ||
|
||
To create a drinks machine controller: | ||
|
||
``` | ||
import examples.valve.controller as DrinksController | ||
dm = DrinksController.DrinkMachine(devCtrl, 1) | ||
``` | ||
|
||
You can now call functions on the drinks machine controller. Tab completion will | ||
work within the repl, so you can see the available options. |
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,84 @@ | ||
from enum import StrEnum | ||
from chip import ChipDeviceCtrl | ||
from chip.clusters.Types import NullValue | ||
import chip.clusters as Clusters | ||
|
||
|
||
class Bottle(StrEnum): | ||
kBourbon = "bourbon" | ||
kGin = "gin" | ||
kCampari = "campari" | ||
kVermouth = "vermouth" | ||
kSourMix = "sour mix" | ||
kSimpleSyrup = "simple syrup", | ||
|
||
|
||
class Oz: | ||
def __init__(self, oz: float): | ||
self.oz = oz | ||
|
||
def time(self): | ||
# One oz == approx 12s. | ||
return self.oz * 12 | ||
|
||
|
||
class DrinkMachine: | ||
def __init__(self, devCtrl: ChipDeviceCtrl, node_id: int): | ||
self.dev_ctrl = devCtrl | ||
self.node_id = node_id | ||
# TODO: Should this actually be modelled as an aggregator with bridged nodes so I can have a NodeLabel? | ||
# Right now I'm going to leave this as something on the app side because it's a demo, but it's weird that we don't have writeable labels unless you model it strangely. Spec issue? | ||
self.bottles: dict[Bottle, int] = {Bottle.kBourbon: 1, Bottle.kGin: 2, | ||
Bottle.kCampari: 3, Bottle.kVermouth: 4, Bottle.kSourMix: 5, Bottle.kSimpleSyrup: 6} | ||
self.recipes: dict[str, dict[Bottle, Oz]] = {} | ||
self.add_recipe("negroni", {Bottle.kGin: Oz(1.5), Bottle.kCampari: Oz(1.5), Bottle.kVermouth: Oz(1.5)}) | ||
self.add_recipe("boulevardier", {Bottle.kBourbon: Oz(1.5), Bottle.kCampari: Oz(1.5), Bottle.kVermouth: Oz(1.5)}) | ||
self.add_recipe("bourbon sour", {Bottle.kBourbon: Oz(2), Bottle.kSourMix: Oz(1), Bottle.kSimpleSyrup: Oz(1.5)}) | ||
self.add_recipe("martini", {Bottle.kGin: Oz(2), Bottle.kVermouth: Oz(0.25)}) | ||
self.add_recipe("gimlet", {Bottle.kGin: Oz(2.5), Bottle.kSourMix: Oz(0.5), Bottle.kSimpleSyrup: Oz(0.5)}) | ||
self.add_recipe("old fashioned", {Bottle.kBourbon: Oz(2), Bottle.kSimpleSyrup: Oz(0.125)}) | ||
self.add_recipe("shot of bourbon", {Bottle.kBourbon: Oz(1.5)}) | ||
self.add_recipe("shot of gin", {Bottle.kGin: Oz(1.5)}) | ||
|
||
def set_bottle_names(self, bottles: dict[Bottle, int]) -> bool: | ||
''' Bottle is a dict of bottle name to endpoint and should contain all 6 endpoints at once''' | ||
if len(bottles) != 6: | ||
return False | ||
self.bottles = bottles | ||
|
||
def get_bottle_names(self): | ||
return self.bottles | ||
|
||
def get_recipes(self): | ||
return self.recipes | ||
|
||
def add_recipe(self, name: str, ingredients: dict[Bottle, Oz]): | ||
# TODO: should store somewhere permanent - simplest is to write out to file. In the meanwhile, we have a few pre-populated | ||
self.recipes[name] = ingredients | ||
|
||
async def dispense(self, recipe: str): | ||
# TODO: be a bit nicer on the comparison here. Strings as keys aren't great, but I want the flexibility to add non-standard recipes | ||
if recipe not in self.recipes.keys(): | ||
print(f"Unable to find the specified recipe. Available Recipes: {self.recipes.keys()}") | ||
return | ||
required_bottles = set(self.recipes[recipe].keys()) | ||
if not required_bottles.issubset(set(self.bottles)): | ||
print('Recipe requires an ingredient that is not loaded into the drink machine') | ||
print(f'Recipe requires: {required_bottles}') | ||
print(f'Available: {self.bottles}') | ||
return | ||
|
||
ingredients = self.recipes[recipe] | ||
for bottle, amount in ingredients.items(): | ||
ep = self.bottles[bottle] | ||
time = amount.time() | ||
await self.dev_ctrl.SendCommand(nodeid=self.node_id, endpoint=ep, | ||
payload=Clusters.ValveConfigurationAndControl.Commands.Open(openDuration=time)) | ||
|
||
async def prime(self, endpoint: int): | ||
await self.dev_ctrl.SendCommand(nodeid=self.node_id, endpoint=endpoint, | ||
payload=Clusters.ValveConfigurationAndControl.Commands.Open(openDuration=NullValue)) | ||
|
||
async def stop(self, endpoint: int): | ||
await self.dev_ctrl.SendCommand(nodeid=self.node_id, endpoint=endpoint, | ||
payload=Clusters.ValveConfigurationAndControl.Commands.Close()) |
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,25 @@ | ||
# Copyright (c) 2020 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("//build_overrides/build.gni") | ||
|
||
# The location of the build configuration file. | ||
buildconfig = "${build_root}/config/BUILDCONFIG.gn" | ||
|
||
# CHIP uses angle bracket includes. | ||
check_system_includes = true | ||
|
||
default_args = { | ||
import("//args.gni") | ||
} |
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,55 @@ | ||
# 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("//build_overrides/chip.gni") | ||
|
||
import("${chip_root}/build/chip/tools.gni") | ||
import("${chip_root}/src/app/common_flags.gni") | ||
|
||
assert(chip_build_tools) | ||
|
||
import("${chip_root}/examples/common/pigweed/pigweed_rpcs.gni") | ||
|
||
config("includes") { | ||
include_dirs = [ | ||
".", | ||
"include", | ||
] | ||
} | ||
|
||
executable("valve-app") { | ||
sources = [ | ||
"include/CHIPProjectAppConfig.h", | ||
"main.cpp", | ||
] | ||
|
||
deps = [ | ||
"${chip_root}/examples/platform/linux:app-main", | ||
"${chip_root}/examples/valve/valve-common", | ||
"${chip_root}/src/lib", | ||
] | ||
|
||
cflags = [ "-Wconversion" ] | ||
|
||
include_dirs = [ "include" ] | ||
output_dir = root_out_dir | ||
} | ||
|
||
group("linux") { | ||
deps = [ ":valve-app" ] | ||
} | ||
|
||
group("default") { | ||
deps = [ ":linux" ] | ||
} |
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,25 @@ | ||
# 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("//build_overrides/chip.gni") | ||
|
||
import("${chip_root}/config/standalone/args.gni") | ||
|
||
chip_device_project_config_include = "<CHIPProjectAppConfig.h>" | ||
chip_project_config_include = "<CHIPProjectAppConfig.h>" | ||
chip_system_project_config_include = "<SystemProjectConfig.h>" | ||
|
||
chip_project_config_include_dirs = | ||
[ "${chip_root}/examples/air-purifier-app/linux/include" ] | ||
chip_project_config_include_dirs += [ "${chip_root}/config/standalone" ] |
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 @@ | ||
../../build_overrides |
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,38 @@ | ||
/* | ||
* | ||
* Copyright (c) 2023 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. | ||
*/ | ||
|
||
#pragma once | ||
|
||
// include the CHIPProjectConfig from config/standalone | ||
#include <CHIPProjectConfig.h> | ||
|
||
#define CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY 0 | ||
|
||
#define CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY_CLIENT 0 | ||
|
||
#define CHIP_DEVICE_CONFIG_ENABLE_EXTENDED_DISCOVERY 1 | ||
|
||
#define CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONABLE_DEVICE_TYPE 1 | ||
|
||
#define CHIP_DEVICE_CONFIG_DEVICE_TYPE 0x0042 // Water valve | ||
|
||
#define CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONABLE_DEVICE_NAME 1 | ||
|
||
#define CHIP_DEVICE_ENABLE_PORT_PARAMS 1 | ||
|
||
#define CHIP_DEVICE_CONFIG_DEVICE_NAME "DISCO Drinks" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.