From b99441764b3be364333a68dfa99c537cad4f0579 Mon Sep 17 00:00:00 2001 From: cecille Date: Mon, 30 Sep 2024 17:07:45 -0400 Subject: [PATCH] controller now tested --- .../{valve-app => valve}/controller/__init__.py | 14 +++++++++----- examples/{valve-app => valve}/linux/.gn | 0 examples/{valve-app => valve}/linux/BUILD.gn | 2 +- examples/{valve-app => valve}/linux/args.gni | 0 .../{valve-app => valve}/linux/build_overrides | 0 .../linux/include/CHIPProjectAppConfig.h | 0 examples/{valve-app => valve}/linux/main.cpp | 4 ++-- .../linux/third_party/connectedhomeip | 0 .../{valve-app => valve}/valve-common/BUILD.gn | 0 .../valve-common/valve-app.matter | 0 .../valve-common/valve-app.zap | 0 11 files changed, 12 insertions(+), 8 deletions(-) rename examples/{valve-app => valve}/controller/__init__.py (90%) rename examples/{valve-app => valve}/linux/.gn (100%) rename examples/{valve-app => valve}/linux/BUILD.gn (96%) rename examples/{valve-app => valve}/linux/args.gni (100%) rename examples/{valve-app => valve}/linux/build_overrides (100%) rename examples/{valve-app => valve}/linux/include/CHIPProjectAppConfig.h (100%) rename examples/{valve-app => valve}/linux/main.cpp (97%) rename examples/{valve-app => valve}/linux/third_party/connectedhomeip (100%) rename examples/{valve-app => valve}/valve-common/BUILD.gn (100%) rename examples/{valve-app => valve}/valve-common/valve-app.matter (100%) rename examples/{valve-app => valve}/valve-common/valve-app.zap (100%) diff --git a/examples/valve-app/controller/__init__.py b/examples/valve/controller/__init__.py similarity index 90% rename from examples/valve-app/controller/__init__.py rename to examples/valve/controller/__init__.py index 1d5a9a756de9ab..7d76b665aa0e35 100644 --- a/examples/valve-app/controller/__init__.py +++ b/examples/valve/controller/__init__.py @@ -11,14 +11,13 @@ class Bottle(StrEnum): kSourMix = "sour mix" kSimpleSyrup = "simple syrup", -# One once == approx 12s. - class Oz: def __init__(self, oz: float): self.oz = oz def time(self): + # One oz == approx 12s. return self.oz * 12 @@ -26,7 +25,7 @@ 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? + # 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} @@ -37,6 +36,8 @@ def __init__(self, devCtrl: ChipDeviceCtrl, node_id: int): 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''' @@ -45,7 +46,10 @@ def set_bottle_names(self, bottles: dict[Bottle, int]) -> bool: self.bottles = bottles def get_bottle_names(self): - return self.Bottle + 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 @@ -60,7 +64,7 @@ async def dispense(self, recipe: str): 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'Availble: {self.bottles}') + print(f'Available: {self.bottles}') return ingredients = self.recipes[recipe] diff --git a/examples/valve-app/linux/.gn b/examples/valve/linux/.gn similarity index 100% rename from examples/valve-app/linux/.gn rename to examples/valve/linux/.gn diff --git a/examples/valve-app/linux/BUILD.gn b/examples/valve/linux/BUILD.gn similarity index 96% rename from examples/valve-app/linux/BUILD.gn rename to examples/valve/linux/BUILD.gn index 86ea7a3900e210..d4a43214538098 100644 --- a/examples/valve-app/linux/BUILD.gn +++ b/examples/valve/linux/BUILD.gn @@ -36,7 +36,7 @@ executable("valve-app") { deps = [ "${chip_root}/examples/platform/linux:app-main", - "${chip_root}/examples/valve-app/valve-common", + "${chip_root}/examples/valve/valve-common", "${chip_root}/src/lib", ] diff --git a/examples/valve-app/linux/args.gni b/examples/valve/linux/args.gni similarity index 100% rename from examples/valve-app/linux/args.gni rename to examples/valve/linux/args.gni diff --git a/examples/valve-app/linux/build_overrides b/examples/valve/linux/build_overrides similarity index 100% rename from examples/valve-app/linux/build_overrides rename to examples/valve/linux/build_overrides diff --git a/examples/valve-app/linux/include/CHIPProjectAppConfig.h b/examples/valve/linux/include/CHIPProjectAppConfig.h similarity index 100% rename from examples/valve-app/linux/include/CHIPProjectAppConfig.h rename to examples/valve/linux/include/CHIPProjectAppConfig.h diff --git a/examples/valve-app/linux/main.cpp b/examples/valve/linux/main.cpp similarity index 97% rename from examples/valve-app/linux/main.cpp rename to examples/valve/linux/main.cpp index d86f65ca1d5e43..83df6e1d7d746e 100644 --- a/examples/valve-app/linux/main.cpp +++ b/examples/valve/linux/main.cpp @@ -35,7 +35,7 @@ class PrintOnlyDelegate : public NonLevelControlDelegate PrintOnlyDelegate(EndpointId endpoint) : mEndpoint(endpoint) {} CHIP_ERROR HandleOpenValve(ValveStateEnum & currentState, BitMask & valveFault) override { - ChipLogProgress(NotSpecified, "VALVE IS OPENING on endpoint %u!!!!!", mEndpoint); + ChipLogError(NotSpecified, "\n\nVALVE IS OPENING on endpoint %u!!!!!\n\n", mEndpoint); state = ValveStateEnum::kOpen; currentState = state; return CHIP_NO_ERROR; @@ -43,7 +43,7 @@ class PrintOnlyDelegate : public NonLevelControlDelegate ValveStateEnum GetCurrentValveState() override { return state; } CHIP_ERROR HandleCloseValve(ValveStateEnum & currentState, BitMask & valveFault) override { - ChipLogProgress(NotSpecified, "VALVE IS CLOSING on endpoint %u!!!!!", mEndpoint); + ChipLogError(NotSpecified, "\n\nVALVE IS CLOSING on endpoint %u!!!!!\n\n", mEndpoint); state = ValveStateEnum::kClosed; currentState = state; return CHIP_NO_ERROR; diff --git a/examples/valve-app/linux/third_party/connectedhomeip b/examples/valve/linux/third_party/connectedhomeip similarity index 100% rename from examples/valve-app/linux/third_party/connectedhomeip rename to examples/valve/linux/third_party/connectedhomeip diff --git a/examples/valve-app/valve-common/BUILD.gn b/examples/valve/valve-common/BUILD.gn similarity index 100% rename from examples/valve-app/valve-common/BUILD.gn rename to examples/valve/valve-common/BUILD.gn diff --git a/examples/valve-app/valve-common/valve-app.matter b/examples/valve/valve-common/valve-app.matter similarity index 100% rename from examples/valve-app/valve-common/valve-app.matter rename to examples/valve/valve-common/valve-app.matter diff --git a/examples/valve-app/valve-common/valve-app.zap b/examples/valve/valve-common/valve-app.zap similarity index 100% rename from examples/valve-app/valve-common/valve-app.zap rename to examples/valve/valve-common/valve-app.zap