From 77148179cae3017cbd683cce61462620c7328b6c Mon Sep 17 00:00:00 2001 From: Jojo-1000 <33495614+Jojo-1000@users.noreply.github.com> Date: Thu, 24 Sep 2020 20:44:55 +0200 Subject: [PATCH] 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 | 4 +++- src/HueDeviceTypes.cpp | 11 ++++++++--- src/Light.cpp | 4 +++- test/test_LightFactory.cpp | 10 ++++++++-- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/include/hueplusplus/Light.h b/include/hueplusplus/Light.h index aa6b201..1592ceb 100644 --- a/include/hueplusplus/Light.h +++ b/include/hueplusplus/Light.h @@ -49,7 +49,9 @@ enum class ColorType TEMPERATURE, //!< light has color temperature control GAMUT_A_TEMPERATURE, //!< light uses Gamut A and has color temperature control GAMUT_B_TEMPERATURE, //!< light uses Gamut B and has color temperature control - GAMUT_C_TEMPERATURE //!< light uses Gamut C and has color temperature control + GAMUT_C_TEMPERATURE, //!< light uses Gamut C and has color temperature control + GAMUT_OTHER, //!< light uses capabilities to specify a different gamut + GAMUT_OTHER_TEMPERATURE //!< light uses capabilities to specify a different gamut and has color temperature control }; //! \brief Class for Hue Light fixtures diff --git a/src/HueDeviceTypes.cpp b/src/HueDeviceTypes.cpp index c43e31e..462324d 100644 --- a/src/HueDeviceTypes.cpp +++ b/src/HueDeviceTypes.cpp @@ -136,7 +136,7 @@ ColorType LightFactory::getColorType(const nlohmann::json& lightState, bool hasC else { // Only other type is "Other" which does not have an enum value - return ColorType::UNDEFINED; + return hasCt ? ColorType::GAMUT_OTHER_TEMPERATURE : ColorType::GAMUT_OTHER; } } else @@ -155,8 +155,13 @@ ColorType LightFactory::getColorType(const nlohmann::json& lightState, bool hasC { return hasCt ? ColorType::GAMUT_C_TEMPERATURE : ColorType::GAMUT_C; } - std::cerr << "Could not determine Light color type:" << modelid << "!\n"; - throw HueException(CURRENT_FILE_INFO, "Could not determine Light color type!"); + else + { + std::cerr << "Warning: Could not determine Light color type:" << modelid + << "!\n" + "Results may not be correct.\n"; + return ColorType::UNDEFINED; + } } } } // namespace hueplusplus diff --git a/src/Light.cpp b/src/Light.cpp index a09e016..64cf296 100644 --- a/src/Light.cpp +++ b/src/Light.cpp @@ -74,7 +74,9 @@ ColorGamut Light::getColorGamut() const case ColorType::GAMUT_C: case ColorType::GAMUT_C_TEMPERATURE: return gamut::gamutC; - default: { + case ColorType::UNDEFINED: + return gamut::maxGamut; + default: { // GAMUT_OTHER, GAMUT_OTHER_TEMPERATURE const nlohmann::json& capabilitiesGamut = utils::safeGetMember(state.getValue(), "capabilities", "control", "colorgamut"); if (capabilitiesGamut.is_array() && capabilitiesGamut.size() == 3) diff --git a/test/test_LightFactory.cpp b/test/test_LightFactory.cpp index ec2009e..d42c8f6 100644 --- a/test/test_LightFactory.cpp +++ b/test/test_LightFactory.cpp @@ -94,7 +94,7 @@ TEST(LightFactory, createLight_gamutCapabilities) lightState["capabilities"]["control"]["colorgamuttype"] = "Other"; test_light_1 = factory.createLight(lightState, 1); - EXPECT_EQ(test_light_1.getColorType(), ColorType::UNDEFINED); + EXPECT_EQ(test_light_1.getColorType(), ColorType::GAMUT_OTHER); // With color temperature lightState["type"] = "Extended color light"; @@ -112,6 +112,11 @@ TEST(LightFactory, createLight_gamutCapabilities) test_light_1 = factory.createLight(lightState, 1); EXPECT_EQ(test_light_1.getColorType(), ColorType::GAMUT_C_TEMPERATURE); + + lightState["capabilities"]["control"]["colorgamuttype"] = "Other"; + + test_light_1 = factory.createLight(lightState, 1); + EXPECT_EQ(test_light_1.getColorType(), ColorType::GAMUT_OTHER_TEMPERATURE); } TEST(LightFactory, createLight_gamutModelid) @@ -164,5 +169,6 @@ TEST(LightFactory, createLight_gamutModelid) // Unknown model lightState["modelid"] = "Unknown model"; - EXPECT_THROW(factory.createLight(lightState, 1), HueException); + test_light_1 = factory.createLight(lightState, 1); + EXPECT_EQ(test_light_1.getColorType(), ColorType::UNDEFINED); } -- libgit2 0.21.4