ColourDevice.h
Go to the documentation of this file.
1 /****
2  * ColourDevice.h
3  *
4  * Copyright 2019 mikee47 <mike@sillyhouse.net>
5  *
6  * This file is part of the HueEmulator Library
7  *
8  * This library is free software: you can redistribute it and/or modify it under the terms of the
9  * GNU General Public License as published by the Free Software Foundation, version 3 or later.
10  *
11  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
12  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13  * See the GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along with this library.
16  * If not, see <https://www.gnu.org/licenses/>.
17  *
18  ****/
19 
20 #pragma once
21 
22 #include "DimmableDevice.h"
23 
24 namespace Hue
25 {
26 class ColourDevice : public DimmableDevice
27 {
28 public:
29  ColourDevice(ID id, const String& name) : DimmableDevice(id, name)
30  {
31  }
32 
33  bool getAttribute(Attribute attr, unsigned& value) const override
34  {
35  switch(attr) {
36  case Attribute::sat:
37  value = sat;
38  return true;
39  case Attribute::hue:
40  value = hue;
41  return true;
42  case Attribute::ct:
43  value = ct;
44  return true;
45  default:
46  return DimmableDevice::getAttribute(attr, value);
47  }
48  }
49 
50  Status setAttribute(Attribute attr, unsigned value, Callback callback) override
51  {
52  switch(attr) {
53  case Attribute::sat:
54  sat = value;
55  return Status::success;
56  case Attribute::hue:
57  hue = value;
58  return Status::success;
59  case Attribute::ct:
60  ct = value;
61  return Status::success;
62  default:
63  return DimmableDevice::setAttribute(attr, value, callback);
64  }
65  }
66 
67 private:
68  uint8_t sat = 0;
69  uint16_t hue = 0;
70  uint16_t ct = 234;
71 };
72 
73 } // namespace Hue
ColourDevice(ID id, const String &name)
Definition: ColourDevice.h:63
The String class.
Definition: WString.h:136
Status setAttribute(Attribute attr, unsigned value, Callback callback) override
Set a device attribute.
Definition: DimmableDevice.h:78
bool getAttribute(Attribute attr, unsigned &value) const override
Get the (cached) device attribute value.
Definition: ColourDevice.h:67
uint32_t ID
Definition: Libraries/HueEmulator/src/include/Hue/Device.h:95
Status
Status of a setAttribute request.
Definition: Libraries/HueEmulator/src/include/Hue/Device.h:60
@ success
The action was performed immediately without error.
Status setAttribute(Attribute attr, unsigned value, Callback callback) override
Set a device attribute.
Definition: ColourDevice.h:84
Delegate< void(Status status, int errorCode)> Callback
Callback invoked when setAttribute() has completed.
Definition: Libraries/HueEmulator/src/include/Hue/Device.h:117
bool getAttribute(Attribute attr, unsigned &value) const override
Get the (cached) device attribute value.
Definition: DimmableDevice.h:67
DimmableDevice(ID id, const String &name)
Definition: DimmableDevice.h:63
Definition: Bridge.h:29
Attribute
Definition: Libraries/HueEmulator/src/include/Hue/Device.h:97