Skip to content

Commit

Permalink
controller now tested
Browse files Browse the repository at this point in the history
  • Loading branch information
cecille committed Sep 30, 2024
1 parent 3e30568 commit b994417
Show file tree
Hide file tree
Showing 11 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,21 @@ 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


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}
Expand All @@ -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'''
Expand All @@ -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
Expand All @@ -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]
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ class PrintOnlyDelegate : public NonLevelControlDelegate
PrintOnlyDelegate(EndpointId endpoint) : mEndpoint(endpoint) {}
CHIP_ERROR HandleOpenValve(ValveStateEnum & currentState, BitMask<ValveFaultBitmap> & 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;
}
ValveStateEnum GetCurrentValveState() override { return state; }
CHIP_ERROR HandleCloseValve(ValveStateEnum & currentState, BitMask<ValveFaultBitmap> & 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;
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit b994417

Please sign in to comment.