hueplusplus  1.0.0
Light.h
Go to the documentation of this file.
1 
23 #ifndef INCLUDE_HUEPLUSPLUS_HUE_LIGHT_H
24 #define INCLUDE_HUEPLUSPLUS_HUE_LIGHT_H
25 
26 #include <memory>
27 
28 #include "APICache.h"
29 #include "BaseDevice.h"
30 #include "BrightnessStrategy.h"
31 #include "ColorHueStrategy.h"
33 #include "HueCommandAPI.h"
34 #include "StateTransaction.h"
35 
36 #include "json/json.hpp"
37 
38 namespace hueplusplus
39 {
40 
42 enum class ColorType
43 {
44  UNDEFINED,
45  NONE,
46  GAMUT_A,
47  GAMUT_B,
48  GAMUT_C,
49  TEMPERATURE,
53  GAMUT_OTHER,
55 };
56 
60 class Light : public BaseDevice
61 {
62  friend class LightFactory;
64  friend class SimpleColorHueStrategy;
68 
69 public:
72 
77  virtual std::string getLuminaireUId() const;
78 
82  virtual ColorType getColorType() const;
83 
86  ColorGamut getColorGamut() const;
87 
91 
100  virtual bool on(uint8_t transition = 4);
101 
110  virtual bool off(uint8_t transition = 4);
111 
119  virtual bool isOn();
120 
125  virtual bool isOn() const;
126 
131  virtual bool hasBrightnessControl() const { return brightnessStrategy != nullptr; };
132 
138  virtual bool hasTemperatureControl() const { return colorTemperatureStrategy != nullptr; };
139 
144  virtual bool hasColorControl() const { return colorHueStrategy != nullptr; };
145 
158  virtual bool setBrightness(unsigned int bri, uint8_t transition = 4)
159  {
160  if (brightnessStrategy)
161  {
162  return brightnessStrategy->setBrightness(bri, transition, *this);
163  }
164  return false;
165  };
166 
173  virtual unsigned int getBrightness() const
174  {
175  if (brightnessStrategy)
176  {
177  return brightnessStrategy->getBrightness(*this);
178  }
179  return 0;
180  };
181 
192  virtual unsigned int getBrightness()
193  {
194  if (brightnessStrategy)
195  {
196  return brightnessStrategy->getBrightness(*this);
197  }
198  return 0;
199  };
200 
213  virtual bool setColorTemperature(unsigned int mired, uint8_t transition = 4)
214  {
215  if (colorTemperatureStrategy)
216  {
217  return colorTemperatureStrategy->setColorTemperature(mired, transition, *this);
218  }
219  return false;
220  };
221 
231  virtual unsigned int getColorTemperature() const
232  {
233  if (colorTemperatureStrategy)
234  {
235  return colorTemperatureStrategy->getColorTemperature(*this);
236  }
237  return 0;
238  };
239 
252  virtual unsigned int getColorTemperature()
253  {
254  if (colorTemperatureStrategy)
255  {
256  return colorTemperatureStrategy->getColorTemperature(*this);
257  }
258  return 0;
259  };
260 
273  virtual bool setColorHue(uint16_t hue, uint8_t transition = 4)
274  {
275  if (colorHueStrategy)
276  {
277  return colorHueStrategy->setColorHue(hue, transition, *this);
278  }
279  return false;
280  };
281 
294  virtual bool setColorSaturation(uint8_t sat, uint8_t transition = 4)
295  {
296  if (colorHueStrategy)
297  {
298  return colorHueStrategy->setColorSaturation(sat, transition, *this);
299  }
300  return false;
301  };
302 
315  virtual bool setColorHueSaturation(const HueSaturation& hueSat, uint8_t transition = 4)
316  {
317  if (colorHueStrategy)
318  {
319  return colorHueStrategy->setColorHueSaturation(hueSat, transition, *this);
320  }
321  return false;
322  };
323 
336  {
337  if (colorHueStrategy)
338  {
339  return colorHueStrategy->getColorHueSaturation(*this);
340  }
341  return {};
342  };
343 
356  {
357  if (colorHueStrategy)
358  {
359  return colorHueStrategy->getColorHueSaturation(*this);
360  }
361  return {};
362  };
363 
375  virtual bool setColorXY(const XYBrightness& xy, uint8_t transition = 4)
376  {
377  if (colorHueStrategy)
378  {
379  return colorHueStrategy->setColorXY(xy, transition, *this);
380  }
381  return false;
382  };
383 
390  virtual XYBrightness getColorXY() const
391  {
392  if (colorHueStrategy)
393  {
394  return colorHueStrategy->getColorXY(*this);
395  }
396  return {};
397  };
398 
410  {
411  if (colorHueStrategy)
412  {
413  return colorHueStrategy->getColorXY(*this);
414  }
415  return {};
416  }
417 
431  virtual bool setColorRGB(const RGB& rgb, uint8_t transition = 4)
432  {
433  if (colorHueStrategy)
434  {
435  return colorHueStrategy->setColorXY(rgb.toXY(getColorGamut()), transition, *this);
436  }
437  return false;
438  }
439 
448  virtual bool alert();
449 
461  virtual bool alertTemperature(unsigned int mired)
462  {
463  if (colorTemperatureStrategy)
464  {
465  return colorTemperatureStrategy->alertTemperature(mired, *this);
466  }
467  return false;
468  }
469 
481  virtual bool alertHueSaturation(const HueSaturation& hueSat)
482  {
483  if (colorHueStrategy)
484  {
485  return colorHueStrategy->alertHueSaturation(hueSat, *this);
486  }
487  return false;
488  }
489 
501  virtual bool alertXY(const XYBrightness& xy)
502  {
503  if (colorHueStrategy)
504  {
505  return colorHueStrategy->alertXY(xy, *this);
506  }
507  return false;
508  }
509 
525  virtual bool setColorLoop(bool on)
526  {
527  if (colorHueStrategy)
528  {
529  return colorHueStrategy->setColorLoop(on, *this);
530  }
531  return false;
532  }
533 
542  virtual StateTransaction transaction();
543 
545 
546 protected:
553  Light(int id, const HueCommandAPI& commands);
554 
561  Light(int id, const std::shared_ptr<APICache>& baseCache);
562 
578  Light(int id, const HueCommandAPI& commands, std::shared_ptr<const BrightnessStrategy> brightnessStrategy,
579  std::shared_ptr<const ColorTemperatureStrategy> colorTempStrategy,
580  std::shared_ptr<const ColorHueStrategy> colorHueStrategy, std::chrono::steady_clock::duration refreshDuration,
581  const nlohmann::json& currentState);
582 
588  virtual void setBrightnessStrategy(std::shared_ptr<const BrightnessStrategy> strat)
589  {
590  brightnessStrategy = std::move(strat);
591  };
592 
598  virtual void setColorTemperatureStrategy(std::shared_ptr<const ColorTemperatureStrategy> strat)
599  {
600  colorTemperatureStrategy = std::move(strat);
601  };
602 
607  virtual void setColorHueStrategy(std::shared_ptr<const ColorHueStrategy> strat)
608  {
609  colorHueStrategy = std::move(strat);
610  };
611 
612 protected:
614 
615  std::shared_ptr<const BrightnessStrategy>
617  std::shared_ptr<const ColorTemperatureStrategy>
619  std::shared_ptr<const ColorHueStrategy>
621 };
622 } // namespace hueplusplus
623 
624 #endif
virtual bool hasTemperatureControl() const
Const function to check whether this light has color temperature control.
Definition: Light.h:138
ColorType
enum that specifies the color type of all HueLights
Definition: Light.h:42
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
light uses Gamut A and has color temperature control
Definition: HueCommandAPI.h:37
Color in RGB.
Definition: ColorUnits.h:109
virtual void setColorHueStrategy(std::shared_ptr< const ColorHueStrategy > strat)
Protected function that sets the colorHue strategy.
Definition: Light.h:607
light uses capabilities to specify a different gamut and has color temperature control ...
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
std::shared_ptr< const ColorHueStrategy > colorHueStrategy
holds a reference to the strategy that handles all color commands
Definition: Light.h:620
light has color temperature control
Class implementing the functions of ColorTemperatureStrategy.
Definition: ExtendedColorTemperatureStrategy.h:32
virtual bool hasColorControl() const
Connst function to check whether this light has full color control.
Definition: Light.h:144
Namespace for the hueplusplus library.
Definition: Action.h:27
light uses Gamut C and has color temperature control
virtual bool alertTemperature(unsigned int mired)
Function that lets the light perform one breath cycle in specified color temperature.
Definition: Light.h:461
ColorType for this light is unknown or undefined.
virtual unsigned int getColorTemperature()
Function that returns the current color temperature of the light.
Definition: Light.h:252
virtual bool alertXY(const XYBrightness &xy)
Function that lets the light perform one breath cycle in specified color.
Definition: Light.h:501
Definition: SimpleColorHueStrategy.h:34
virtual unsigned int getBrightness() const
Const function that returns the brightness of this light.
Definition: Light.h:173
light has no specific ColorType
std::shared_ptr< const BrightnessStrategy > brightnessStrategy
holds a reference to the strategy that handles brightness commands
Definition: Light.h:616
virtual HueSaturation getColorHueSaturation()
Function that returns the current color of the light as hue and saturation.
Definition: Light.h:355
Base class for physical devices connected to the bridge (sensor or light).
Definition: BaseDevice.h:35
virtual XYBrightness getColorXY()
Function that returns the current color of the light as xy.
Definition: Light.h:409
Definition: HueDeviceTypes.h:33
virtual bool hasBrightnessControl() const
Const function to check whether this light has brightness control.
Definition: Light.h:131
Color and brightness in CIE.
Definition: ColorUnits.h:62
Class implementing the functions of BrightnessStrategy.
Definition: SimpleBrightnessStrategy.h:32
light uses capabilities to specify a different gamut
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
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
Definition: ExtendedColorHueStrategy.h:34
ColorType colorType
holds the ColorType of the light
Definition: Light.h:610
virtual bool alertHueSaturation(const HueSaturation &hueSat)
Function that lets the light perform one breath cycle in specified color.
Definition: Light.h:481
Transaction class which can be used for either light or group state.
Definition: StateTransaction.h:61
virtual bool setBrightness(unsigned int bri, uint8_t transition=4)
Function that sets the brightness of this light.
Definition: Light.h:158
virtual void setColorTemperatureStrategy(std::shared_ptr< const ColorTemperatureStrategy > strat)
Protected function that sets the colorTemperature strategy.
Definition: Light.h:598
Class for Hue Light fixtures.
Definition: Light.h:60
virtual unsigned int getColorTemperature() const
Const function that returns the current color temperature of the light.
Definition: Light.h:231
virtual unsigned int getBrightness()
Function that returns the brightness of this light.
Definition: Light.h:192
virtual XYBrightness getColorXY() const
Const function that returns the current color of the light as xy.
Definition: Light.h:390
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
std::shared_ptr< const ColorTemperatureStrategy > colorTemperatureStrategy
holds a reference to the strategy that handles colortemperature commands
Definition: Light.h:618
virtual void setBrightnessStrategy(std::shared_ptr< const BrightnessStrategy > strat)
Protected function that sets the brightness strategy.
Definition: Light.h:588
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
Triangle of representable colors in CIE.
Definition: ColorUnits.h:77
Color in hue and saturation.
Definition: ColorUnits.h:31
virtual HueSaturation getColorHueSaturation() const
Const function that returns the current color of the light as hue and saturation. ...
Definition: Light.h:335
light uses Gamut B and has color temperature control
Class implementing the functions of ColorTemperatureStrategy.
Definition: SimpleColorTemperatureStrategy.h:32
XYBrightness toXY() const
Convert to XYBrightness without clamping.
Definition: ColorUnits.cpp:109
virtual bool setColorLoop(bool on)
Function to turn colorloop effect on/off.
Definition: Light.h:525