Skip to content

Commit

Permalink
fix(stepper): previous direction
Browse files Browse the repository at this point in the history
It changes now the previous direction when calling on_min and on_full
  • Loading branch information
xaviml committed Feb 18, 2020
1 parent 016f672 commit 905f0b7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions apps/controllerx/core/type/light_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,14 @@ async def set_value(self, attribute, fraction):

@action
async def on_full(self, attribute):
stepper = self.manual_steppers[attribute]
stepper.previous_direction = Stepper.UP
await self.set_value(attribute, 1)

@action
async def on_min(self, attribute):
stepper = self.manual_steppers[attribute]
stepper.previous_direction = Stepper.DOWN
await self.set_value(attribute, 0)

async def get_attribute(self, attribute):
Expand Down
12 changes: 12 additions & 0 deletions tests/core/type/light_controller_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,15 @@ async def test_on_full(sut, mocker):
max_ = 10
on_patch = mocker.patch.object(sut, "on")
stepper = MinMaxStepper(1, max_, 10)
stepper.previous_direction = Stepper.DOWN
sut.manual_steppers = {attribute: stepper}

# SUT
await sut.on_full(attribute)

# Checks
on_patch.assert_called_once_with(**{attribute: max_})
assert stepper.previous_direction == Stepper.UP


@pytest.mark.asyncio
Expand All @@ -239,9 +245,15 @@ async def test_on_min(sut, mocker):
min_ = 1
on_patch = mocker.patch.object(sut, "on")
stepper = MinMaxStepper(min_, 10, 10)
stepper.previous_direction = Stepper.UP
sut.manual_steppers = {attribute: stepper}

# SUT
await sut.on_min(attribute)

# Checks
on_patch.assert_called_once_with(**{attribute: min_})
assert stepper.previous_direction == Stepper.DOWN


@pytest.mark.parametrize(
Expand Down

0 comments on commit 905f0b7

Please sign in to comment.