23 #ifndef INCLUDE_HUEPLUSPLUS_HUE_SENSOR_H 24 #define INCLUDE_HUEPLUSPLUS_HUE_SENSOR_H 33 #include "json/json.hpp" 65 Sensor(
int id,
const std::shared_ptr<APICache>& baseCache);
72 Sensor(
int id,
const HueCommandAPI& commands, std::chrono::steady_clock::duration refreshDuration,
const nlohmann::json& currentState);
92 bool hasBatteryState()
const;
96 int getBatteryState()
const;
102 void setBatteryState(
int percent);
105 bool hasAlert()
const;
109 Alert getLastAlert()
const;
115 void sendAlert(
Alert type);
118 bool hasReachable()
const;
121 bool isReachable()
const;
124 bool hasUserTest()
const;
133 void setUserTest(
bool enabled);
140 std::string getURL()
const;
146 void setURL(
const std::string& url);
153 std::vector<std::string> getPendingConfig()
const;
156 bool hasLEDIndication()
const;
159 bool getLEDIndication()
const;
165 void setLEDIndication(
bool on);
169 nlohmann::json getConfig()
const;
175 void setConfigAttribute(
const std::string& key,
const nlohmann::json& value);
185 nlohmann::json getState()
const;
191 void setStateAttribute(
const std::string& key,
const nlohmann::json& value);
196 std::string getStateAddress(
const std::string& key)
const;
199 bool isCertified()
const;
204 bool isPrimary()
const;
209 template <
typename T>
212 if (getType() != T::typeStr)
214 throw HueException(
FileInfo {__FILE__, __LINE__, __func__},
"Sensor type does not match: " + getType());
223 template <
typename T>
226 if (getType() != T::typeStr)
228 throw HueException(
FileInfo {__FILE__, __LINE__, __func__},
"Sensor type does not match: " + getType());
230 return T(std::move(*
this));
248 CreateSensor(
const std::string& name,
const std::string& modelid,
const std::string& swversion,
249 const std::string& type,
const std::string& uniqueid,
const std::string& manufacturername);
265 nlohmann::json getRequest()
const;
298 bool hasBatteryState()
const;
302 int getBatteryState()
const;
308 void setBatteryState(
int percent);
318 void setCoordinates(
const std::string& latitude,
const std::string& longitude);
322 bool isConfigured()
const;
327 int getSunriseOffset()
const;
334 void setSunriseOffset(
int minutes);
339 int getSunsetOffset()
const;
346 void setSunsetOffset(
int minutes);
349 bool isDaylight()
const;
357 static constexpr
const char* typeStr =
"Daylight";
362 template <
typename SensorT, detail::
void_t<decltype(std::declval<const SensorT>().getLastUpdated())>* =
nullptr>
365 return detail::ConditionHelper<time::AbsoluteTime>(
366 "/sensors/" + std::to_string(sensor.getId()) +
"/state/lastupdated");
369 template <
typename ButtonSensor, detail::
void_t<decltype(std::declval<const ButtonSensor>().getButtonEvent())>* =
nullptr>
372 return detail::ConditionHelper<int>(
373 "/sensors/" + std::to_string(sensor.getId()) +
"/state/buttonevent");
376 template <
typename PresenceSensor, detail::
void_t<decltype(std::declval<const PresenceSensor>().getPresence())>* =
nullptr>
379 return detail::ConditionHelper<bool>(
380 "/sensors/" + std::to_string(sensor.getId()) +
"/state/presence");
383 template <
typename TemperatureSensor, detail::
void_t<decltype(std::declval<const TemperatureSensor>().getPresence())>* =
nullptr>
386 return detail::ConditionHelper<int>(
387 "/sensors/" + std::to_string(sensor.getId()) +
"/state/temperature");
Definition: HueCommandAPI.h:37
Exception class with file information. Base class of all custom exception classes.
Definition: HueException.h:49
Long select alert (15s breathe)
DaylightSensor(Sensor sensor)
Construct from generic sensor.
Definition: Sensor.h:283
T asSensorType() &&
Convert sensor to a specific type.
Definition: Sensor.h:224
Namespace for the hueplusplus library.
Definition: Action.h:27
std::string alertToString(Alert alert)
Convert alert to string form.
Definition: Sensor.cpp:30
Alert
Specifies light alert modes.
Definition: Sensor.h:38
Base class for physical devices connected to the bridge (sensor or light).
Definition: BaseDevice.h:35
Contains information about error location, use CURRENT_FILE_INFO to create.
Definition: HueException.h:34
One-time, absolute time point.
Definition: TimePattern.h:72
nlohmann::json request
Definition: Sensor.h:268
Daylight sensor to detect sunrise and sunset.
Definition: Sensor.h:279
Class for generic or unknown sensor types.
Definition: Sensor.h:59
Alert alertFromString(const std::string &s)
Convert string to Alert enum.
Definition: Sensor.cpp:44
Select alert (breathe cycle)
T asSensorType() const &
Convert sensor to a specific type.
Definition: Sensor.h:210
Parameters for creating a new Sensor.
Definition: Sensor.h:237
detail::ConditionHelper< int > makeCondition(const TemperatureSensor &sensor)
Definition: Sensor.h:384
detail::ConditionHelper< time::AbsoluteTime > makeConditionLastUpdate(const SensorT &sensor)
Definition: Sensor.h:363