hueplusplus  1.0.0
SensorList.h
Go to the documentation of this file.
1 
22 #ifndef INCLUDE_HUEPLUSPLUS_SENSOR_LIST_H
23 #define INCLUDE_HUEPLUSPLUS_SENSOR_LIST_H
24 
25 #include "ResourceList.h"
26 #include "Sensor.h"
27 
28 namespace hueplusplus
29 {
33 class SensorList : public CreateableResourceList<SearchableResourceList<Sensor>, CreateSensor>
34 {
35 public:
37 
46  template <typename T>
47  T getAsType(int id)
48  {
49  return get(id).asSensorType<T>();
50  }
58  template <typename T>
59  std::vector<T> getAllByType()
60  {
61  nlohmann::json state = this->stateCache->getValue();
62  std::vector<T> result;
63  for (auto it = state.begin(); it != state.end(); ++it)
64  {
65  // Only parse the sensors with the correct type
66  if (it->value("type", "") == T::typeStr)
67  {
68  result.push_back(get(maybeStoi(it.key())).asSensorType<T>());
69  }
70  }
71  return result;
72  }
73 
74 protected:
76  SensorList(SensorList&&) = default;
78  SensorList& operator=(SensorList&&) = default;
79 };
80 } // namespace hueplusplus
81 
82 #endif
Handles a ResourceList where Resources can be added by the user.
Definition: ResourceList.h:285
std::shared_ptr< APICache > stateCache
Definition: ResourceList.h:230
Namespace for the hueplusplus library.
Definition: Action.h:27
std::vector< T > getAllByType()
Get all sensors of type T.
Definition: SensorList.h:59
static IdType maybeStoi(const std::string &key)
Calls std::stoi if IdType is int.
Definition: ResourceList.h:173
Handles a list of Sensors with type specific getters.
Definition: SensorList.h:33
T getAsType(int id)
Get sensor specified by id, convert to T.
Definition: SensorList.h:47
CreateableResourceList(CreateableResourceList &&)=default
Protected defaulted move constructor.
SensorList(SensorList &&)=default
Protected defaulted move constructor.
SensorList & operator=(SensorList &&)=default
Protected defaulted move assignment.