Hue.h
4.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/**
\file Hue.h
Copyright Notice\n
Copyright (C) 2017 Jan Rogall - developer\n
Copyright (C) 2017 Moritz Wirger - developer\n
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
**/
#ifndef _HUE_H
#define _HUE_H
#include "HueLight.h"
#include "json/json.h"
#include <map>
#include <memory>
#include <string>
#include <utility>
#include <vector>
// forward declarations
class Hue;
//! Class to find all Hue bridges on the network and create usernames for them.
class HueFinder
{
public:
struct HueIdentification
{
std::string ip;
std::string mac;
};
public:
//! Function that finds all bridges in the network and returns them.\n
//! The user should be given the opportunity to select the correct one based on the mac address.
//! \return vector containing ip and mac of all found bridges
std::vector<HueIdentification> FindBridges() const;
//! Function that gets a \ref Hue bridge based on its identification
//! \param identification \ref HueIdentification that specifies a bridge
//! \return \ref Hue class object
Hue GetBridge(const HueIdentification& identification);
//! Function that adds a \ref username to the \ref usernames map
//! \param mac MAC address of Hue bridge
//! \param username Username that is used to control the Hue bridge
void AddUsername(const std::string& mac, const std::string& username);
//! Function that returns a map of mac addresses and usernames.
//! These should be saved at the end and re-loaded next time, so only one username is generated per bridge.
//! \returns A map mapping mac address to username for every bridge
const std::map<std::string, std::string>& GetAllUsernames() const;
private:
//! Function that sends a username request to the Hue bridge for about 30 seconds, but you have 5 seconds to prepare.\n
//! It returns the username received
//! \param ip String that specifies the ip the request is send to
//! \return String containing username
std::string RequestUsername(const std::string& ip) const;
private:
std::map<std::string, std::string> usernames;
};
//! Hue class
class Hue
{
public:
//! Constructor of Hue class
//! \param ip String that specifies the ip address of the Hue bridge
//! \param username String that specifies the username that is used to control the bridge. This needs to be acquired in \ref requestUsername
Hue(const std::string& ip, const std::string& username);
//! Function to get the ip address of the hue bridge
//! \return string containing ip
std::string getBridgeIP();
//! Function that sends a username request to the Hue bridge for about 30 seconds, but you have 5 seconds to prepare
//! It automatically sets the \ref username variable according to the username received
//! This function should only be called once to acquire a username to control the bridge and the username should be saved for future use
//! \param ip String that specifies the ip the request is send to
void requestUsername(const std::string& ip);
//! Function that returns the \ref username
//! \return String containing \ref username
std::string getUsername();
//! Function to set the ip address of the Hue bridge in this class
//! \param ip String that specifies the ip
void setIP(const std::string ip);
// todo: some intelligence of finding light
//! Function that returns a \HueLight of specified \ref id
//! \param id Integer that specifies the ID of a Hue light
//! \return \ref HueLight that can be controlled
std::unique_ptr<HueLight> getLight(int id);
private:
//! Function that refreshes the local \ref state of the Hue bridge
void refreshState();
private:
std::string ip;
std::string username;
Json::Value state;
};
#endif