23#ifndef INCLUDE_HUEPLUSPLUS_HUE_SENSOR_H
24#define INCLUDE_HUEPLUSPLUS_HUE_SENSOR_H
33#include <nlohmann/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);
140 std::string
getURL()
const;
146 void setURL(
const std::string& url);
209 template <
typename T>
223 template <
typename T>
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);
318 void setCoordinates(
const std::string& latitude,
const std::string& longitude);
357 static constexpr const char*
typeStr =
"Daylight";
362template <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");
369template <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");
376template <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");
383template <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");
Base class for physical devices connected to the bridge (sensor or light).
Definition BaseDevice.h:36
virtual std::string getType() const
Const function that returns the device type.
Definition BaseDevice.cpp:39
Parameters for creating a new Sensor.
Definition Sensor.h:238
CreateSensor & setRecycle(bool recycle)
Enable recycling, delete automatically when not referenced.
Definition Sensor.cpp:260
nlohmann::json request
Definition Sensor.h:268
CreateSensor & setConfig(const nlohmann::json &config)
Set config object.
Definition Sensor.cpp:254
nlohmann::json getRequest() const
Get request to create the sensor.
Definition Sensor.cpp:266
CreateSensor & setState(const nlohmann::json &state)
Set state object.
Definition Sensor.cpp:248
Definition HueCommandAPI.h:38
Exception class with file information. Base class of all custom exception classes.
Definition HueException.h:50
Class for generic or unknown sensor types.
Definition Sensor.h:60
std::string getURL() const
Get sensor URL.
Definition Sensor.cpp:158
std::string getStateAddress(const std::string &key) const
Get address of the given state attribute, used for conditions.
Definition Sensor.cpp:206
T asSensorType() &&
Convert sensor to a specific type.
Definition Sensor.h:224
T asSensorType() const &
Convert sensor to a specific type.
Definition Sensor.h:210
void setBatteryState(int percent)
Set battery state.
Definition Sensor.cpp:83
int getBatteryState() const
Get battery state.
Definition Sensor.cpp:79
bool isOn() const
check whether the sensor is turned on
Definition Sensor.cpp:65
void setUserTest(bool enabled)
Enable or disable user test mode.
Definition Sensor.cpp:149
bool hasAlert() const
Check whether the sensor has alerts.
Definition Sensor.cpp:87
bool hasOn() const
Check whether the sensor has an on attribute.
Definition Sensor.cpp:60
void setConfigAttribute(const std::string &key, const nlohmann::json &value)
Set attribute in the sensor config.
Definition Sensor.cpp:216
bool getLEDIndication() const
Get whether the indicator LED is on.
Definition Sensor.cpp:188
bool isCertified() const
Check if the sensor is Hue certified.
Definition Sensor.cpp:221
std::vector< std::string > getPendingConfig() const
Get pending config entries, if they exist.
Definition Sensor.cpp:167
void sendAlert(Alert type)
Send alert.
Definition Sensor.cpp:107
time::AbsoluteTime getLastUpdated() const
Get time of last status update.
Definition Sensor.cpp:134
bool isReachable() const
Get whether sensor is reachable.
Definition Sensor.cpp:128
void setOn(bool on)
Turn sensor on or off.
Definition Sensor.cpp:70
bool isPrimary() const
Check if the sensor is primary sensor of the device.
Definition Sensor.cpp:227
nlohmann::json getConfig() const
Get entire config object.
Definition Sensor.cpp:211
bool hasBatteryState() const
Check whether the sensor has a battery state.
Definition Sensor.cpp:75
nlohmann::json getState() const
Get state object.
Definition Sensor.cpp:197
void setStateAttribute(const std::string &key, const nlohmann::json &value)
Set part of the sensor state.
Definition Sensor.cpp:201
void setURL(const std::string &url)
Set sensor URL.
Definition Sensor.cpp:162
bool hasUserTest() const
Check whether the sensor has a user test mode.
Definition Sensor.cpp:145
bool hasLEDIndication() const
Check whether the sensor has an LED indicator.
Definition Sensor.cpp:184
bool hasURL() const
Check whether the sensor has a URL.
Definition Sensor.cpp:154
void setLEDIndication(bool on)
Turn LED indicator on or off.
Definition Sensor.cpp:192
bool hasReachable() const
Check whether the sensor has reachable validation.
Definition Sensor.cpp:124
Alert getLastAlert() const
Get last sent alert.
Definition Sensor.cpp:91
Daylight sensor to detect sunrise and sunset.
Definition Sensor.h:280
void setSunriseOffset(int minutes)
Set sunrise offset time.
Definition Sensor.cpp:321
bool isOn() const
Check if the sensor is on.
Definition Sensor.cpp:276
void setSunsetOffset(int minutes)
Set sunset offset time.
Definition Sensor.cpp:330
static constexpr const char * typeStr
Daylight sensor type name.
Definition Sensor.h:357
int getSunsetOffset() const
Get time offset in minutes to sunset.
Definition Sensor.cpp:326
int getBatteryState() const
Get battery state.
Definition Sensor.cpp:290
bool isConfigured() const
Check whether coordinates are configured.
Definition Sensor.cpp:313
bool isDaylight() const
Check whether it is daylight or not.
Definition Sensor.cpp:335
int getSunriseOffset() const
Get time offset in minutes to sunrise.
Definition Sensor.cpp:317
DaylightSensor(Sensor sensor)
Construct from generic sensor.
Definition Sensor.h:283
void setCoordinates(const std::string &latitude, const std::string &longitude)
Set GPS coordinates for the calculation.
Definition Sensor.cpp:298
void setBatteryState(int percent)
Set battery state.
Definition Sensor.cpp:294
bool hasBatteryState() const
Check whether the sensor has a battery state.
Definition Sensor.cpp:286
void setOn(bool on)
Enable or disable sensor.
Definition Sensor.cpp:281
time::AbsoluteTime getLastUpdated() const
Get time of last status update.
Definition Sensor.cpp:340
One-time, absolute time point.
Definition TimePattern.h:73
detail::ConditionHelper< bool > makeCondition(const CLIPOpenClose &sensor)
Definition CLIPSensors.cpp:103
detail::ConditionHelper< time::AbsoluteTime > makeConditionLastUpdate(const SensorT &sensor)
Definition Sensor.h:363
Namespace for the hueplusplus library.
Definition Action.h:28
std::string alertToString(Alert alert)
Convert alert to string form.
Definition Sensor.cpp:30
Alert alertFromString(const std::string &s)
Convert string to Alert enum.
Definition Sensor.cpp:44
Alert
Specifies light alert modes.
Definition Sensor.h:39
@ lselect
Long select alert (15s breathe)
@ select
Select alert (breathe cycle)
Contains information about error location, use CURRENT_FILE_INFO to create.
Definition HueException.h:35