From 74b51fb2c0d1ac063def640a6314f2fe27bcb121 Mon Sep 17 00:00:00 2001 From: Moritz Wirger Date: Sat, 13 Mar 2021 22:33:50 +0100 Subject: [PATCH] Fix naming convention --- README.md | 16 ++++++++-------- doc/markdown/Mainpage.md | 16 ++++++++-------- include/hueplusplus/Bridge.h | 24 ++++++++++++------------ include/hueplusplus/ColorHueStrategy.h | 4 ++-- include/hueplusplus/EntertainmentMode.h | 51 ++++++++++++++++++++++++++------------------------- include/hueplusplus/Light.h | 12 ++++++------ include/hueplusplus/SimpleColorHueStrategy.h | 6 +++--- src/Bridge.cpp | 34 +++++++++++++++++----------------- src/EntertainmentMode.cpp | 31 ++++++++++++++++--------------- src/Light.cpp | 11 +++++------ test/mocks/mock_Light.h | 8 ++++---- test/test_Bridge.cpp | 35 ++++++++++++++++++----------------- test/test_Light.cpp | 44 ++++++++++++++++++++++---------------------- test/test_LightFactory.cpp | 7 ++++--- test/test_Scene.cpp | 4 ++-- test/test_Sensor.cpp | 2 +- test/test_SensorImpls.cpp | 2 +- test/test_SimpleColorTemperatureStrategy.cpp | 5 ++--- 18 files changed, 157 insertions(+), 155 deletions(-) diff --git a/README.md b/README.md index 7d0baf5..c63fc31 100755 --- a/README.md +++ b/README.md @@ -26,12 +26,12 @@ A simple and easy to use library for Philips Hue Lights To start searching for a Hue Bridge you will need to choose an IHttpHandler and create one. The options are a "WinHttpHandler" (for windows) or a "LinHttpHandler" (for linux). Then create a BridgeFinder object with the handler. The handler is needed, because it tells the finder which functions to use to communicate with a bridge or your local network. -After that you can call FindBridges(), which will return a vector containing the ip and mac address of all found Bridges. +After that you can call findBridges(), which will return a vector containing the ip and mac address of all found Bridges. ```C++ // For windows use std::make_shared(); handler = std::make_shared(); hueplusplus::BridgeFinder finder(handler); -std::vector bridges = finder.FindBridges(); +std::vector bridges = finder.findBridges(); if (bridges.empty()) { std::cerr << "No bridges found\n"; @@ -42,15 +42,15 @@ if (bridges.empty()) ### Authenticate Bridges If you have found the Bridge you were looking for, you can then move on with the authentication process. -To get a new username from the Bridge (for now) you simply call GetBridge(bridges[\]), +To get a new username from the Bridge (for now) you simply call getBridge(bridges[\]), where index is your preferred Bridge from the part [Searching for Bridges](#searchingBridges). ```C++ -hueplusplus::Bridge bridge = finder.GetBridge(bridges[0]); +hueplusplus::Bridge bridge = finder.getBridge(bridges[0]); ``` If you on the other hand already have a username you can add your bridge like so ```C++ -finder.AddUsername(bridges[0].mac, ""); -hueplusplus::Bridge bridge = finder.GetBridge(bridges[0]); +finder.addUsername(bridges[0].mac, ""); +hueplusplus::Bridge bridge = finder.getBridge(bridges[0]); ``` If you do not want to use the BridgeFinder or you already know the ip and username of your bridge you have the option to create your own Bridge object. Here you will need to provide the ip address, the port number, a username and an HttpHandler @@ -74,12 +74,12 @@ std::vector lights = bridge.lights().getAll(); ``` If you now want to control a light, call a specific function of it. ```C++ -light1.On(); +light1.on(); light1.setBrightness(120); light1.alertHueSaturation(25500, 255); light1.setColorLoop(true); light1.setColorRGB(255, 128, 0); -lights[1].Off(); +lights[1].off(); lights.at(1).setColorHue(4562); ``` But keep in mind that some light types do not have all functions available. So you might call a diff --git a/doc/markdown/Mainpage.md b/doc/markdown/Mainpage.md index 5af8285..e738def 100644 --- a/doc/markdown/Mainpage.md +++ b/doc/markdown/Mainpage.md @@ -22,12 +22,12 @@ To start searching for a Hue Bridge you will need to choose an IHttpHandler and Then create a [BridgeFinder](@ref hueplusplus::BridgeFinder) object with the handler. The handler is needed, because it tells the finder which functions to use to communicate with a bridge or your local network. -After that you can call [FindBridges()](@ref hueplusplus::BridgeFinder::FindBridges), which will return a vector containing the ip and mac address of all found Bridges. +After that you can call [findBridges()](@ref hueplusplus::BridgeFinder::findBridges), which will return a vector containing the ip and mac address of all found Bridges. ```{.cpp} // For windows use std::make_shared(); handler = std::make_shared(); hueplusplus::BridgeFinder finder(handler); -std::vector bridges = finder.FindBridges(); +std::vector bridges = finder.findBridges(); if (bridges.empty()) { std::cerr << "No bridges found\n"; @@ -38,15 +38,15 @@ if (bridges.empty()) ### Authenticate Bridges If you have found the Bridge you were looking for, you can then move on with the authentication process. -To get a new username from the Bridge (for now) you simply call [GetBridge(bridges[\])](@ref hueplusplus::BridgeFinder::GetBridge), +To get a new username from the Bridge (for now) you simply call [getBridge(bridges[\])](@ref hueplusplus::BridgeFinder::getBridge), where index is your preferred Bridge from the part [Searching for Bridges](#searchingBridges). This requires the user to press the link button. ```{.cpp} -hueplusplus::Bridge bridge = finder.GetBridge(bridges[0]); +hueplusplus::Bridge bridge = finder.getBridge(bridges[0]); ``` If you on the other hand already have a username you can add your bridge like so ```{.cpp} -finder.AddUsername(bridges[0].mac, ""); -hueplusplus::Bridge bridge = finder.GetBridge(bridges[0]); +finder.addUsername(bridges[0].mac, ""); +hueplusplus::Bridge bridge = finder.getBridge(bridges[0]); ``` If you do not want to use the BridgeFinder or you already know the ip and username of your bridge you have the option to create your own Bridge object. Here you will need to provide the ip address, the port number, a username and an HttpHandler @@ -70,12 +70,12 @@ std::vector lights = bridge.lights().getAll(); ``` If you now want to control a light, call a specific function of it. ```{.cpp} -light1.On(); +light1.on(); light1.setBrightness(120); light1.alertHueSaturation(25500, 255); light1.setColorLoop(true); light1.setColorRGB(255, 128, 0); -lights[1].Off(); +lights[1].off(); lights.at(1).setColorHue(4562); ``` But keep in mind that some light types do not have all functions available. So you might call a diff --git a/include/hueplusplus/Bridge.h b/include/hueplusplus/Bridge.h index 1f77b0e..4a214fb 100644 --- a/include/hueplusplus/Bridge.h +++ b/include/hueplusplus/Bridge.h @@ -80,7 +80,7 @@ public: //! \return vector containing ip and mac of all found bridges //! \throws std::system_error when system or socket operations fail //! \throws HueException when response contained no body - std::vector FindBridges() const; + std::vector findBridges() const; //! \brief Gets a Hue bridge based on its identification //! @@ -91,31 +91,31 @@ public: //! \throws HueException when response contained no body or username could not be requested //! \throws HueAPIResponseException when response contains an error //! \throws nlohmann::json::parse_error when response could not be parsed - Bridge GetBridge(const BridgeIdentification& identification, bool sharedState = false); + Bridge getBridge(const BridgeIdentification& identification, bool sharedState = false); //! \brief Function that adds a username to the usernames map //! //! \param mac MAC address of Hue bridge //! \param username Username that is used to control the Hue bridge - void AddUsername(const std::string& mac, const std::string& username); + void addUsername(const std::string& mac, const std::string& username); //! \brief Function that adds a client key to the clientkeys map //! //! The client key is only needed for entertainment mode, otherwise it is optional. //! \param mac MAC address of Hue bridge //! \param clientkey Client key that is used to control the Hue bridge in entertainment mode - void AddClientKey(const std::string& mac, const std::string& clientkey); + void addClientKey(const std::string& mac, const std::string& clientkey); //! \brief Function that returns a map of mac addresses and usernames. //! - //! Note these should be saved at the end and re-loaded with \ref AddUsername + //! Note these should be saved at the end and re-loaded with \ref addUsername //! next time, so only one username is generated per bridge. \returns A map //! mapping mac address to username for every bridge - const std::map& GetAllUsernames() const; + const std::map& getAllUsernames() const; //! \brief Normalizes mac address to plain hex number. //! \returns \p input without separators and whitespace, in lower case. - static std::string NormalizeMac(std::string input); + static std::string normalizeMac(std::string input); private: //! \brief Parses mac address from description.xml @@ -123,12 +123,12 @@ private: //! \param description Content of description.xml file as returned by GET request. //! \returns Content of xml element \c serialNumber if description matches a Hue bridge, otherwise an empty //! string. - static std::string ParseDescription(const std::string& description); + static std::string parseDescription(const std::string& description); std::map usernames; //!< Maps all macs to usernames added by \ref - //!< BridgeFinder::AddUsername + //!< BridgeFinder::addUsername std::map clientkeys; //!< Maps all macs to clientkeys added by \ref - //!< BridgeFinder::AddClientKey + //!< BridgeFinder::addClientKey std::shared_ptr http_handler; }; @@ -184,12 +184,12 @@ public: //! \brief Function to set stream mode to active for entertainment mode //! //! \return bool - whether stream request was successful - bool StartStreaming(std::string group_identifier); + bool startStreaming(std::string group_identifier); //! \brief Function to set stream mode to active for entertainment mode //! //! \return bool - whether stream request was successful - bool StopStreaming(std::string group_identifier); + bool stopStreaming(std::string group_identifier); //! \brief Function to get the port of the hue bridge //! diff --git a/include/hueplusplus/ColorHueStrategy.h b/include/hueplusplus/ColorHueStrategy.h index 30304fb..2f4cbd4 100644 --- a/include/hueplusplus/ColorHueStrategy.h +++ b/include/hueplusplus/ColorHueStrategy.h @@ -79,8 +79,8 @@ public: //! through every color on the current hue and saturation settings. Notice //! that none of the setter functions check whether this feature is enabled //! and the colorloop can only be disabled with this function or by simply - //! calling Off()/OffNoRefresh() and then On()/OnNoRefresh(), so you could - //! alternatively call Off() and then use any of the setter functions. \param + //! calling off() and then on(), so you could + //! alternatively call off() and then use any of the setter functions. \param //! on Boolean to turn this feature on or off, true/1 for on and false/0 for //! off \param light A reference of the light virtual bool setColorLoop(bool on, Light& light) const = 0; diff --git a/include/hueplusplus/EntertainmentMode.h b/include/hueplusplus/EntertainmentMode.h index 1a0867c..586c2ca 100644 --- a/include/hueplusplus/EntertainmentMode.h +++ b/include/hueplusplus/EntertainmentMode.h @@ -2,6 +2,7 @@ \file EntertainmentMode.h Copyright Notice\n Copyright (C) 2020 Adam Honse - developer\n + Copyright (C) 2021 Moritz Wirger - developer\n This file is part of hueplusplus. @@ -35,42 +36,42 @@ struct TLSContext; class EntertainmentMode { public: - //! @brief Constructor + //! \brief Constructor //! - //! @param b Bridge reference - //! @param g Group to control in entertainment mode reference + //! \param b Bridge reference + //! \param g Group to control in entertainment mode reference EntertainmentMode(Bridge& b, Group& g); - //! @brief Destroy the Entertainment Mode object + //! \brief Destroy the Entertainment Mode object ~EntertainmentMode(); - //! @brief Connect and start streaming + //! \brief Connect and start streaming //! - //! @return true If conected and ready to receive commands - //! @return false If an error occured - bool Connect(); + //! \return true If conected and ready to receive commands + //! \return false If an error occured + bool connect(); - //! @brief Disconnect and stop streaming + //! \brief Disconnect and stop streaming //! - //! @return true If disconnected successfully - //! @return false If an error occurred - bool Disconnect(); + //! \return true If disconnected successfully + //! \return false If an error occurred + bool disconnect(); - //! @brief Set the color of the given light in RGB format + //! \brief Set the color of the given light in RGB format //! - //! @param light_index Light index inside the group - //! @param red Red color value (0-255) - //! @param green Green color value (0-255) - //! @param blue Blue color value (0-255) - //! @return true If light_index was valid - //! @return false If light_index was invalid - bool SetColorRGB(uint8_t light_index, uint8_t red, uint8_t green, uint8_t blue); - - //! @brief Update all set colors by @ref SetColorRGB + //! \param light_index Light index inside the group + //! \param red Red color value (0-255) + //! \param green Green color value (0-255) + //! \param blue Blue color value (0-255) + //! \return true If light_index was valid + //! \return false If light_index was invalid + bool setColorRGB(uint8_t light_index, uint8_t red, uint8_t green, uint8_t blue); + + //! \brief Update all set colors by \ref setColorRGB //! - //! @return true If all color values for all lights have ben written/sent - //! @return false If there was an error while writing - bool Update(); + //! \return true If all color values for all lights have ben written/sent + //! \return false If there was an error while writing + bool update(); protected: Bridge* bridge; //!< Associated bridge diff --git a/include/hueplusplus/Light.h b/include/hueplusplus/Light.h index b4822b5..aa6b201 100644 --- a/include/hueplusplus/Light.h +++ b/include/hueplusplus/Light.h @@ -95,7 +95,7 @@ public: //! \throws HueException when response contained no body //! \throws HueAPIResponseException when response contains an error //! \throws nlohmann::json::parse_error when response could not be parsed - virtual bool On(uint8_t transition = 4); + virtual bool on(uint8_t transition = 4); //! \brief Function that turns the light off. //! @@ -105,7 +105,7 @@ public: //! \throws HueException when response contained no body //! \throws HueAPIResponseException when response contains an error //! \throws nlohmann::json::parse_error when response could not be parsed - virtual bool Off(uint8_t transition = 4); + virtual bool off(uint8_t transition = 4); //! \brief Function to check whether a light is on or off //! @@ -145,13 +145,13 @@ public: //! //! \param kelvin Unsigned integer value in Kelvin //! \return Unsigned integer value in Mired - unsigned int KelvinToMired(unsigned int kelvin) const; + unsigned int kelvinToMired(unsigned int kelvin) const; //! \brief Const function that converts Mired to Kelvin. //! //! \param mired Unsigned integer value in Mired //! \return Unsigned integer value in Kelvin - unsigned int MiredToKelvin(unsigned int mired) const; + unsigned int miredToKelvin(unsigned int mired) const; //! \brief Function that sets the brightness of this light. //! @@ -524,8 +524,8 @@ public: //! colors on current hue and saturation levels. Notice that none of the //! setter functions check whether this feature is enabled and the colorloop //! can only be disabled with this function or by simply calling - //! Off()/OffNoRefresh() and then On()/OnNoRefresh(), so you could - //! alternatively call Off() and then use any of the setter functions. + //! off() and then on(), so you could + //! alternatively call off() and then use any of the setter functions. //! \param on bool that enables this feature when true and disables it when false //! \return Bool that is true on success //! \throws std::system_error when system or socket operations fail diff --git a/include/hueplusplus/SimpleColorHueStrategy.h b/include/hueplusplus/SimpleColorHueStrategy.h index 2117979..c9593c3 100644 --- a/include/hueplusplus/SimpleColorHueStrategy.h +++ b/include/hueplusplus/SimpleColorHueStrategy.h @@ -68,7 +68,7 @@ public: //! of 100ms, 4 = 400ms and should be seen as the default \param light A //! reference of the light bool setColorXY(const XYBrightness& xy, uint8_t transition, Light& light) const override; - + //! \brief Function for turning on/off the color loop feature of a light. //! //! Can be theoretically set for any light, but it only works for lights that @@ -76,8 +76,8 @@ public: //! through every color on the current hue and saturation settings. Notice //! that none of the setter functions check whether this feature is enabled //! and the colorloop can only be disabled with this function or by simply - //! calling Off()/OffNoRefresh() and then On()/OnNoRefresh(), so you could - //! alternatively call Off() and then use any of the setter functions. + //! calling off() and then on(), so you could + //! alternatively call off() and then use any of the setter functions. //! \param on Boolean to turn this feature on or off, true/1 for on and //! false/0 for off \param light A reference of the light bool setColorLoop(bool on, Light& light) const override; diff --git a/src/Bridge.cpp b/src/Bridge.cpp index fdf3b0d..07d8835 100644 --- a/src/Bridge.cpp +++ b/src/Bridge.cpp @@ -39,7 +39,7 @@ namespace hueplusplus { BridgeFinder::BridgeFinder(std::shared_ptr handler) : http_handler(std::move(handler)) { } -std::vector BridgeFinder::FindBridges() const +std::vector BridgeFinder::findBridges() const { UPnP uplug; std::vector> foundDevices = uplug.getDevices(http_handler); @@ -58,10 +58,10 @@ std::vector BridgeFinder::FindBridges() cons { std::string desc = http_handler->GETString("/description.xml", "application/xml", "", bridge.ip, bridge.port); - std::string mac = ParseDescription(desc); + std::string mac = parseDescription(desc); if (!mac.empty()) { - bridge.mac = NormalizeMac(mac); + bridge.mac = normalizeMac(mac); foundBridges.push_back(std::move(bridge)); } } @@ -74,9 +74,9 @@ std::vector BridgeFinder::FindBridges() cons return foundBridges; } -Bridge BridgeFinder::GetBridge(const BridgeIdentification& identification, bool sharedState) +Bridge BridgeFinder::getBridge(const BridgeIdentification& identification, bool sharedState) { - std::string normalizedMac = NormalizeMac(identification.mac); + std::string normalizedMac = normalizeMac(identification.mac); auto pos = usernames.find(normalizedMac); auto key = clientkeys.find(normalizedMac); if (pos != usernames.end()) @@ -92,35 +92,35 @@ Bridge BridgeFinder::GetBridge(const BridgeIdentification& identification, bool std::chrono::seconds(10), sharedState); } } - Bridge bridge(identification.ip, identification.port, "", http_handler, std::chrono::seconds(10), sharedState); + Bridge bridge(identification.ip, identification.port, "", http_handler, "", std::chrono::seconds(10), sharedState); bridge.requestUsername(); if (bridge.getUsername().empty()) { std::cerr << "Failed to request username for ip " << identification.ip << std::endl; throw HueException(CURRENT_FILE_INFO, "Failed to request username!"); } - AddUsername(normalizedMac, bridge.getUsername()); - AddClientKey(normalizedMac, bridge.getClientKey()); + addUsername(normalizedMac, bridge.getUsername()); + addClientKey(normalizedMac, bridge.getClientKey()); return bridge; } -void BridgeFinder::AddUsername(const std::string& mac, const std::string& username) +void BridgeFinder::addUsername(const std::string& mac, const std::string& username) { - usernames[NormalizeMac(mac)] = username; + usernames[normalizeMac(mac)] = username; } -void BridgeFinder::AddClientKey(const std::string& mac, const std::string& clientkey) +void BridgeFinder::addClientKey(const std::string& mac, const std::string& clientkey) { - clientkeys[NormalizeMac(mac)] = clientkey; + clientkeys[normalizeMac(mac)] = clientkey; } -const std::map& BridgeFinder::GetAllUsernames() const +const std::map& BridgeFinder::getAllUsernames() const { return usernames; } -std::string BridgeFinder::NormalizeMac(std::string input) +std::string BridgeFinder::normalizeMac(std::string input) { // Remove any non alphanumeric characters (e.g. ':' and whitespace) input.erase(std::remove_if(input.begin(), input.end(), [](char c) { return !std::isalnum(c, std::locale()); }), @@ -130,7 +130,7 @@ std::string BridgeFinder::NormalizeMac(std::string input) return input; } -std::string BridgeFinder::ParseDescription(const std::string& description) +std::string BridgeFinder::parseDescription(const std::string& description) { const char* model = "Philips hue bridge"; const char* serialBegin = ""; @@ -248,7 +248,7 @@ std::string Bridge::requestUsername() return username; } -bool Bridge::StartStreaming(std::string group_identifier) +bool Bridge::startStreaming(std::string group_identifier) { if (clientkey.empty()) { @@ -271,7 +271,7 @@ bool Bridge::StartStreaming(std::string group_identifier) return success == true; } -bool Bridge::StopStreaming(std::string group_identifier) +bool Bridge::stopStreaming(std::string group_identifier) { nlohmann::json request; diff --git a/src/EntertainmentMode.cpp b/src/EntertainmentMode.cpp index 0d381f9..ac1080c 100644 --- a/src/EntertainmentMode.cpp +++ b/src/EntertainmentMode.cpp @@ -2,6 +2,7 @@ \file EntertainmentMode.cpp Copyright Notice\n Copyright (C) 2020 Adam Honse - developer\n + Copyright (C) 2021 Moritz Wirger - developer\n This file is part of hueplusplus. @@ -45,7 +46,7 @@ struct TLSContext mbedtls_timing_delay_context timer; }; -std::vector HexToBytes(const std::string& hex) +std::vector hexToBytes(const std::string& hex) { std::vector bytes; @@ -65,7 +66,7 @@ EntertainmentMode::EntertainmentMode(Bridge& b, Group& g) /*-------------------------------------------------*\ | Signal the bridge to start streaming | \*-------------------------------------------------*/ - bridge->StartStreaming(std::to_string(group->getId())); + bridge->startStreaming(std::to_string(group->getId())); /*-------------------------------------------------*\ | Get the number of lights from the group | @@ -139,13 +140,13 @@ EntertainmentMode::~EntertainmentMode() mbedtls_net_free(&tls_context->server_fd); } -bool EntertainmentMode::Connect() +bool EntertainmentMode::connect() { /*-------------------------------------------------*\ | Signal the bridge to start streaming | | If successful, connect to the UDP port | \*-------------------------------------------------*/ - if (bridge->StartStreaming(std::to_string(group->getId()))) + if (bridge->startStreaming(std::to_string(group->getId()))) { /*-------------------------------------------------*\ | Connect to the Hue bridge UDP server | @@ -159,7 +160,7 @@ bool EntertainmentMode::Connect() if (ret != 0) { mbedtls_ssl_close_notify(&tls_context->ssl); - bridge->StopStreaming(std::to_string(group->getId())); + bridge->stopStreaming(std::to_string(group->getId())); return false; } @@ -175,7 +176,7 @@ bool EntertainmentMode::Connect() if (ret != 0) { mbedtls_ssl_close_notify(&tls_context->ssl); - bridge->StopStreaming(std::to_string(group->getId())); + bridge->stopStreaming(std::to_string(group->getId())); return false; } @@ -186,7 +187,7 @@ bool EntertainmentMode::Connect() /*-------------------------------------------------*\ | Convert client key to binary array | \*-------------------------------------------------*/ - std::vector psk_binary = HexToBytes(bridge->getClientKey()); + std::vector psk_binary = hexToBytes(bridge->getClientKey()); /*-------------------------------------------------*\ | Configure SSL pre-shared key and identity | @@ -202,7 +203,7 @@ bool EntertainmentMode::Connect() if (ret != 0) { mbedtls_ssl_close_notify(&tls_context->ssl); - bridge->StopStreaming(std::to_string(group->getId())); + bridge->stopStreaming(std::to_string(group->getId())); return false; } @@ -217,7 +218,7 @@ bool EntertainmentMode::Connect() if (ret != 0) { mbedtls_ssl_close_notify(&tls_context->ssl); - bridge->StopStreaming(std::to_string(group->getId())); + bridge->stopStreaming(std::to_string(group->getId())); return false; } @@ -229,7 +230,7 @@ bool EntertainmentMode::Connect() if (ret != 0) { mbedtls_ssl_close_notify(&tls_context->ssl); - bridge->StopStreaming(std::to_string(group->getId())); + bridge->stopStreaming(std::to_string(group->getId())); return false; } @@ -252,7 +253,7 @@ bool EntertainmentMode::Connect() if (ret != 0) { mbedtls_ssl_close_notify(&tls_context->ssl); - bridge->StopStreaming(std::to_string(group->getId())); + bridge->stopStreaming(std::to_string(group->getId())); return false; } @@ -264,13 +265,13 @@ bool EntertainmentMode::Connect() } } -bool EntertainmentMode::Disconnect() +bool EntertainmentMode::disconnect() { mbedtls_ssl_close_notify(&tls_context->ssl); - return bridge->StopStreaming(std::to_string(group->getId())); + return bridge->stopStreaming(std::to_string(group->getId())); } -bool EntertainmentMode::SetColorRGB(uint8_t light_index, uint8_t red, uint8_t green, uint8_t blue) +bool EntertainmentMode::setColorRGB(uint8_t light_index, uint8_t red, uint8_t green, uint8_t blue) { if (light_index < entertainment_num_lights) { @@ -291,7 +292,7 @@ bool EntertainmentMode::SetColorRGB(uint8_t light_index, uint8_t red, uint8_t gr } } -bool EntertainmentMode::Update() +bool EntertainmentMode::update() { int ret; unsigned int total = 0; diff --git a/src/Light.cpp b/src/Light.cpp index 353d06d..a09e016 100644 --- a/src/Light.cpp +++ b/src/Light.cpp @@ -20,24 +20,23 @@ along with hueplusplus. If not, see . **/ -#include "hueplusplus/Light.h" - #include #include #include #include "hueplusplus/HueExceptionMacro.h" +#include "hueplusplus/Light.h" #include "hueplusplus/Utils.h" #include "json/json.hpp" namespace hueplusplus { -bool Light::On(uint8_t transition) +bool Light::on(uint8_t transition) { return transaction().setOn(true).setTransition(transition).commit(); } -bool Light::Off(uint8_t transition) +bool Light::off(uint8_t transition) { return transaction().setOn(false).setTransition(transition).commit(); } @@ -91,12 +90,12 @@ ColorGamut Light::getColorGamut() const } } -unsigned int Light::KelvinToMired(unsigned int kelvin) const +unsigned int Light::kelvinToMired(unsigned int kelvin) const { return int(0.5f + (1000000 / kelvin)); } -unsigned int Light::MiredToKelvin(unsigned int mired) const +unsigned int Light::miredToKelvin(unsigned int mired) const { return int(0.5f + (1000000 / mired)); } diff --git a/test/mocks/mock_Light.h b/test/mocks/mock_Light.h index ca8b01e..a44656b 100644 --- a/test/mocks/mock_Light.h +++ b/test/mocks/mock_Light.h @@ -38,16 +38,16 @@ class MockLight : public hueplusplus::Light public: MockLight(std::shared_ptr handler) : Light(1, hueplusplus::HueCommandAPI(getBridgeIp(), getBridgePort(), getBridgeUsername(), handler), nullptr, - nullptr, nullptr, std::chrono::steady_clock::duration::max(), nullptr) + nullptr, nullptr, std::chrono::steady_clock::duration::max(), nullptr) { // Set refresh duration to max, so random refreshes do not hinder the test setups } nlohmann::json& getState() { return state.getValue(); } - MOCK_METHOD1(On, bool(uint8_t transition)); + MOCK_METHOD1(on, bool(uint8_t transition)); - MOCK_METHOD1(Off, bool(uint8_t transition)); + MOCK_METHOD1(off, bool(uint8_t transition)); MOCK_METHOD0(isOn, bool()); @@ -124,7 +124,7 @@ public: MOCK_METHOD1(setColorLoop, bool(bool on)); MOCK_METHOD3(sendPutRequest, - nlohmann::json(const std::string& subPath, const nlohmann::json& request,hueplusplus::FileInfo fileInfo)); + nlohmann::json(const std::string& subPath, const nlohmann::json& request, hueplusplus::FileInfo fileInfo)); }; #endif diff --git a/test/test_Bridge.cpp b/test/test_Bridge.cpp index 6e03593..3561502 100644 --- a/test/test_Bridge.cpp +++ b/test/test_Bridge.cpp @@ -62,10 +62,10 @@ protected: ~BridgeFinderTest() {}; }; -TEST_F(BridgeFinderTest, FindBridges) +TEST_F(BridgeFinderTest, findBridges) { BridgeFinder finder(handler); - std::vector bridges = finder.FindBridges(); + std::vector bridges = finder.findBridges(); BridgeFinder::BridgeIdentification bridge_to_comp; bridge_to_comp.ip = getBridgeIp(); @@ -81,11 +81,11 @@ TEST_F(BridgeFinderTest, FindBridges) EXPECT_CALL(*handler, GETString("/description.xml", "application/xml", "", getBridgeIp(), getBridgePort())) .Times(1) .WillOnce(::testing::Return("invalid stuff")); - bridges = finder.FindBridges(); + bridges = finder.findBridges(); EXPECT_TRUE(bridges.empty()); } -TEST_F(BridgeFinderTest, GetBridge) +TEST_F(BridgeFinderTest, getBridge) { using namespace ::testing; nlohmann::json request {{"devicetype", "HuePlusPlus#User"}, {"generateclientkey", true}}; @@ -98,9 +98,9 @@ TEST_F(BridgeFinderTest, GetBridge) .WillRepeatedly(Return(errorResponse)); BridgeFinder finder(handler); - std::vector bridges = finder.FindBridges(); + std::vector bridges = finder.findBridges(); - ASSERT_THROW(finder.GetBridge(bridges[0]), HueException); + ASSERT_THROW(finder.getBridge(bridges[0]), HueException); nlohmann::json successResponse = {{{"success", {{"username", getBridgeUsername()}}}}}; @@ -109,9 +109,9 @@ TEST_F(BridgeFinderTest, GetBridge) .WillOnce(Return(successResponse)); finder = BridgeFinder(handler); - bridges = finder.FindBridges(); + bridges = finder.findBridges(); - Bridge test_bridge = finder.GetBridge(bridges[0]); + Bridge test_bridge = finder.getBridge(bridges[0]); EXPECT_EQ(test_bridge.getBridgeIP(), getBridgeIp()) << "Bridge IP not matching"; EXPECT_EQ(test_bridge.getBridgePort(), getBridgePort()) << "Bridge Port not matching"; @@ -120,27 +120,27 @@ TEST_F(BridgeFinderTest, GetBridge) Mock::VerifyAndClearExpectations(handler.get()); } -TEST_F(BridgeFinderTest, AddUsername) +TEST_F(BridgeFinderTest, addUsername) { BridgeFinder finder(handler); - std::vector bridges = finder.FindBridges(); + std::vector bridges = finder.findBridges(); - finder.AddUsername(bridges[0].mac, getBridgeUsername()); - Bridge test_bridge = finder.GetBridge(bridges[0]); + finder.addUsername(bridges[0].mac, getBridgeUsername()); + Bridge test_bridge = finder.getBridge(bridges[0]); EXPECT_EQ(test_bridge.getBridgeIP(), getBridgeIp()) << "Bridge IP not matching"; EXPECT_EQ(test_bridge.getBridgePort(), getBridgePort()) << "Bridge Port not matching"; EXPECT_EQ(test_bridge.getUsername(), getBridgeUsername()) << "Bridge username not matching"; } -TEST_F(BridgeFinderTest, GetAllUsernames) +TEST_F(BridgeFinderTest, getAllUsernames) { BridgeFinder finder(handler); - std::vector bridges = finder.FindBridges(); + std::vector bridges = finder.findBridges(); - finder.AddUsername(bridges[0].mac, getBridgeUsername()); + finder.addUsername(bridges[0].mac, getBridgeUsername()); - std::map users = finder.GetAllUsernames(); + std::map users = finder.getAllUsernames(); EXPECT_EQ(users[getBridgeMac()], getBridgeUsername()) << "Username of MAC:" << getBridgeMac() << "not matching"; } @@ -299,7 +299,8 @@ TEST(Bridge, SharedState) *handler, GETJson("/api/" + getBridgeUsername(), nlohmann::json::object(), getBridgeIp(), getBridgePort())) .Times(1) .WillOnce(Return(hue_bridge_state)); - Bridge test_bridge(getBridgeIp(), getBridgePort(), getBridgeUsername(), handler, std::chrono::seconds(10), true); + Bridge test_bridge( + getBridgeIp(), getBridgePort(), getBridgeUsername(), handler, "", std::chrono::seconds(10), true); // Test when correct data is sent Light test_light_1 = test_bridge.lights().get(1); diff --git a/test/test_Light.cpp b/test/test_Light.cpp index 614699c..6518ddb 100644 --- a/test/test_Light.cpp +++ b/test/test_Light.cpp @@ -89,7 +89,7 @@ TEST_F(HueLightTest, Constructor) Light test_light_3 = test_bridge.lights().get(3); } -TEST_F(HueLightTest, On) +TEST_F(HueLightTest, on) { using namespace ::testing; EXPECT_CALL(*handler, PUTJson("/api/" + getBridgeUsername() + "/lights/2/state", _, getBridgeIp(), 80)) @@ -112,12 +112,12 @@ TEST_F(HueLightTest, On) Light test_light_2 = test_bridge.lights().get(2); Light test_light_3 = test_bridge.lights().get(3); - EXPECT_EQ(true, test_light_1.On(33)); - EXPECT_EQ(false, test_light_2.On()); - EXPECT_EQ(true, test_light_3.On(255)); + EXPECT_EQ(true, test_light_1.on(33)); + EXPECT_EQ(false, test_light_2.on()); + EXPECT_EQ(true, test_light_3.on(255)); } -TEST_F(HueLightTest, Off) +TEST_F(HueLightTest, off) { using namespace ::testing; nlohmann::json prep_ret; @@ -136,9 +136,9 @@ TEST_F(HueLightTest, Off) Light test_light_2 = test_bridge.lights().get(2); Light test_light_3 = test_bridge.lights().get(3); - EXPECT_EQ(true, test_light_1.Off(33)); - EXPECT_EQ(true, test_light_2.Off()); - EXPECT_EQ(true, test_light_3.Off(255)); + EXPECT_EQ(true, test_light_1.off(33)); + EXPECT_EQ(true, test_light_2.off()); + EXPECT_EQ(true, test_light_3.off(255)); } TEST_F(HueLightTest, isOn) @@ -362,7 +362,7 @@ TEST_F(HueLightTest, getColorType) EXPECT_EQ(ColorType::GAMUT_C_TEMPERATURE, test_light_3.getColorType()); } -TEST_F(HueLightTest, KelvinToMired) +TEST_F(HueLightTest, kelvinToMired) { const Light ctest_light_1 = test_bridge.lights().get(1); const Light ctest_light_2 = test_bridge.lights().get(2); @@ -371,15 +371,15 @@ TEST_F(HueLightTest, KelvinToMired) Light test_light_2 = test_bridge.lights().get(2); Light test_light_3 = test_bridge.lights().get(3); - EXPECT_EQ(10000, ctest_light_1.KelvinToMired(100)); - EXPECT_EQ(500, ctest_light_2.KelvinToMired(2000)); - EXPECT_EQ(303, ctest_light_3.KelvinToMired(3300)); - EXPECT_EQ(250, test_light_1.KelvinToMired(4000)); - EXPECT_EQ(200, test_light_2.KelvinToMired(5000)); - EXPECT_EQ(166, test_light_3.KelvinToMired(6000)); + EXPECT_EQ(10000, ctest_light_1.kelvinToMired(100)); + EXPECT_EQ(500, ctest_light_2.kelvinToMired(2000)); + EXPECT_EQ(303, ctest_light_3.kelvinToMired(3300)); + EXPECT_EQ(250, test_light_1.kelvinToMired(4000)); + EXPECT_EQ(200, test_light_2.kelvinToMired(5000)); + EXPECT_EQ(166, test_light_3.kelvinToMired(6000)); } -TEST_F(HueLightTest, MiredToKelvin) +TEST_F(HueLightTest, miredToKelvin) { const Light ctest_light_1 = test_bridge.lights().get(1); const Light ctest_light_2 = test_bridge.lights().get(2); @@ -388,12 +388,12 @@ TEST_F(HueLightTest, MiredToKelvin) Light test_light_2 = test_bridge.lights().get(2); Light test_light_3 = test_bridge.lights().get(3); - EXPECT_EQ(100, ctest_light_1.MiredToKelvin(10000)); - EXPECT_EQ(2000, ctest_light_2.MiredToKelvin(500)); - EXPECT_EQ(3300, ctest_light_3.MiredToKelvin(303)); - EXPECT_EQ(4000, test_light_1.MiredToKelvin(250)); - EXPECT_EQ(5000, test_light_2.MiredToKelvin(200)); - EXPECT_EQ(6024, test_light_3.MiredToKelvin(166)); // 6000 kelvin should be 166 mired, but keep in + EXPECT_EQ(100, ctest_light_1.miredToKelvin(10000)); + EXPECT_EQ(2000, ctest_light_2.miredToKelvin(500)); + EXPECT_EQ(3300, ctest_light_3.miredToKelvin(303)); + EXPECT_EQ(4000, test_light_1.miredToKelvin(250)); + EXPECT_EQ(5000, test_light_2.miredToKelvin(200)); + EXPECT_EQ(6024, test_light_3.miredToKelvin(166)); // 6000 kelvin should be 166 mired, but keep in // mind flops are not exact } diff --git a/test/test_LightFactory.cpp b/test/test_LightFactory.cpp index 6b985d7..ec2009e 100644 --- a/test/test_LightFactory.cpp +++ b/test/test_LightFactory.cpp @@ -20,9 +20,10 @@ along with hueplusplus. If not, see . **/ -#include #include +#include + #include "testhelper.h" #include "mocks/mock_HttpHandler.h" @@ -70,12 +71,12 @@ TEST(LightFactory, createLight_gamutCapabilities) std::chrono::steady_clock::duration::max()); nlohmann::json lightState - = { {"state", + = {{"state", {{"on", true}, {"bri", 254}, {"ct", 366}, {"alert", "none"}, {"colormode", "ct"}, {"reachable", true}}}, {"swupdate", {{"state", "noupdates"}, {"lastinstall", nullptr}}}, {"type", "Color light"}, {"name", "Hue ambiance lamp 1"}, {"modelid", "LTW001"}, {"manufacturername", "Philips"}, {"uniqueid", "00:00:00:00:00:00:00:00-00"}, {"swversion", "5.50.1.19085"}, - {"capabilities", {{"control", {{"colorgamuttype", "A"}}}}} }; + {"capabilities", {{"control", {{"colorgamuttype", "A"}}}}}}; Light test_light_1 = factory.createLight(lightState, 1); EXPECT_EQ(test_light_1.getColorType(), ColorType::GAMUT_A); diff --git a/test/test_Scene.cpp b/test/test_Scene.cpp index 6b38971..fc2f6c3 100644 --- a/test/test_Scene.cpp +++ b/test/test_Scene.cpp @@ -30,7 +30,7 @@ using namespace hueplusplus; using namespace testing; -TEST(LightState, On) +TEST(LightState, on) { EXPECT_FALSE(LightState(nlohmann::json::object()).isOn()); EXPECT_TRUE(LightState(nlohmann::json {{"on", true}}).isOn()); @@ -141,7 +141,7 @@ public: {{"3", {{"on", false}, {"bri", 100}, {"xy", {0.3, 0.2}}}}, {"4", {{"on", true}, {"bri", 200}, {"xy", {0.3, 0.2}}, {"effect", "colorloop"}}}, {"5", {{"on", true}, {"bri", 100}, {"xy", {0.3, 0.2}}}}}}}) - {} + { } void expectGetState(const std::string& id) { diff --git a/test/test_Sensor.cpp b/test/test_Sensor.cpp index 130c608..2e62aab 100644 --- a/test/test_Sensor.cpp +++ b/test/test_Sensor.cpp @@ -72,7 +72,7 @@ TEST(Alert, alertToString) EXPECT_EQ("lselect", alertToString(Alert::lselect)); } -TEST_F(SensorTest, On) +TEST_F(SensorTest, on) { EXPECT_FALSE(getSensor().hasOn()); state["config"]["on"] = true; diff --git a/test/test_SensorImpls.cpp b/test/test_SensorImpls.cpp index 2b8948d..90c98fb 100644 --- a/test/test_SensorImpls.cpp +++ b/test/test_SensorImpls.cpp @@ -159,7 +159,7 @@ class CLIPGenericFlagTest : public SensorImplTest class CLIPGenericStatusTest : public SensorImplTest { }; -TYPED_TEST(SensorOnTest, On) +TYPED_TEST(SensorOnTest, on) { this->state["config"]["on"] = false; EXPECT_FALSE(this->getSensor().isOn()); diff --git a/test/test_SimpleColorTemperatureStrategy.cpp b/test/test_SimpleColorTemperatureStrategy.cpp index 770dd28..d97b8ac 100644 --- a/test/test_SimpleColorTemperatureStrategy.cpp +++ b/test/test_SimpleColorTemperatureStrategy.cpp @@ -102,7 +102,7 @@ TEST(SimpleColorTemperatureStrategy, alertTemperature) light.getState()["state"]["on"] = false; EXPECT_EQ(false, SimpleColorTemperatureStrategy().alertTemperature(400, light)); } - // On + // on { const nlohmann::json state = {{"colormode", "ct"}, {"on", true}, {"ct", 200}}; light.getState()["state"] = state; @@ -123,7 +123,7 @@ TEST(SimpleColorTemperatureStrategy, alertTemperature) EXPECT_TRUE(SimpleColorTemperatureStrategy().alertTemperature(400, light)); Mock::VerifyAndClearExpectations(handler.get()); } - // Off + // off { const nlohmann::json state = {{"colormode", "ct"}, {"on", false}, {"ct", 200}}; light.getState()["state"] = state; @@ -134,7 +134,6 @@ TEST(SimpleColorTemperatureStrategy, alertTemperature) reverseTransaction.expectSuccessfulPut(handler, Exactly(1)); EXPECT_TRUE(SimpleColorTemperatureStrategy().alertTemperature(400, light)); Mock::VerifyAndClearExpectations(handler.get()); - } } -- libgit2 0.21.4