Browse Source

Fix night mode behavior under 1.9.0, add test (#440)

Chris Mullins 6 years ago
parent
commit
d18a4a40e4
2 changed files with 43 additions and 1 deletions
  1. 3 1
      lib/MiLightState/GroupState.cpp
  2. 40 0
      test/remote/spec/state_spec.rb

+ 3 - 1
lib/MiLightState/GroupState.cpp

@@ -549,7 +549,9 @@ bool GroupState::setMireds(uint16_t mireds) {
   return setKelvin(Units::miredsToWhiteVal(mireds, 100));
 }
 
-bool GroupState::isSetBulbMode() const { return state.fields._isSetBulbMode; }
+bool GroupState::isSetBulbMode() const {
+  return  (isSetNightMode() && isNightMode()) || state.fields._isSetBulbMode;
+}
 BulbMode GroupState::getBulbMode() const {
   // Night mode is a transient state.  When power is toggled, the bulb returns
   // to the state it was last in.  To handle this case, night mode state is

+ 40 - 0
test/remote/spec/state_spec.rb

@@ -33,6 +33,46 @@ RSpec.describe 'State' do
     end
   end
 
+  context 'night mode command' do
+    it 'should affect state when bulb is off' do
+      state = @client.patch_state({'command' => 'night_mode'}, @id_params)
+
+      expect(state['bulb_mode']).to eq('night')
+      expect(state['effect']).to    eq('night_mode')
+    end
+
+    it 'should affect state when bulb is on' do
+      @client.patch_state({'status' => 'ON'}, @id_params)
+      state = @client.patch_state({'command' => 'night_mode'}, @id_params)
+
+      expect(state['status']).to    eq('ON')
+      expect(state['bulb_mode']).to eq('night')
+      expect(state['effect']).to    eq('night_mode')
+    end
+
+    it 'should revert to previous mode when status is toggled' do
+      @client.patch_state({'status' => 'ON', 'kelvin' => 100}, @id_params)
+      state = @client.patch_state({'command' => 'night_mode'}, @id_params)
+
+      expect(state['effect']).to eq('night_mode')
+
+      state = @client.patch_state({'status' => 'OFF'}, @id_params)
+
+      expect(state['bulb_mode']).to eq('white')
+      expect(state['kelvin']).to    eq(100)
+
+      @client.patch_state({'status' => 'ON', 'hue' => 0}, @id_params)
+      state = @client.patch_state({'command' => 'night_mode'}, @id_params)
+
+      expect(state['effect']).to eq('night_mode')
+
+      state = @client.patch_state({'status' => 'OFF'}, @id_params)
+
+      expect(state['bulb_mode']).to eq('color')
+      expect(state['hue']).to       eq(0)
+    end
+  end
+
   context 'deleting' do
     it 'should support deleting state' do
       desired_state = {