Commit f225eaee6a28b73685a1e80af6f15c4f5d7c5e68

Authored by Jojo-1000
Committed by Moritz Wirger
1 parent 65ddf858

Add getLastUpdated() to DaylightSensor and ZLLTemperature.

include/hueplusplus/ResourceList.h
... ... @@ -319,7 +319,7 @@ public:
319 319 this->stateCache.refresh();
320 320 return this->maybeStoi(idStr);
321 321 }
322   - return BaseResourceList::IdType {};
  322 + return typename BaseResourceList::IdType {};
323 323 }
324 324  
325 325 protected:
... ...
include/hueplusplus/Sensor.h
... ... @@ -336,6 +336,11 @@ public:
336 336 //! \brief Get reported daylight status
337 337 bool isDaylight() const;
338 338  
  339 + //! \brief Get time of last status update
  340 + //! \returns The last update time, or a time with a zero duration from epoch
  341 + //! if the last update time is not set.
  342 + time::AbsoluteTime getLastUpdated() const;
  343 +
339 344 //! \brief Daylight sensor type name
340 345 static constexpr const char* typeStr = "Daylight";
341 346 };
... ...
include/hueplusplus/TimePattern.h
... ... @@ -24,6 +24,7 @@
24 24  
25 25 #include <chrono>
26 26 #include <string>
  27 +#include <cstddef>
27 28  
28 29 namespace hueplusplus
29 30 {
... ... @@ -422,7 +423,7 @@ private:
422 423 Type type;
423 424 union
424 425 {
425   - nullptr_t undefined;
  426 + std::nullptr_t undefined;
426 427 AbsoluteVariedTime absolute;
427 428 RecurringTime recurring;
428 429 TimeInterval interval;
... ...
include/hueplusplus/ZLLSensors.h
... ... @@ -246,6 +246,11 @@ public:
246 246 //! \returns Temperature in 0.01 degrees Celsius.
247 247 int getTemperature() const;
248 248  
  249 + //! \brief Get time of last status update
  250 + //! \returns The last update time, or a time with a zero duration from epoch
  251 + //! if the last update time is not set.
  252 + time::AbsoluteTime getLastUpdated() const;
  253 +
249 254 //! \brief ZLLTemperature sensor type name
250 255 static constexpr const char* typeStr = "ZLLTemperature";
251 256 };
... ...
src/Sensor.cpp
... ... @@ -326,5 +326,16 @@ bool DaylightSensor::isDaylight() const
326 326 {
327 327 return state.getValue().at("state").at("daylight").get<bool>();
328 328 }
  329 +
  330 +time::AbsoluteTime DaylightSensor::getLastUpdated() const
  331 +{
  332 + const nlohmann::json& stateJson = state.getValue().at("state");
  333 + auto it = stateJson.find("lastupdated");
  334 + if (it == stateJson.end() || !it->is_string() || *it == "none")
  335 + {
  336 + return time::AbsoluteTime(std::chrono::system_clock::time_point(std::chrono::seconds{ 0 }));
  337 + }
  338 + return time::AbsoluteTime::parseUTC(it->get<std::string>());
  339 +}
329 340 } // namespace sensors
330 341 } // namespace hueplusplus
... ...
src/ZLLSensors.cpp
... ... @@ -215,6 +215,17 @@ int ZLLTemperature::getTemperature() const
215 215 return state.getValue().at("state").at("temperature").get<int>();
216 216 }
217 217  
  218 +time::AbsoluteTime ZLLTemperature::getLastUpdated() const
  219 +{
  220 + const nlohmann::json& stateJson = state.getValue().at("state");
  221 + auto it = stateJson.find("lastupdated");
  222 + if (it == stateJson.end() || !it->is_string() || *it == "none")
  223 + {
  224 + return time::AbsoluteTime(std::chrono::system_clock::time_point(std::chrono::seconds{ 0 }));
  225 + }
  226 + return time::AbsoluteTime::parseUTC(it->get<std::string>());
  227 +}
  228 +
218 229 constexpr const char* ZLLLightLevel::typeStr;
219 230  
220 231 bool ZLLLightLevel::isOn() const
... ...
test/test_SensorImpls.cpp
... ... @@ -97,7 +97,7 @@ TYPED_TEST_SUITE(SensorReachableTest, SensorReachableTypes);
97 97 template <typename T>
98 98 class SensorUpdateTest : public SensorImplTest<T>
99 99 { };
100   -using SensorUpdateTypes = Types<CLIPSwitch, ZLLSwitch, ZLLPresence, ZLLLightLevel>;
  100 +using SensorUpdateTypes = Types<CLIPSwitch, ZLLSwitch, ZLLPresence, ZLLLightLevel, ZLLTemperature, DaylightSensor>;
101 101 TYPED_TEST_SUITE(SensorUpdateTest, SensorUpdateTypes);
102 102  
103 103 template <typename T>
... ...