hueplusplus 1.2.0
Loading...
Searching...
No Matches
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 <nlohmann/json.hpp>
37
38namespace hueplusplus
39{
40
56
60class Light : public BaseDevice
61{
62 friend class LightFactory;
68
69public:
72
77 virtual std::string getLuminaireUId() const;
78
82 virtual ColorType getColorType() const;
83
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 {
161 {
162 return brightnessStrategy->setBrightness(bri, transition, *this);
163 }
164 return false;
165 };
166
173 virtual unsigned int getBrightness() const
174 {
176 {
177 return brightnessStrategy->getBrightness(*this);
178 }
179 return 0;
180 };
181
192 virtual unsigned int getBrightness()
193 {
195 {
196 return brightnessStrategy->getBrightness(*this);
197 }
198 return 0;
199 };
200
213 virtual bool setColorTemperature(unsigned int mired, uint8_t transition = 4)
214 {
216 {
217 return colorTemperatureStrategy->setColorTemperature(mired, transition, *this);
218 }
219 return false;
220 };
221
231 virtual unsigned int getColorTemperature() const
232 {
234 {
235 return colorTemperatureStrategy->getColorTemperature(*this);
236 }
237 return 0;
238 };
239
252 virtual unsigned int getColorTemperature()
253 {
255 {
256 return colorTemperatureStrategy->getColorTemperature(*this);
257 }
258 return 0;
259 };
260
273 virtual bool setColorHue(uint16_t hue, uint8_t transition = 4)
274 {
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 {
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 {
318 {
319 return colorHueStrategy->setColorHueSaturation(hueSat, transition, *this);
320 }
321 return false;
322 };
323
336 {
338 {
339 return colorHueStrategy->getColorHueSaturation(*this);
340 }
341 return {};
342 };
343
356 {
358 {
359 return colorHueStrategy->getColorHueSaturation(*this);
360 }
361 return {};
362 };
363
375 virtual bool setColorXY(const XYBrightness& xy, uint8_t transition = 4)
376 {
378 {
379 return colorHueStrategy->setColorXY(xy, transition, *this);
380 }
381 return false;
382 };
383
390 virtual XYBrightness getColorXY() const
391 {
393 {
394 return colorHueStrategy->getColorXY(*this);
395 }
396 return {};
397 };
398
410 {
412 {
413 return colorHueStrategy->getColorXY(*this);
414 }
415 return {};
416 }
417
431 virtual bool setColorRGB(const RGB& rgb, uint8_t transition = 4)
432 {
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 {
464 {
465 return colorTemperatureStrategy->alertTemperature(mired, *this);
466 }
467 return false;
468 }
469
481 virtual bool alertHueSaturation(const HueSaturation& hueSat)
482 {
484 {
485 return colorHueStrategy->alertHueSaturation(hueSat, *this);
486 }
487 return false;
488 }
489
501 virtual bool alertXY(const XYBrightness& xy)
502 {
504 {
505 return colorHueStrategy->alertXY(xy, *this);
506 }
507 return false;
508 }
509
525 virtual bool setColorLoop(bool on)
526 {
528 {
529 return colorHueStrategy->setColorLoop(on, *this);
530 }
531 return false;
532 }
533
543
545
546protected:
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
612protected:
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
Base class for physical devices connected to the bridge (sensor or light).
Definition BaseDevice.h:36
Definition ExtendedColorHueStrategy.h:35
Class implementing the functions of ColorTemperatureStrategy.
Definition ExtendedColorTemperatureStrategy.h:33
Definition HueCommandAPI.h:38
Definition HueDeviceTypes.h:34
Class for Hue Light fixtures.
Definition Light.h:61
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
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
virtual bool alertXY(const XYBrightness &xy)
Function that lets the light perform one breath cycle in specified color.
Definition Light.h:501
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
virtual XYBrightness getColorXY() const
Const function that returns the current color of the light as xy.
Definition Light.h:390
virtual bool isOn()
Function to check whether a light is on or off.
Definition Light.cpp:44
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
virtual StateTransaction transaction()
Create a transaction for this light.
Definition Light.cpp:100
virtual XYBrightness getColorXY()
Function that returns the current color of the light as xy.
Definition Light.h:409
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
virtual bool alertHueSaturation(const HueSaturation &hueSat)
Function that lets the light perform one breath cycle in specified color.
Definition Light.h:481
virtual bool hasTemperatureControl() const
Const function to check whether this light has color temperature control.
Definition Light.h:138
std::shared_ptr< const ColorHueStrategy > colorHueStrategy
holds a reference to the strategy that handles all color commands
Definition Light.h:620
virtual bool off(uint8_t transition=4)
Function that turns the light off.
Definition Light.cpp:39
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 hasColorControl() const
Connst function to check whether this light has full color control.
Definition Light.h:144
virtual void setColorHueStrategy(std::shared_ptr< const ColorHueStrategy > strat)
Protected function that sets the colorHue strategy.
Definition Light.h:607
ColorType colorType
holds the ColorType of the light
Definition Light.h:613
virtual bool alert()
Function that lets the light perform one breath cycle.
Definition Light.cpp:95
virtual HueSaturation getColorHueSaturation()
Function that returns the current color of the light as hue and saturation.
Definition Light.h:355
virtual unsigned int getBrightness() const
Const function that returns the brightness of this light.
Definition Light.h:173
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
ColorGamut getColorGamut() const
Get gamut space of possible light colors.
Definition Light.cpp:64
virtual unsigned int getColorTemperature() const
Const function that returns the current color temperature of the light.
Definition Light.h:231
virtual bool on(uint8_t transition=4)
Function that turns the light on.
Definition Light.cpp:34
virtual unsigned int getColorTemperature()
Function that returns the current color temperature of the light.
Definition Light.h:252
virtual ColorType getColorType() const
Const function that returns the color type of the light.
Definition Light.cpp:59
std::shared_ptr< const ColorTemperatureStrategy > colorTemperatureStrategy
holds a reference to the strategy that handles colortemperature commands
Definition Light.h:618
virtual unsigned int getBrightness()
Function that returns the brightness of this light.
Definition Light.h:192
virtual bool setColorLoop(bool on)
Function to turn colorloop effect on/off.
Definition Light.h:525
virtual bool alertTemperature(unsigned int mired)
Function that lets the light perform one breath cycle in specified color temperature.
Definition Light.h:461
virtual HueSaturation getColorHueSaturation() const
Const function that returns the current color of the light as hue and saturation.
Definition Light.h:335
virtual void setBrightnessStrategy(std::shared_ptr< const BrightnessStrategy > strat)
Protected function that sets the brightness strategy.
Definition Light.h:588
virtual bool hasBrightnessControl() const
Const function to check whether this light has brightness control.
Definition Light.h:131
std::shared_ptr< const BrightnessStrategy > brightnessStrategy
holds a reference to the strategy that handles brightness commands
Definition Light.h:616
virtual std::string getLuminaireUId() const
Const function that returns the luminaireuniqueid of the light.
Definition Light.cpp:54
Class implementing the functions of BrightnessStrategy.
Definition SimpleBrightnessStrategy.h:33
Definition SimpleColorHueStrategy.h:35
Class implementing the functions of ColorTemperatureStrategy.
Definition SimpleColorTemperatureStrategy.h:33
Transaction class which can be used for either light or group state.
Definition StateTransaction.h:62
Namespace for the hueplusplus library.
Definition Action.h:28
ColorType
enum that specifies the color type of all HueLights
Definition Light.h:43
@ UNDEFINED
ColorType for this light is unknown or undefined.
@ GAMUT_A_TEMPERATURE
light uses Gamut A and has color temperature control
@ GAMUT_OTHER_TEMPERATURE
light uses capabilities to specify a different gamut and has color temperature control
@ NONE
light has no specific ColorType
@ TEMPERATURE
light has color temperature control
@ GAMUT_B
light uses Gamut B
@ GAMUT_A
light uses Gamut A
@ GAMUT_B_TEMPERATURE
light uses Gamut B and has color temperature control
@ GAMUT_C_TEMPERATURE
light uses Gamut C and has color temperature control
@ GAMUT_OTHER
light uses capabilities to specify a different gamut
@ GAMUT_C
light uses Gamut C
Triangle of representable colors in CIE.
Definition ColorUnits.h:78
Color in hue and saturation.
Definition ColorUnits.h:32
Color in RGB.
Definition ColorUnits.h:110
XYBrightness toXY() const
Convert to XYBrightness without clamping.
Definition ColorUnits.cpp:109
Color and brightness in CIE.
Definition ColorUnits.h:63