OnOffDevice.h
Go to the documentation of this file.
1 /****
2  * OnOffDevice.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 "Device.h"
23 
24 namespace Hue
25 {
26 class OnOffDevice : public Device
27 {
28 public:
29  OnOffDevice(ID id, const String& name) : id(id), name(name)
30  {
31  }
32 
33  ID getId() const override
34  {
35  return id;
36  }
37 
38  String getName() const override
39  {
40  return name;
41  }
42 
43  bool getAttribute(Attribute attr, unsigned& value) const override
44  {
45  switch(attr) {
46  case Attribute::on:
47  value = on;
48  return true;
49  default:
50  return false;
51  }
52  }
53 
54  Status setAttribute(Attribute attr, unsigned value, Callback callback) override
55  {
56  switch(attr) {
57  case Attribute::on:
58  this->on = value;
59  return Status::success;
60  default:
61  return Status::error;
62  }
63  }
64 
65 private:
66  ID id;
67  String name;
68  bool on{false};
69 };
70 
71 } // namespace Hue
Status setAttribute(Attribute attr, unsigned value, Callback callback) override
Set a device attribute.
Definition: OnOffDevice.h:88
The String class.
Definition: WString.h:136
ID getId() const override
Definition: OnOffDevice.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.
Delegate< void(Status status, int errorCode)> Callback
Callback invoked when setAttribute() has completed.
Definition: Libraries/HueEmulator/src/include/Hue/Device.h:117
OnOffDevice(ID id, const String &name)
Definition: OnOffDevice.h:63
bool getAttribute(Attribute attr, unsigned &value) const override
Get the (cached) device attribute value.
Definition: OnOffDevice.h:77
@ error
Action could not be completed.
Definition: Bridge.h:29
Attribute
Definition: Libraries/HueEmulator/src/include/Hue/Device.h:97
String getName() const override
Definition: OnOffDevice.h:72