Skip to content

Commit 5b230c4

Browse files
committed
Merge branch 'dev': 1.8.4
2 parents 7657c5f + e453d98 commit 5b230c4

4 files changed

Lines changed: 42 additions & 22 deletions

File tree

lib/MiLight/FUT089PacketFormatter.cpp

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,22 @@ void FUT089PacketFormatter::updateColorRaw(uint8_t value) {
3535
void FUT089PacketFormatter::updateTemperature(uint8_t value) {
3636
// look up our current mode
3737
const GroupState* ourState = this->stateStore->get(this->deviceId, this->groupId, REMOTE_TYPE_FUT089);
38-
BulbMode originalBulbMode = ourState->getBulbMode();
39-
40-
// are we already in white? If not, change to white
41-
if (originalBulbMode != BulbMode::BULB_MODE_WHITE) {
42-
updateColorWhite();
38+
BulbMode originalBulbMode;
39+
40+
if (ourState != NULL) {
41+
originalBulbMode = ourState->getBulbMode();
42+
43+
// are we already in white? If not, change to white
44+
if (originalBulbMode != BulbMode::BULB_MODE_WHITE) {
45+
updateColorWhite();
46+
}
4347
}
4448

4549
// now make the temperature change
4650
command(FUT089_KELVIN, 100 - value);
4751

4852
// and return to our original mode
49-
if ((settings->enableAutomaticModeSwitching) && (originalBulbMode != BulbMode::BULB_MODE_WHITE)) {
53+
if (ourState != NULL && (settings->enableAutomaticModeSwitching) && (originalBulbMode != BulbMode::BULB_MODE_WHITE)) {
5054
switchMode(*ourState, originalBulbMode);
5155
}
5256
}
@@ -58,18 +62,22 @@ void FUT089PacketFormatter::updateTemperature(uint8_t value) {
5862
void FUT089PacketFormatter::updateSaturation(uint8_t value) {
5963
// look up our current mode
6064
const GroupState* ourState = this->stateStore->get(this->deviceId, this->groupId, REMOTE_TYPE_FUT089);
61-
BulbMode originalBulbMode = ourState->getBulbMode();
65+
BulbMode originalBulbMode;
66+
67+
if (ourState != NULL) {
68+
originalBulbMode = ourState->getBulbMode();
69+
}
6270

6371
// are we already in color? If not, we need to flip modes
64-
if ((settings->enableAutomaticModeSwitching) && (originalBulbMode != BulbMode::BULB_MODE_COLOR)) {
72+
if (ourState != NULL && (settings->enableAutomaticModeSwitching) && (originalBulbMode != BulbMode::BULB_MODE_COLOR)) {
6573
updateHue(ourState->getHue());
6674
}
6775

6876
// now make the saturation change
6977
command(FUT089_SATURATION, 100 - value);
7078

7179
// and revert back if necessary
72-
if ((settings->enableAutomaticModeSwitching) && (originalBulbMode != BulbMode::BULB_MODE_COLOR)) {
80+
if (ourState != NULL && (settings->enableAutomaticModeSwitching) && (originalBulbMode != BulbMode::BULB_MODE_COLOR)) {
7381
switchMode(*ourState, originalBulbMode);
7482
}
7583
}

lib/MiLight/RgbCctPacketFormatter.cpp

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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) {
6366
void 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

8291
void 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);

lib/MiLight/RgbPacketFormatter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ void RgbPacketFormatter::updateColorRaw(uint8_t value) {
4848

4949
void RgbPacketFormatter::updateBrightness(uint8_t value) {
5050
const GroupState* state = this->stateStore->get(deviceId, groupId, MiLightRemoteType::REMOTE_TYPE_RGB);
51-
int8_t knownValue = state->isSetBrightness() ? state->getBrightness() : -1;
51+
int8_t knownValue = (state != NULL && state->isSetBrightness()) ? state->getBrightness() : -1;
5252

5353
valueByStepFunction(
5454
&PacketFormatter::increaseBrightness,

lib/MiLight/RgbwPacketFormatter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ void RgbwPacketFormatter::previousMode() {
4444

4545
uint8_t RgbwPacketFormatter::currentMode() {
4646
const GroupState* state = stateStore->get(deviceId, groupId, REMOTE_TYPE_RGBW);
47-
return state->getMode();
47+
return state != NULL ? state->getMode() : 0;
4848
}
4949

5050
void RgbwPacketFormatter::updateMode(uint8_t mode) {

0 commit comments

Comments
 (0)