diff --git a/include/hueplusplus/ResourceList.h b/include/hueplusplus/ResourceList.h index 7378270..51ab674 100644 --- a/include/hueplusplus/ResourceList.h +++ b/include/hueplusplus/ResourceList.h @@ -319,7 +319,7 @@ public: this->stateCache.refresh(); return this->maybeStoi(idStr); } - return BaseResourceList::IdType {}; + return typename BaseResourceList::IdType {}; } protected: diff --git a/include/hueplusplus/Sensor.h b/include/hueplusplus/Sensor.h index 7eeb44f..a070e8e 100644 --- a/include/hueplusplus/Sensor.h +++ b/include/hueplusplus/Sensor.h @@ -336,6 +336,11 @@ public: //! \brief Get reported daylight status bool isDaylight() const; + //! \brief Get time of last status update + //! \returns The last update time, or a time with a zero duration from epoch + //! if the last update time is not set. + time::AbsoluteTime getLastUpdated() const; + //! \brief Daylight sensor type name static constexpr const char* typeStr = "Daylight"; }; diff --git a/include/hueplusplus/TimePattern.h b/include/hueplusplus/TimePattern.h index a69d5a9..80002ae 100644 --- a/include/hueplusplus/TimePattern.h +++ b/include/hueplusplus/TimePattern.h @@ -24,6 +24,7 @@ #include #include +#include namespace hueplusplus { @@ -422,7 +423,7 @@ private: Type type; union { - nullptr_t undefined; + std::nullptr_t undefined; AbsoluteVariedTime absolute; RecurringTime recurring; TimeInterval interval; diff --git a/include/hueplusplus/ZLLSensors.h b/include/hueplusplus/ZLLSensors.h index 476176a..e45e3c5 100644 --- a/include/hueplusplus/ZLLSensors.h +++ b/include/hueplusplus/ZLLSensors.h @@ -246,6 +246,11 @@ public: //! \returns Temperature in 0.01 degrees Celsius. int getTemperature() const; + //! \brief Get time of last status update + //! \returns The last update time, or a time with a zero duration from epoch + //! if the last update time is not set. + time::AbsoluteTime getLastUpdated() const; + //! \brief ZLLTemperature sensor type name static constexpr const char* typeStr = "ZLLTemperature"; }; diff --git a/src/Sensor.cpp b/src/Sensor.cpp index 4cda9a8..995db07 100644 --- a/src/Sensor.cpp +++ b/src/Sensor.cpp @@ -326,5 +326,16 @@ bool DaylightSensor::isDaylight() const { return state.getValue().at("state").at("daylight").get(); } + +time::AbsoluteTime DaylightSensor::getLastUpdated() const +{ + const nlohmann::json& stateJson = state.getValue().at("state"); + auto it = stateJson.find("lastupdated"); + if (it == stateJson.end() || !it->is_string() || *it == "none") + { + return time::AbsoluteTime(std::chrono::system_clock::time_point(std::chrono::seconds{ 0 })); + } + return time::AbsoluteTime::parseUTC(it->get()); +} } // namespace sensors } // namespace hueplusplus diff --git a/src/ZLLSensors.cpp b/src/ZLLSensors.cpp index 2361054..94ee2fb 100644 --- a/src/ZLLSensors.cpp +++ b/src/ZLLSensors.cpp @@ -215,6 +215,17 @@ int ZLLTemperature::getTemperature() const return state.getValue().at("state").at("temperature").get(); } +time::AbsoluteTime ZLLTemperature::getLastUpdated() const +{ + const nlohmann::json& stateJson = state.getValue().at("state"); + auto it = stateJson.find("lastupdated"); + if (it == stateJson.end() || !it->is_string() || *it == "none") + { + return time::AbsoluteTime(std::chrono::system_clock::time_point(std::chrono::seconds{ 0 })); + } + return time::AbsoluteTime::parseUTC(it->get()); +} + constexpr const char* ZLLLightLevel::typeStr; bool ZLLLightLevel::isOn() const diff --git a/test/test_SensorImpls.cpp b/test/test_SensorImpls.cpp index c99435a..56d3d4e 100644 --- a/test/test_SensorImpls.cpp +++ b/test/test_SensorImpls.cpp @@ -97,7 +97,7 @@ TYPED_TEST_SUITE(SensorReachableTest, SensorReachableTypes); template class SensorUpdateTest : public SensorImplTest { }; -using SensorUpdateTypes = Types; +using SensorUpdateTypes = Types; TYPED_TEST_SUITE(SensorUpdateTest, SensorUpdateTypes); template