Loading...
Searching...
No Matches
SensorList.h
Go to the documentation of this file.
#ifndef INCLUDE_HUEPLUSPLUS_SENSOR_LIST_H
#define INCLUDE_HUEPLUSPLUS_SENSOR_LIST_H
#include "ResourceList.h"
#include "Sensor.h"
namespace hueplusplus
{
class SensorList : public CreateableResourceList<SearchableResourceList<Sensor>, CreateSensor>
{
public:
using CreateableResourceList::CreateableResourceList;
template <typename T>
T getAsType(int id)
{
return get(id).asSensorType<T>();
}
template <typename T>
std::vector<T> getAllByType()
{
nlohmann::json state = this->stateCache->getValue();
std::vector<T> result;
for (auto it = state.begin(); it != state.end(); ++it)
{
// Only parse the sensors with the correct type
if (it->value("type", "") == T::typeStr)
{
result.push_back(get(maybeStoi(it.key())).asSensorType<T>());
}
}
return result;
}
protected:
SensorList(SensorList&&) = default;
SensorList& operator=(SensorList&&) = default;
};
} // namespace hueplusplus
#endif
ResourceList.h
Sensor.h
hueplusplus::CreateableResourceList::CreateableResourceList
CreateableResourceList(CreateableResourceList &&)=default
Protected defaulted move constructor.
hueplusplus::ResourceList< Sensor, int >::get
Sensor get(const IdType &id)
Definition ResourceList.h:126
hueplusplus::ResourceList< Sensor, int >::maybeStoi
static IdType maybeStoi(const std::string &key)
Definition ResourceList.h:173
hueplusplus::ResourceList< Sensor, int >::stateCache
std::shared_ptr< APICache > stateCache
Definition ResourceList.h:230
hueplusplus::Sensor::asSensorType
T asSensorType() const &
Convert sensor to a specific type.
Definition Sensor.h:210
hueplusplus::SensorList::operator=
SensorList & operator=(SensorList &&)=default
Protected defaulted move assignment.
hueplusplus::SensorList::getAllByType
std::vector< T > getAllByType()
Get all sensors of type T.
Definition SensorList.h:59
hueplusplus::SensorList::getAsType
T getAsType(int id)
Get sensor specified by id, convert to T.
Definition SensorList.h:47
hueplusplus::SensorList::SensorList
SensorList(SensorList &&)=default
Protected defaulted move constructor.
hueplusplus::SensorList::CreateableResourceList
CreateableResourceList(CreateableResourceList &&)=default
Protected defaulted move constructor.
hueplusplus
Namespace for the hueplusplus library.
Definition Action.h:28