BeeeOn Gateway  v2020.3.1-2-g6f737dc
Platform to interconnect the IoT world
ZWaveNode.h
1 #pragma once
2 
3 #include <set>
4 #include <string>
5 
6 #include <Poco/Timespan.h>
7 
8 namespace BeeeOn {
9 
22 class ZWaveNode {
23 public:
28  struct Identity {
29  const uint32_t home;
30  const uint8_t node;
31 
32  Identity(const uint32_t home, const uint8_t node);
33 
34  Identity &operator =(const Identity &other);
35 
36  bool operator ==(const Identity &other) const;
37  bool operator !=(const Identity &other) const;
38  bool operator <(const Identity &other) const;
39 
40  std::string toString() const;
41  };
42 
48  class CommandClass {
49  public:
50  enum {
51  BASIC = 32,
52  SWITCH_BINARY = 37,
53  SENSOR_BINARY = 48,
54  SENSOR_MULTILEVEL = 49,
55  BATTERY = 128,
56  WAKE_UP = 132,
57  ALARM = 113,
58  };
59 
61  uint8_t id,
62  uint8_t index,
63  uint8_t instance,
64  const std::string &name = "");
65 
69  uint8_t id() const;
70 
74  uint8_t index() const;
75 
79  uint8_t instance() const;
80 
84  std::string name() const;
85 
86  std::string toString() const;
87 
88  bool operator <(const CommandClass &cc) const;
89 
90  private:
91  uint8_t m_id;
92  uint8_t m_index;
93  uint8_t m_instance;
94  std::string m_name;
95  };
96 
102  class Value {
103  public:
104  Value(const ZWaveNode &node,
105  const CommandClass &cc,
106  const std::string &value,
107  const std::string &unit = "");
108 
109  Value(const Identity &node,
110  const CommandClass &cc,
111  const std::string &value,
112  const std::string &unit = "");
113 
117  const Identity &node() const;
118 
122  const CommandClass &commandClass() const;
123 
127  std::string value() const;
128 
132  std::string unit() const;
133 
140  bool asBool() const;
141 
147  uint32_t asHex32() const;
148 
153  double asDouble() const;
154 
163  int asInt(bool floor = false) const;
164 
170  double asCelsius() const;
171 
177  double asLuminance() const;
178 
183  double asPM25() const;
184 
189  Poco::Timespan asTime() const;
190 
191  std::string toString() const;
192 
193  private:
194  Identity m_node;
195  CommandClass m_commandClass;
196  std::string m_value;
197  std::string m_unit;
198  };
199 
203  enum Support {
204  SUPPORT_LISTENING = 0x01,
205  SUPPORT_BEAMING = 0x02,
206  SUPPORT_ROUTING = 0x04,
207  SUPPORT_SECURITY = 0x08,
208  SUPPORT_ZWAVEPLUS = 0x10,
209  };
210 
211  ZWaveNode(const Identity &id, bool controller = false);
212 
216  uint32_t home() const;
217 
221  uint8_t node() const;
222 
226  const Identity &id() const;
227 
232  bool controller() const;
233 
237  void setSupport(uint32_t support);
238 
242  uint32_t support() const;
243 
247  void setProductId(uint16_t id);
248 
252  uint16_t productId() const;
253 
257  void setProduct(const std::string &name);
258 
262  std::string product() const;
263 
267  void setProductType(uint16_t type);
268 
272  uint16_t productType() const;
273 
277  void setVendorId(uint16_t id);
278 
282  uint16_t vendorId() const;
283 
287  void setVendor(const std::string &vendor);
288 
292  std::string vendor() const;
293 
298  void setQueried(bool queried);
299 
303  bool queried() const;
304 
305  void add(const CommandClass &cc);
306  const std::set<CommandClass> &commandClasses() const;
307 
308  std::string toString() const;
309  std::string toInfoString() const;
310 
311  bool operator <(const ZWaveNode &node) const;
312 
313 private:
314  Identity m_id;
315  bool m_controller;
316  bool m_queried;
317  uint32_t m_support;
318  uint16_t m_productId;
319  std::string m_product;
320  uint16_t m_vendorId;
321  std::string m_vendor;
322  uint16_t m_productType;
323  std::set<CommandClass> m_commandClasses;
324 };
325 
326 }
std::string value() const
Definition: ZWaveNode.cpp:109
Command class representation of a Z-Wave value. We support only a subset of command classes that are ...
Definition: ZWaveNode.h:48
uint8_t index() const
Definition: ZWaveNode.cpp:31
uint16_t vendorId() const
Definition: ZWaveNode.cpp:333
void setVendor(const std::string &vendor)
Definition: ZWaveNode.cpp:338
void setProductType(uint16_t type)
Definition: ZWaveNode.cpp:318
Value coming from the Z-Wave network. It holds some data (usually sensor data) and metadata to identi...
Definition: ZWaveNode.h:102
uint16_t productType() const
Definition: ZWaveNode.cpp:323
int asInt(bool floor=false) const
Definition: ZWaveNode.cpp:134
const Identity & node() const
Definition: ZWaveNode.cpp:99
std::string vendor() const
Definition: ZWaveNode.cpp:343
void setProduct(const std::string &name)
Definition: ZWaveNode.cpp:308
double asDouble() const
Definition: ZWaveNode.cpp:129
uint32_t home() const
Definition: ZWaveNode.cpp:268
void setSupport(uint32_t support)
Definition: ZWaveNode.cpp:288
void setVendorId(uint16_t id)
Definition: ZWaveNode.cpp:328
uint8_t instance() const
Definition: ZWaveNode.cpp:36
std::string product() const
Definition: ZWaveNode.cpp:313
uint32_t support() const
Definition: ZWaveNode.cpp:293
uint8_t id() const
Definition: ZWaveNode.cpp:26
Poco::Timespan asTime() const
Definition: ZWaveNode.cpp:189
uint8_t node() const
Definition: ZWaveNode.cpp:273
const CommandClass & commandClass() const
Definition: ZWaveNode.cpp:104
bool controller() const
Definition: ZWaveNode.cpp:283
void setProductId(uint16_t id)
Definition: ZWaveNode.cpp:298
ZWaveNode represents information from the Z-Wave network about a particular node. Each Z-Wave node is...
Definition: ZWaveNode.h:22
std::string unit() const
Definition: ZWaveNode.cpp:114
uint16_t productId() const
Definition: ZWaveNode.cpp:303
double asLuminance() const
Definition: ZWaveNode.cpp:161
bool asBool() const
Definition: ZWaveNode.cpp:119
const Identity & id() const
Definition: ZWaveNode.cpp:278
void setQueried(bool queried)
Definition: ZWaveNode.cpp:348
bool queried() const
Definition: ZWaveNode.cpp:353
double asPM25() const
Definition: ZWaveNode.cpp:180
Support
Feature flags denoting supported features of a Z-Wave node.
Definition: ZWaveNode.h:203
std::string name() const
Definition: ZWaveNode.cpp:41
double asCelsius() const
Definition: ZWaveNode.cpp:146
uint32_t asHex32() const
Definition: ZWaveNode.cpp:124
Identity of a Z-Wave node that can be used separately without any instance of the ZWaveNode class...
Definition: ZWaveNode.h:28