diff --git a/include/hueplusplus/CLIPSensors.h b/include/hueplusplus/CLIPSensors.h
new file mode 100644
index 0000000..5233e2d
--- /dev/null
+++ b/include/hueplusplus/CLIPSensors.h
@@ -0,0 +1,219 @@
+/**
+ \file CLIPSensors.h
+ Copyright Notice\n
+ Copyright (C) 2020 Jan Rogall - developer\n
+
+ This file is part of hueplusplus.
+
+ hueplusplus is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ hueplusplus is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with hueplusplus. If not, see .
+ */
+
+#ifndef INCLUDE_HUEPLUSPLUS_CLIP_SENSORS_H
+#define INCLUDE_HUEPLUSPLUS_CLIP_SENSORS_H
+
+#include "Sensor.h"
+
+namespace hueplusplus
+{
+namespace sensors
+{
+class CLIPSwitch : public BaseDevice
+{
+public:
+ CLIPSwitch(Sensor sensor) : BaseDevice(std::move(sensor)) { }
+
+ int getButtonEvent() const;
+
+ static constexpr const char* typeStr = "CLIPSwitch";
+};
+class CLIPOpenClose : public BaseDevice
+{
+public:
+ CLIPOpenClose(Sensor sensor) : BaseDevice(std::move(sensor)) { }
+
+ bool isOn() const;
+ void setOn(bool on);
+
+ bool hasBattery() const;
+ int getBatteryState() const;
+ void setBatteryState(int percent);
+
+ bool isReachable() const;
+
+ bool hasURL() const;
+ std::string getURL() const;
+ void setURL(const std::string& url);
+
+ bool isOpen() const;
+
+ time::AbsoluteTime getLastUpdated() const;
+
+ static constexpr const char* typeStr = "CLIPOpenClose";
+};
+
+class CLIPPresence : public BaseDevice
+{
+public:
+ bool isOn() const;
+ void setOn(bool on);
+
+ bool hasBattery() const;
+ int getBatteryState() const;
+ void setBatteryState(int percent);
+
+ bool isReachable() const;
+
+ bool hasURL() const;
+ std::string getURL() const;
+ void setURL(const std::string& url);
+
+ bool getPresence() const;
+ void setPresence(bool presence);
+
+ time::AbsoluteTime getLastUpdated() const;
+
+ static constexpr const char* typeStr = "CLIPPresence";
+};
+
+class CLIPTemperature : public BaseDevice
+{
+public:
+ CLIPTemperature(Sensor sensor) : BaseDevice(std::move(sensor)) { }
+
+ bool isOn() const;
+ void setOn(bool on);
+
+ bool hasBattery() const;
+ int getBatteryState() const;
+ void setBatteryState(int percent);
+
+ bool isReachable() const;
+
+ bool hasURL() const;
+ std::string getURL() const;
+ void setURL(const std::string& url);
+
+ int getTemperature() const;
+ void setTemperature(int temperature);
+
+ time::AbsoluteTime getLastUpdated() const;
+
+ static constexpr const char* typeStr = "CLIPTemperature";
+};
+class CLIPHumidity : public BaseDevice
+{
+public:
+ CLIPHumidity(Sensor sensor) : BaseDevice(std::move(sensor)) { }
+
+ bool isOn() const;
+ void setOn(bool on);
+
+ bool hasBattery() const;
+ int getBatteryState() const;
+ void setBatteryState(int percent);
+
+ bool isReachable() const;
+
+ bool hasURL() const;
+ std::string getURL() const;
+ void setURL(const std::string& url);
+
+ int getHumidity() const;
+ void setHumidity(int humidity);
+
+ time::AbsoluteTime getLastUpdated() const;
+
+ static constexpr const char* typeStr = "CLIPHumidity";
+};
+class CLIPLightLevel : public BaseDevice
+{
+public:
+ CLIPLightLevel(Sensor sensor) : BaseDevice(std::move(sensor)) { }
+
+ bool isOn() const;
+ void setOn(bool on);
+
+ bool hasBattery() const;
+ int getBatteryState() const;
+ void setBatteryState(int percent);
+
+ bool isReachable() const;
+
+ int getDarkThreshold() const;
+ void setDarkThreshold(int threshold);
+
+ int getThresholdOffset() const;
+ void setThresholdOffset(int offset);
+
+ bool hasURL() const;
+ std::string getURL() const;
+ void setURL(const std::string& url);
+
+ void setLightLevel(int level);
+ int getLightLevel() const;
+ bool isDark() const;
+ bool isDaylight() const;
+
+ static constexpr const char* typeStr = "CLIPLightLevel";
+};
+class CLIPGenericFlag : public BaseDevice
+{
+public:
+ CLIPGenericFlag(Sensor sensor) : BaseDevice(std::move(sensor)) { }
+
+ bool isOn() const;
+ void setOn(bool on);
+
+ bool hasBattery() const;
+ int getBatteryState() const;
+ void setBatteryState(int percent);
+
+ bool isReachable() const;
+
+ bool hasURL() const;
+ std::string getURL() const;
+ void setURL(const std::string& url);
+
+ bool getFlag() const;
+ void setFlag(bool flag);
+
+ static constexpr const char* typeStr = "CLIPGenericFlag";
+};
+class CLIPGenericStatus : public BaseDevice
+{
+public:
+ CLIPGenericStatus(Sensor sensor) : BaseDevice(std::move(sensor)) { }
+
+ bool isOn() const;
+ void setOn(bool on);
+
+ bool hasBattery() const;
+ int getBatteryState() const;
+ void setBatteryState(int percent);
+
+ bool isReachable() const;
+
+ bool hasURL() const;
+ std::string getURL() const;
+ void setURL(const std::string& url);
+
+ int getStatus() const;
+ void setStatus(int status);
+
+ static constexpr const char* typeStr = "CLIPGenericStatus";
+};
+} // namespace sensors
+} // namespace hueplusplus
+
+#endif
diff --git a/include/hueplusplus/Sensor.h b/include/hueplusplus/Sensor.h
index 5e75bf5..ac0efe1 100644
--- a/include/hueplusplus/Sensor.h
+++ b/include/hueplusplus/Sensor.h
@@ -26,13 +26,14 @@
#include "BaseDevice.h"
#include "HueCommandAPI.h"
+#include "TimePattern.h"
#include "json/json.hpp"
namespace hueplusplus
{
//!
-//! Class for Hue sensors
+//! Generic class for Hue sensors
//!
class Sensor : public BaseDevice
{
@@ -42,47 +43,62 @@ public:
//! \brief std dtor
~Sensor() = default;
- //! \brief Function to get button event
- //!
- //! \return integer representing the button event
- //! \throws std::system_error when system or socket operations fail
- //! \throws HueException when response contained no body
- //! \throws HueAPIResponseException when response contains an error
- //! \throws nlohmann::json::parse_error when response could not be parsed
- virtual int getButtonEvent();
-
- //! \brief Const function to get button event
- //!
- //! \note This will not refresh the sensor state
- //! \return integer representing the button event
- virtual int getButtonEvent() const;
-
- //! \brief Function to get sensor status
- //!
- //! \return integer representing the status
- //! \throws std::system_error when system or socket operations fail
- //! \throws HueException when response contained no body
- //! \throws HueAPIResponseException when response contains an error
- //! \throws nlohmann::json::parse_error when response could not be parsed
- virtual int getStatus();
-
- //! \brief Const function to get sensor status
- //!
- //! \note This will not refresh the sensor state
- //! \return integer representing the button event
- virtual int getStatus() const;
-
- //! \brief Const function to check whether this sensor has a button event
- //!
- //! \return Bool that is true when the sensor has specified abilities and false
- //! when not
- virtual bool hasButtonEvent() const;
-
- //! \brief Const function to check whether this sensor has a status
- //!
- //! \return Bool that is true when the sensor has specified abilities and false
- //! when not
- virtual bool hasStatus() const;
+ bool hasOn() const;
+ // Check whether sensor is on. Does not update when off
+ bool isOn() const;
+ void setOn(bool on);
+
+ bool hasBatteryState() const;
+ // Battery state in percent
+ int getBatteryState() const;
+ bool isReachable() const;
+
+ bool hasAlert() const;
+ std::string getLastAlert() const;
+ void sendAlert(const std::string& alert);
+
+ bool hasReachable() const;
+ bool isReachable() const;
+
+ time::AbsoluteTime getLastUpdated() const;
+
+ bool hasUserTest() const;
+ void setUserTest(bool enabled);
+
+ bool hasURL() const;
+ std::string getURL() const;
+ void setURL(const std::string& url);
+
+ std::vector getPendingConfig() const;
+
+ bool hasLEDIndication() const;
+ bool getLEDIndication() const;
+ void setLEDIndication(bool on);
+
+ nlohmann::json getState() const;
+ time::AbsoluteTime getLastUpdated() const;
+
+ bool isCertified() const;
+ bool isPrimary() const;
+
+ template
+ T asSensorType() const
+ {
+ if (getType() != T::type_str)
+ {
+ throw HueException(FileInfo {__FILE__, __LINE__, __func__}, "Sensor type does not match: " + getType());
+ }
+ return T(*this);
+ }
+ template
+ T asSensorType() &&
+ {
+ if (getType() != T::typeStr)
+ {
+ throw HueException(FileInfo {__FILE__, __LINE__, __func__}, "Sensor type does not match: " + getType());
+ }
+ return T(std::move(*this));
+ }
protected:
//! \brief Protected ctor that is used by \ref Bridge class.
@@ -92,6 +108,36 @@ protected:
//! \param refreshDuration Time between refreshing the cached state.
Sensor(int id, const HueCommandAPI& commands, std::chrono::steady_clock::duration refreshDuration);
};
+
+namespace sensors
+{
+class DaylightSensor : public BaseDevice
+{
+public:
+ DaylightSensor(Sensor sensor) : BaseDevice(std::move(sensor)) { }
+
+ bool isOn() const;
+ void setOn(bool on);
+
+ bool hasBattery() const;
+ int getBatteryState() const;
+ void setBatteryState(int percent);
+
+ void setCoordinates(std::string latitude, std::string longitude);
+
+ int getSunriseOffset() const;
+ void setSunriseOffset(int minutes);
+
+ int getSunsetOffeset() const;
+ void setSunsetOffest(int minutes);
+
+ bool isDaylight() const;
+
+ static constexpr const char* typeStr = "Daylight";
+};
+
+} // namespace sensors
+
} // namespace hueplusplus
#endif
diff --git a/include/hueplusplus/ZLLSensors.h b/include/hueplusplus/ZLLSensors.h
new file mode 100644
index 0000000..cfe55bb
--- /dev/null
+++ b/include/hueplusplus/ZLLSensors.h
@@ -0,0 +1,169 @@
+/**
+ \file ZLLSensors.h
+ Copyright Notice\n
+ Copyright (C) 2020 Jan Rogall - developer\n
+
+ This file is part of hueplusplus.
+
+ hueplusplus is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ hueplusplus is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with hueplusplus. If not, see .
+ */
+
+#ifndef INCLUDE_HUEPLUSPLUS_ZLL_SENSORS_H
+#define INCLUDE_HUEPLUSPLUS_ZLL_SENSORS_H
+
+#include "Sensor.h"
+
+namespace hueplusplus
+{
+namespace sensors
+{
+enum class Alert
+{
+ none,
+ select,
+ lselect
+};
+
+class ZGPSwitch : public BaseDevice
+{
+public:
+ ZGPSwitch(Sensor sensor) : BaseDevice(std::move(sensor)) { }
+
+ bool isOn() const;
+ void setOn(bool on);
+
+ int getButtonEvent();
+
+ static constexpr int c_button1 = 34;
+ static constexpr int c_button2 = 16;
+ static constexpr int c_button3 = 17;
+ static constexpr int c_button4 = 18;
+
+ static constexpr const char* typeStr = "ZGPSwitch";
+};
+class ZLLSwitch : public BaseDevice
+{
+public:
+ ZLLSwitch(Sensor sensor) : BaseDevice(std::move(sensor)) { }
+
+ bool isOn() const;
+ void setOn(bool on);
+
+ bool hasBattery() const;
+ int getBatteryState() const;
+
+ Alert getLastAlert() const;
+ void sendAlert(Alert type);
+
+ bool isReachable() const;
+
+ int getButtonEvent() const;
+
+ time::AbsoluteTime getLastUpdated() const;
+
+ static constexpr int c_ON_INITIAL_PRESS = 1000;
+ static constexpr int c_ON_HOLD = 1001;
+ static constexpr int c_ON_SHORT_RELEASED = 1002;
+ static constexpr int c_ON_LONG_RELEASED = 1003;
+ static constexpr int c_UP_INITIAL_PRESS = 2000;
+ static constexpr int c_UP_HOLD = 2001;
+ static constexpr int c_UP_SHORT_RELEASED = 2002;
+ static constexpr int c_UP_LONG_RELEASED = 2003;
+ static constexpr int c_DOWN_INITIAL_PRESS = 3000;
+ static constexpr int c_DOWN_HOLD = 3001;
+ static constexpr int c_DOWN_SHORT_RELEASED = 3002;
+ static constexpr int c_DOWN_LONG_RELEASED = 3003;
+ static constexpr int c_OFF_INITIAL_PRESS = 4000;
+ static constexpr int c_OFF_HOLD = 4001;
+ static constexpr int c_OFF_SHORT_RELEASED = 4002;
+ static constexpr int c_OFF_LONG_RELEASED = 4003;
+
+ static constexpr const char* typeStr = "ZLLSwitch";
+};
+class ZLLPresence : public BaseDevice
+{
+public:
+ ZLLPresence(Sensor sensor) : BaseDevice(std::move(sensor)) { }
+ bool isOn() const;
+ void setOn(bool on);
+
+ bool hasBattery() const;
+ int getBatteryState() const;
+
+ Alert getLastAlert() const;
+ void sendAlert(Alert type);
+
+ bool isReachable() const;
+
+ int getSensitivity() const;
+ int getMaxSensitivity() const;
+ void setSensitivity(int sensitivity);
+
+ bool getPresence() const;
+
+ time::AbsoluteTime getLastUpdated() const;
+
+ static constexpr const char* typeStr = "ZLLPresence";
+};
+
+class ZLLTemperature : public BaseDevice
+{
+public:
+ ZLLTemperature(Sensor sensor) : BaseDevice(std::move(sensor)) { }
+
+ bool isOn() const;
+ void setOn(bool on);
+
+ bool hasBattery() const;
+ int getBatteryState() const;
+
+ Alert getLastAlert() const;
+ void sendAlert(Alert type);
+
+ bool isReachable() const;
+
+ int getTemperature() const;
+
+ static constexpr const char* typeStr = "ZLLTemperature";
+};
+class ZLLLightLevel : public BaseDevice
+{
+public:
+ ZLLLightLevel(Sensor sensor) : BaseDevice(std::move(sensor)) { }
+
+ bool isOn() const;
+ void setOn(bool on);
+
+ bool hasBattery() const;
+ int getBatteryState() const;
+ void setBatteryState(int percent);
+
+ bool isReachable() const;
+
+ int getDarkThreshold() const;
+ void setDarkThreshold(int threshold);
+
+ int getThresholdOffset() const;
+ void setThresholdOffset(int offset);
+
+ int getLightLevel() const;
+ bool isDark() const;
+ bool isDaylight() const;
+
+ static constexpr const char* typeStr = "ZLLLightLevel";
+};
+} // namespace sensors
+} // namespace hueplusplus
+
+#endif