hueplusplus 1.2.0
Loading...
Searching...
No Matches
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
28namespace hueplusplus
29{
33class SensorList : public CreateableResourceList<SearchableResourceList<Sensor>, CreateSensor>
34{
35public:
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
74protected:
76 SensorList(SensorList&&) = default;
79};
80} // namespace hueplusplus
81
82#endif
Handles a ResourceList where Resources can be added by the user.
Definition ResourceList.h:286
CreateableResourceList(CreateableResourceList &&)=default
Protected defaulted move constructor.
Resource get(const IdType &id)
Get resource specified by id.
Definition ResourceList.h:126
static IdType maybeStoi(const std::string &key)
Calls std::stoi if IdType is int.
Definition ResourceList.h:173
std::shared_ptr< APICache > stateCache
Definition ResourceList.h:230
Handles a list of Sensors with type specific getters.
Definition SensorList.h:34
SensorList & operator=(SensorList &&)=default
Protected defaulted move assignment.
std::vector< T > getAllByType()
Get all sensors of type T.
Definition SensorList.h:59
T getAsType(int id)
Get sensor specified by id, convert to T.
Definition SensorList.h:47
SensorList(SensorList &&)=default
Protected defaulted move constructor.
Namespace for the hueplusplus library.
Definition Action.h:28