Skip to content

Commit

Permalink
Fix #520 -- bug where 0-step status transition had max_int length
Browse files Browse the repository at this point in the history
  • Loading branch information
sidoh committed Sep 18, 2019
1 parent 8529d7a commit e92c643
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/Transitions/FieldTransition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@
#include <algorithm>

FieldTransition::Builder::Builder(size_t id, const BulbId& bulbId, TransitionFn callback, GroupStateField field, uint16_t start, uint16_t end)
: Transition::Builder(id, bulbId, callback, std::ceil(static_cast<int16_t>(end) - start))
: Transition::Builder(
id,
bulbId,
callback,
max(
static_cast<size_t>(1),
static_cast<size_t>(std::ceil(static_cast<int16_t>(end) - start))
)
)
, stepSize(0)
, field(field)
, start(start)
Expand Down
1 change: 1 addition & 0 deletions lib/Transitions/Transition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Transition::Builder& Transition::Builder::setDurationAwarePeriod(size_t period,
} else {
setPeriod(period);
}
return *this;
}

size_t Transition::Builder::getNumPeriods() const {
Expand Down
14 changes: 14 additions & 0 deletions test/remote/spec/transition_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,20 @@
end

context 'status transition' do
it 'should turn off even if starting brightness is 0' do
@client.patch_state({status: 'ON', brightness: 0}, @id_params)
seen_off = false

@mqtt_client.on_update(@id_params) do |id, message|
seen_off = (message['state'] == 'OFF')
end

@client.patch_state({status: "OFF", transition: 1}, @id_params)
@mqtt_client.wait_for_listeners

expect(seen_off).to eq(true)
end

it 'should transition from off -> on' do
seen_updates = {}
@client.patch_state({status: 'OFF'}, @id_params)
Expand Down

0 comments on commit e92c643

Please sign in to comment.