Loading...
Searching...
No Matches
Light.h
Go to the documentation of this file.
#ifndef INCLUDE_HUEPLUSPLUS_HUE_LIGHT_H
#define INCLUDE_HUEPLUSPLUS_HUE_LIGHT_H
#include <memory>
#include "APICache.h"
#include "BaseDevice.h"
#include "BrightnessStrategy.h"
#include "ColorHueStrategy.h"
#include "ColorTemperatureStrategy.h"
#include "HueCommandAPI.h"
#include "StateTransaction.h"
#include <nlohmann/json.hpp>
namespace hueplusplus
{
enum class ColorType
{
UNDEFINED,
NONE,
GAMUT_A,
GAMUT_B,
GAMUT_C,
TEMPERATURE,
GAMUT_A_TEMPERATURE,
GAMUT_B_TEMPERATURE,
GAMUT_C_TEMPERATURE,
GAMUT_OTHER,
GAMUT_OTHER_TEMPERATURE
};
class Light : public BaseDevice
{
friend class LightFactory;
friend class SimpleBrightnessStrategy;
friend class SimpleColorHueStrategy;
friend class ExtendedColorHueStrategy;
friend class SimpleColorTemperatureStrategy;
friend class ExtendedColorTemperatureStrategy;
public:
virtual std::string getLuminaireUId() const;
virtual ColorType getColorType() const;
ColorGamut getColorGamut() const;
virtual bool on(uint8_t transition = 4);
virtual bool off(uint8_t transition = 4);
virtual bool isOn();
virtual bool isOn() const;
virtual bool hasBrightnessControl() const { return brightnessStrategy != nullptr; };
virtual bool hasTemperatureControl() const { return colorTemperatureStrategy != nullptr; };
virtual bool hasColorControl() const { return colorHueStrategy != nullptr; };
virtual bool setBrightness(unsigned int bri, uint8_t transition = 4)
{
if (brightnessStrategy)
{
return brightnessStrategy->setBrightness(bri, transition, *this);
}
return false;
};
virtual unsigned int getBrightness() const
{
if (brightnessStrategy)
{
return brightnessStrategy->getBrightness(*this);
}
return 0;
};
virtual unsigned int getBrightness()
{
if (brightnessStrategy)
{
return brightnessStrategy->getBrightness(*this);
}
return 0;
};
virtual bool setColorTemperature(unsigned int mired, uint8_t transition = 4)
{
if (colorTemperatureStrategy)
{
return colorTemperatureStrategy->setColorTemperature(mired, transition, *this);
}
return false;
};
virtual unsigned int getColorTemperature() const
{
if (colorTemperatureStrategy)
{
return colorTemperatureStrategy->getColorTemperature(*this);
}
return 0;
};
virtual unsigned int getColorTemperature()
{
if (colorTemperatureStrategy)
{
return colorTemperatureStrategy->getColorTemperature(*this);
}
return 0;
};
virtual bool setColorHue(uint16_t hue, uint8_t transition = 4)
{
if (colorHueStrategy)
{
return colorHueStrategy->setColorHue(hue, transition, *this);
}
return false;
};
virtual bool setColorSaturation(uint8_t sat, uint8_t transition = 4)
{
if (colorHueStrategy)
{
return colorHueStrategy->setColorSaturation(sat, transition, *this);
}
return false;
};
virtual bool setColorHueSaturation(const HueSaturation& hueSat, uint8_t transition = 4)
{
if (colorHueStrategy)
{
return colorHueStrategy->setColorHueSaturation(hueSat, transition, *this);
}
return false;
};
virtual HueSaturation getColorHueSaturation() const
{
if (colorHueStrategy)
{
return colorHueStrategy->getColorHueSaturation(*this);
}
return {};
};
virtual HueSaturation getColorHueSaturation()
{
if (colorHueStrategy)
{
return colorHueStrategy->getColorHueSaturation(*this);
}
return {};
};
virtual bool setColorXY(const XYBrightness& xy, uint8_t transition = 4)
{
if (colorHueStrategy)
{
return colorHueStrategy->setColorXY(xy, transition, *this);
}
return false;
};
virtual XYBrightness getColorXY() const
{
if (colorHueStrategy)
{
return colorHueStrategy->getColorXY(*this);
}
return {};
};
virtual XYBrightness getColorXY()
{
if (colorHueStrategy)
{
return colorHueStrategy->getColorXY(*this);
}
return {};
}
virtual bool setColorRGB(const RGB& rgb, uint8_t transition = 4)
{
if (colorHueStrategy)
{
return colorHueStrategy->setColorXY(rgb.toXY(getColorGamut()), transition, *this);
}
return false;
}
virtual bool alert();
virtual bool alertTemperature(unsigned int mired)
{
if (colorTemperatureStrategy)
{
return colorTemperatureStrategy->alertTemperature(mired, *this);
}
return false;
}
virtual bool alertHueSaturation(const HueSaturation& hueSat)
{
if (colorHueStrategy)
{
return colorHueStrategy->alertHueSaturation(hueSat, *this);
}
return false;
}
virtual bool alertXY(const XYBrightness& xy)
{
if (colorHueStrategy)
{
return colorHueStrategy->alertXY(xy, *this);
}
return false;
}
virtual bool setColorLoop(bool on)
{
if (colorHueStrategy)
{
return colorHueStrategy->setColorLoop(on, *this);
}
return false;
}
virtual StateTransaction transaction();
protected:
Light(int id, const HueCommandAPI& commands);
Light(int id, const std::shared_ptr<APICache>& baseCache);
Light(int id, const HueCommandAPI& commands, std::shared_ptr<const BrightnessStrategy> brightnessStrategy,
std::shared_ptr<const ColorTemperatureStrategy> colorTempStrategy,
std::shared_ptr<const ColorHueStrategy> colorHueStrategy, std::chrono::steady_clock::duration refreshDuration,
const nlohmann::json& currentState);
virtual void setBrightnessStrategy(std::shared_ptr<const BrightnessStrategy> strat)
{
brightnessStrategy = std::move(strat);
};
virtual void setColorTemperatureStrategy(std::shared_ptr<const ColorTemperatureStrategy> strat)
{
colorTemperatureStrategy = std::move(strat);
};
virtual void setColorHueStrategy(std::shared_ptr<const ColorHueStrategy> strat)
{
colorHueStrategy = std::move(strat);
};
protected:
ColorType colorType;
std::shared_ptr<const BrightnessStrategy>
brightnessStrategy;
std::shared_ptr<const ColorTemperatureStrategy>
colorTemperatureStrategy;
std::shared_ptr<const ColorHueStrategy>
colorHueStrategy;
};
} // namespace hueplusplus
#endif
APICache.h
BaseDevice.h
BrightnessStrategy.h
ColorHueStrategy.h
ColorTemperatureStrategy.h
HueCommandAPI.h
StateTransaction.h
hueplusplus::BaseDevice
Base class for physical devices connected to the bridge (sensor or light).
Definition BaseDevice.h:36
hueplusplus::ExtendedColorHueStrategy
Definition ExtendedColorHueStrategy.h:35
hueplusplus::ExtendedColorTemperatureStrategy
Class implementing the functions of ColorTemperatureStrategy.
Definition ExtendedColorTemperatureStrategy.h:33
hueplusplus::HueCommandAPI
Definition HueCommandAPI.h:38
hueplusplus::LightFactory
Definition HueDeviceTypes.h:34
hueplusplus::Light
Class for Hue Light fixtures.
Definition Light.h:61
hueplusplus::Light::setColorHue
virtual bool setColorHue(uint16_t hue, uint8_t transition=4)
Function to set the color of this light with specified hue.
Definition Light.h:273
hueplusplus::Light::setColorSaturation
virtual bool setColorSaturation(uint8_t sat, uint8_t transition=4)
Function to set the color of this light with specified saturation.
Definition Light.h:294
hueplusplus::Light::alertXY
virtual bool alertXY(const XYBrightness &xy)
Function that lets the light perform one breath cycle in specified color.
Definition Light.h:501
hueplusplus::Light::setBrightness
virtual bool setBrightness(unsigned int bri, uint8_t transition=4)
Function that sets the brightness of this light.
Definition Light.h:158
hueplusplus::Light::setColorTemperatureStrategy
virtual void setColorTemperatureStrategy(std::shared_ptr< const ColorTemperatureStrategy > strat)
Protected function that sets the colorTemperature strategy.
Definition Light.h:598
hueplusplus::Light::getColorXY
virtual XYBrightness getColorXY() const
Const function that returns the current color of the light as xy.
Definition Light.h:390
hueplusplus::Light::isOn
virtual bool isOn()
Function to check whether a light is on or off.
Definition Light.cpp:44
hueplusplus::Light::setColorHueSaturation
virtual bool setColorHueSaturation(const HueSaturation &hueSat, uint8_t transition=4)
Function to set the color of this light with specified hue and saturation.
Definition Light.h:315
hueplusplus::Light::transaction
virtual StateTransaction transaction()
Create a transaction for this light.
Definition Light.cpp:100
hueplusplus::Light::getColorXY
virtual XYBrightness getColorXY()
Function that returns the current color of the light as xy.
Definition Light.h:409
hueplusplus::Light::setColorRGB
virtual bool setColorRGB(const RGB &rgb, uint8_t transition=4)
Function to set the color of this light with red green and blue values.
Definition Light.h:431
hueplusplus::Light::alertHueSaturation
virtual bool alertHueSaturation(const HueSaturation &hueSat)
Function that lets the light perform one breath cycle in specified color.
Definition Light.h:481
hueplusplus::Light::hasTemperatureControl
virtual bool hasTemperatureControl() const
Const function to check whether this light has color temperature control.
Definition Light.h:138
hueplusplus::Light::colorHueStrategy
std::shared_ptr< const ColorHueStrategy > colorHueStrategy
holds a reference to the strategy that handles all color commands
Definition Light.h:620
hueplusplus::Light::off
virtual bool off(uint8_t transition=4)
Function that turns the light off.
Definition Light.cpp:39
hueplusplus::Light::setColorTemperature
virtual bool setColorTemperature(unsigned int mired, uint8_t transition=4)
Function that sets the color temperature of this light in mired.
Definition Light.h:213
hueplusplus::Light::hasColorControl
virtual bool hasColorControl() const
Connst function to check whether this light has full color control.
Definition Light.h:144
hueplusplus::Light::setColorHueStrategy
virtual void setColorHueStrategy(std::shared_ptr< const ColorHueStrategy > strat)
Protected function that sets the colorHue strategy.
Definition Light.h:607
hueplusplus::Light::colorType
ColorType colorType
holds the ColorType of the light
Definition Light.h:613
hueplusplus::Light::alert
virtual bool alert()
Function that lets the light perform one breath cycle.
Definition Light.cpp:95
hueplusplus::Light::getColorHueSaturation
virtual HueSaturation getColorHueSaturation()
Function that returns the current color of the light as hue and saturation.
Definition Light.h:355
hueplusplus::Light::getBrightness
virtual unsigned int getBrightness() const
Const function that returns the brightness of this light.
Definition Light.h:173
hueplusplus::Light::setColorXY
virtual bool setColorXY(const XYBrightness &xy, uint8_t transition=4)
Function to set the color of this light in CIE with specified x y.
Definition Light.h:375
hueplusplus::Light::getColorGamut
ColorGamut getColorGamut() const
Get gamut space of possible light colors.
Definition Light.cpp:64
hueplusplus::Light::getColorTemperature
virtual unsigned int getColorTemperature() const
Const function that returns the current color temperature of the light.
Definition Light.h:231
hueplusplus::Light::on
virtual bool on(uint8_t transition=4)
Function that turns the light on.
Definition Light.cpp:34
hueplusplus::Light::getColorTemperature
virtual unsigned int getColorTemperature()
Function that returns the current color temperature of the light.
Definition Light.h:252
hueplusplus::Light::getColorType
virtual ColorType getColorType() const
Const function that returns the color type of the light.
Definition Light.cpp:59
hueplusplus::Light::colorTemperatureStrategy
std::shared_ptr< const ColorTemperatureStrategy > colorTemperatureStrategy
holds a reference to the strategy that handles colortemperature commands
Definition Light.h:618
hueplusplus::Light::getBrightness
virtual unsigned int getBrightness()
Function that returns the brightness of this light.
Definition Light.h:192
hueplusplus::Light::setColorLoop
virtual bool setColorLoop(bool on)
Function to turn colorloop effect on/off.
Definition Light.h:525
hueplusplus::Light::alertTemperature
virtual bool alertTemperature(unsigned int mired)
Function that lets the light perform one breath cycle in specified color temperature.
Definition Light.h:461
hueplusplus::Light::getColorHueSaturation
virtual HueSaturation getColorHueSaturation() const
Const function that returns the current color of the light as hue and saturation.
Definition Light.h:335
hueplusplus::Light::setBrightnessStrategy
virtual void setBrightnessStrategy(std::shared_ptr< const BrightnessStrategy > strat)
Protected function that sets the brightness strategy.
Definition Light.h:588
hueplusplus::Light::hasBrightnessControl
virtual bool hasBrightnessControl() const
Const function to check whether this light has brightness control.
Definition Light.h:131
hueplusplus::Light::brightnessStrategy
std::shared_ptr< const BrightnessStrategy > brightnessStrategy
holds a reference to the strategy that handles brightness commands
Definition Light.h:616
hueplusplus::Light::getLuminaireUId
virtual std::string getLuminaireUId() const
Const function that returns the luminaireuniqueid of the light.
Definition Light.cpp:54
hueplusplus::SimpleBrightnessStrategy
Class implementing the functions of BrightnessStrategy.
Definition SimpleBrightnessStrategy.h:33
hueplusplus::SimpleColorHueStrategy
Definition SimpleColorHueStrategy.h:35
hueplusplus::SimpleColorTemperatureStrategy
Class implementing the functions of ColorTemperatureStrategy.
Definition SimpleColorTemperatureStrategy.h:33
hueplusplus::StateTransaction
Transaction class which can be used for either light or group state.
Definition StateTransaction.h:62
hueplusplus
Namespace for the hueplusplus library.
Definition Action.h:28
hueplusplus::ColorType
ColorType
enum that specifies the color type of all HueLights
Definition Light.h:43
hueplusplus::ColorType::UNDEFINED
@ UNDEFINED
ColorType for this light is unknown or undefined.
hueplusplus::ColorType::GAMUT_A_TEMPERATURE
@ GAMUT_A_TEMPERATURE
light uses Gamut A and has color temperature control
hueplusplus::ColorType::GAMUT_OTHER_TEMPERATURE
@ GAMUT_OTHER_TEMPERATURE
light uses capabilities to specify a different gamut and has color temperature control
hueplusplus::ColorType::NONE
@ NONE
light has no specific ColorType
hueplusplus::ColorType::TEMPERATURE
@ TEMPERATURE
light has color temperature control
hueplusplus::ColorType::GAMUT_B
@ GAMUT_B
light uses Gamut B
hueplusplus::ColorType::GAMUT_A
@ GAMUT_A
light uses Gamut A
hueplusplus::ColorType::GAMUT_B_TEMPERATURE
@ GAMUT_B_TEMPERATURE
light uses Gamut B and has color temperature control
hueplusplus::ColorType::GAMUT_C_TEMPERATURE
@ GAMUT_C_TEMPERATURE
light uses Gamut C and has color temperature control
hueplusplus::ColorType::GAMUT_OTHER
@ GAMUT_OTHER
light uses capabilities to specify a different gamut
hueplusplus::ColorType::GAMUT_C
@ GAMUT_C
light uses Gamut C
hueplusplus::ColorGamut
Triangle of representable colors in CIE.
Definition ColorUnits.h:78
hueplusplus::HueSaturation
Color in hue and saturation.
Definition ColorUnits.h:32
hueplusplus::RGB
Color in RGB.
Definition ColorUnits.h:110
hueplusplus::RGB::toXY
XYBrightness toXY() const
Convert to XYBrightness without clamping.
Definition ColorUnits.cpp:109
hueplusplus::XYBrightness
Color and brightness in CIE.
Definition ColorUnits.h:63