Commit 77148179cae3017cbd683cce61462620c7328b6c

Authored by Jojo-1000
Committed by Moritz Wirger
1 parent b4e3087b

Change parsing behavior for unknown light types:

No longer throw exception, instead set type to unknown.
Add separate color types for other gamut.
include/hueplusplus/Light.h
... ... @@ -49,7 +49,9 @@ enum class ColorType
49 49 TEMPERATURE, //!< light has color temperature control
50 50 GAMUT_A_TEMPERATURE, //!< light uses Gamut A and has color temperature control
51 51 GAMUT_B_TEMPERATURE, //!< light uses Gamut B and has color temperature control
52   - GAMUT_C_TEMPERATURE //!< light uses Gamut C and has color temperature control
  52 + GAMUT_C_TEMPERATURE, //!< light uses Gamut C and has color temperature control
  53 + GAMUT_OTHER, //!< light uses capabilities to specify a different gamut
  54 + GAMUT_OTHER_TEMPERATURE //!< light uses capabilities to specify a different gamut and has color temperature control
53 55 };
54 56  
55 57 //! \brief Class for Hue Light fixtures
... ...
src/HueDeviceTypes.cpp
... ... @@ -136,7 +136,7 @@ ColorType LightFactory::getColorType(const nlohmann::json&amp; lightState, bool hasC
136 136 else
137 137 {
138 138 // Only other type is "Other" which does not have an enum value
139   - return ColorType::UNDEFINED;
  139 + return hasCt ? ColorType::GAMUT_OTHER_TEMPERATURE : ColorType::GAMUT_OTHER;
140 140 }
141 141 }
142 142 else
... ... @@ -155,8 +155,13 @@ ColorType LightFactory::getColorType(const nlohmann::json&amp; lightState, bool hasC
155 155 {
156 156 return hasCt ? ColorType::GAMUT_C_TEMPERATURE : ColorType::GAMUT_C;
157 157 }
158   - std::cerr << "Could not determine Light color type:" << modelid << "!\n";
159   - throw HueException(CURRENT_FILE_INFO, "Could not determine Light color type!");
  158 + else
  159 + {
  160 + std::cerr << "Warning: Could not determine Light color type:" << modelid
  161 + << "!\n"
  162 + "Results may not be correct.\n";
  163 + return ColorType::UNDEFINED;
  164 + }
160 165 }
161 166 }
162 167 } // namespace hueplusplus
... ...
src/Light.cpp
... ... @@ -74,7 +74,9 @@ ColorGamut Light::getColorGamut() const
74 74 case ColorType::GAMUT_C:
75 75 case ColorType::GAMUT_C_TEMPERATURE:
76 76 return gamut::gamutC;
77   - default: {
  77 + case ColorType::UNDEFINED:
  78 + return gamut::maxGamut;
  79 + default: { // GAMUT_OTHER, GAMUT_OTHER_TEMPERATURE
78 80 const nlohmann::json& capabilitiesGamut
79 81 = utils::safeGetMember(state.getValue(), "capabilities", "control", "colorgamut");
80 82 if (capabilitiesGamut.is_array() && capabilitiesGamut.size() == 3)
... ...
test/test_LightFactory.cpp
... ... @@ -94,7 +94,7 @@ TEST(LightFactory, createLight_gamutCapabilities)
94 94 lightState["capabilities"]["control"]["colorgamuttype"] = "Other";
95 95  
96 96 test_light_1 = factory.createLight(lightState, 1);
97   - EXPECT_EQ(test_light_1.getColorType(), ColorType::UNDEFINED);
  97 + EXPECT_EQ(test_light_1.getColorType(), ColorType::GAMUT_OTHER);
98 98  
99 99 // With color temperature
100 100 lightState["type"] = "Extended color light";
... ... @@ -112,6 +112,11 @@ TEST(LightFactory, createLight_gamutCapabilities)
112 112  
113 113 test_light_1 = factory.createLight(lightState, 1);
114 114 EXPECT_EQ(test_light_1.getColorType(), ColorType::GAMUT_C_TEMPERATURE);
  115 +
  116 + lightState["capabilities"]["control"]["colorgamuttype"] = "Other";
  117 +
  118 + test_light_1 = factory.createLight(lightState, 1);
  119 + EXPECT_EQ(test_light_1.getColorType(), ColorType::GAMUT_OTHER_TEMPERATURE);
115 120 }
116 121  
117 122 TEST(LightFactory, createLight_gamutModelid)
... ... @@ -164,5 +169,6 @@ TEST(LightFactory, createLight_gamutModelid)
164 169  
165 170 // Unknown model
166 171 lightState["modelid"] = "Unknown model";
167   - EXPECT_THROW(factory.createLight(lightState, 1), HueException);
  172 + test_light_1 = factory.createLight(lightState, 1);
  173 + EXPECT_EQ(test_light_1.getColorType(), ColorType::UNDEFINED);
168 174 }
... ...