@@ -47,14 +47,17 @@ void RgbCctPacketFormatter::updateTemperature(uint8_t value) {
4747 // is lost. So lookup our current bulb mode, and if needed, reset the hue/mode after
4848 // changing the temperature
4949 const GroupState* ourState = this ->stateStore ->get (this ->deviceId , this ->groupId , REMOTE_TYPE_RGB_CCT);
50- BulbMode originalBulbMode = ourState->getBulbMode ();
5150
5251 // now make the temperature change
5352 command (RGB_CCT_KELVIN, cmdValue);
5453
5554 // and return to our original mode
56- if ((settings->enableAutomaticModeSwitching ) && (originalBulbMode != BulbMode::BULB_MODE_WHITE)) {
57- switchMode (*ourState, originalBulbMode);
55+ if (ourState != NULL ) {
56+ BulbMode originalBulbMode = ourState->getBulbMode ();
57+
58+ if ((settings->enableAutomaticModeSwitching ) && (originalBulbMode != BulbMode::BULB_MODE_WHITE)) {
59+ switchMode (*ourState, originalBulbMode);
60+ }
5861 }
5962}
6063
@@ -63,27 +66,36 @@ void RgbCctPacketFormatter::updateTemperature(uint8_t value) {
6366void RgbCctPacketFormatter::updateSaturation (uint8_t value) {
6467 // look up our current mode
6568 const GroupState* ourState = this ->stateStore ->get (this ->deviceId , this ->groupId , REMOTE_TYPE_RGB_CCT);
66- BulbMode originalBulbMode = ourState->getBulbMode ();
67-
68- // are we already in white? If not, change to white
69- if ((settings->enableAutomaticModeSwitching ) && (originalBulbMode != BulbMode::BULB_MODE_COLOR)) {
70- updateHue (ourState->getHue ());
69+ BulbMode originalBulbMode;
70+
71+ if (ourState != NULL ) {
72+ originalBulbMode = ourState->getBulbMode ();
73+
74+ // are we already in white? If not, change to white
75+ if ((settings->enableAutomaticModeSwitching ) && (originalBulbMode != BulbMode::BULB_MODE_COLOR)) {
76+ updateHue (ourState->getHue ());
77+ }
7178 }
7279
7380 // now make the saturation change
7481 uint8_t remapped = value + RGB_CCT_SATURATION_OFFSET;
7582 command (RGB_CCT_SATURATION, remapped);
7683
77- if ((settings->enableAutomaticModeSwitching ) && (originalBulbMode != BulbMode::BULB_MODE_COLOR)) {
78- switchMode (*ourState, originalBulbMode);
84+ if (ourState != NULL ) {
85+ if ((settings->enableAutomaticModeSwitching ) && (originalBulbMode != BulbMode::BULB_MODE_COLOR)) {
86+ switchMode (*ourState, originalBulbMode);
87+ }
7988 }
8089}
8190
8291void RgbCctPacketFormatter::updateColorWhite () {
8392 // there is no direct white command, so let's look up our prior temperature and set that, which
8493 // causes the bulb to go white
8594 const GroupState* ourState = this ->stateStore ->get (this ->deviceId , this ->groupId , REMOTE_TYPE_RGB_CCT);
86- uint8_t value = V2PacketFormatter::tov2scale (ourState->getKelvin (), RGB_CCT_KELVIN_REMOTE_END, 2 );
95+ uint8_t value =
96+ ourState == NULL
97+ ? 0
98+ : V2PacketFormatter::tov2scale (ourState->getKelvin (), RGB_CCT_KELVIN_REMOTE_END, 2 );
8799
88100 // issue command to set kelvin to prior value, which will drive to white
89101 command (RGB_CCT_KELVIN, value);
0 commit comments