Loading...
Searching...
No Matches
Bridge.h
Go to the documentation of this file.
#ifndef INCLUDE_HUEPLUSPLUS_HUE_H
#define INCLUDE_HUEPLUSPLUS_HUE_H
#include <map>
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "APICache.h"
#include "BridgeConfig.h"
#include "BrightnessStrategy.h"
#include "ColorHueStrategy.h"
#include "ColorTemperatureStrategy.h"
#include "Group.h"
#include "HueCommandAPI.h"
#include "HueDeviceTypes.h"
#include "IHttpHandler.h"
#include "Light.h"
#include "ResourceList.h"
#include "Rule.h"
#include "Scene.h"
#include "Schedule.h"
#include "Sensor.h"
#include "SensorList.h"
#include "Utils.h"
#include <nlohmann/json.hpp>
namespace hueplusplus
{
// forward declarations
class Bridge;
class BridgeFinder
{
public:
struct BridgeIdentification
{
std::string ip;
int port = 80;
std::string mac;
};
public:
BridgeFinder(std::shared_ptr<const IHttpHandler> handler);
std::vector<BridgeIdentification> findBridges() const;
Bridge getBridge(const BridgeIdentification& identification, bool sharedState = false);
void addUsername(const std::string& mac, const std::string& username);
void addClientKey(const std::string& mac, const std::string& clientkey);
const std::map<std::string, std::string>& getAllUsernames() const;
static std::string normalizeMac(std::string input);
private:
static std::string parseDescription(const std::string& description);
std::map<std::string, std::string> usernames;
std::map<std::string, std::string> clientkeys;
std::shared_ptr<const IHttpHandler> http_handler;
};
class Bridge
{
friend class BridgeFinder;
public:
using LightList = SearchableResourceList<Light>;
using GroupList = GroupResourceList<Group, CreateGroup>;
using ScheduleList = CreateableResourceList<ResourceList<Schedule, int>, CreateSchedule>;
using SceneList = CreateableResourceList<ResourceList<Scene, std::string>, CreateScene>;
using RuleList = CreateableResourceList<ResourceList<Rule, int>, CreateRule>;
public:
Bridge(const std::string& ip, const int port, const std::string& username,
std::shared_ptr<const IHttpHandler> handler, const std::string& clientkey = "",
std::chrono::steady_clock::duration refreshDuration = std::chrono::seconds(10), bool sharedState = false);
void refresh();
void setRefreshDuration(std::chrono::steady_clock::duration refreshDuration);
std::string getBridgeIP() const;
bool startStreaming(std::string group_identifier);
bool stopStreaming(std::string group_identifier);
int getBridgePort() const;
std::string requestUsername();
std::string getUsername() const;
std::string getClientKey() const;
void setIP(const std::string& ip);
void setPort(const int port);
BridgeConfig& config();
const BridgeConfig& config() const;
LightList& lights();
const LightList& lights() const;
GroupList& groups();
const GroupList& groups() const;
ScheduleList& schedules();
const ScheduleList& schedules() const;
SceneList& scenes();
const SceneList& scenes() const;
SensorList& sensors();
const SensorList& sensors() const;
RuleList& rules();
const RuleList& rules() const;
private:
void setHttpHandler(std::shared_ptr<const IHttpHandler> handler);
private:
std::string ip;
std::string username;
std::string clientkey;
int port;
std::shared_ptr<const IHttpHandler> http_handler;
std::chrono::steady_clock::duration refreshDuration;
std::shared_ptr<APICache> stateCache;
detail::MakeCopyable<LightList> lightList;
detail::MakeCopyable<GroupList> groupList;
detail::MakeCopyable<ScheduleList> scheduleList;
detail::MakeCopyable<SceneList> sceneList;
detail::MakeCopyable<SensorList> sensorList;
detail::MakeCopyable<RuleList> ruleList;
detail::MakeCopyable<BridgeConfig> bridgeConfig;
bool sharedState;
};
} // namespace hueplusplus
#endif
APICache.h
BridgeConfig.h
username
const std::string username
Definition BridgeSetup.cpp:47
BrightnessStrategy.h
ColorHueStrategy.h
ColorTemperatureStrategy.h
Group.h
HueCommandAPI.h
HueDeviceTypes.h
IHttpHandler.h
Light.h
ResourceList.h
Rule.h
Scene.h
Schedule.h
Sensor.h
SensorList.h
Utils.h
hueplusplus::BridgeConfig
General bridge configuration properties.
Definition BridgeConfig.h:56
hueplusplus::BridgeFinder::BridgeFinder
BridgeFinder(std::shared_ptr< const IHttpHandler > handler)
Constructor of BridgeFinder class.
Definition Bridge.cpp:41
hueplusplus::BridgeFinder::findBridges
std::vector< BridgeIdentification > findBridges() const
Finds all bridges in the network and returns them.
Definition Bridge.cpp:43
hueplusplus::BridgeFinder::getBridge
Bridge getBridge(const BridgeIdentification &identification, bool sharedState=false)
Gets a Hue bridge based on its identification.
Definition Bridge.cpp:78
hueplusplus::BridgeFinder::addUsername
void addUsername(const std::string &mac, const std::string &username)
Function that adds a username to the usernames map.
Definition Bridge.cpp:109
hueplusplus::BridgeFinder::getAllUsernames
const std::map< std::string, std::string > & getAllUsernames() const
Function that returns a map of mac addresses and usernames.
Definition Bridge.cpp:119
hueplusplus::BridgeFinder::addClientKey
void addClientKey(const std::string &mac, const std::string &clientkey)
Function that adds a client key to the clientkeys map.
Definition Bridge.cpp:114
hueplusplus::BridgeFinder::normalizeMac
static std::string normalizeMac(std::string input)
Normalizes mac address to plain hex number.
Definition Bridge.cpp:124
hueplusplus::Bridge
Bridge class for a bridge.
Definition Bridge.h:139
hueplusplus::Bridge::ScheduleList
CreateableResourceList< ResourceList< Schedule, int >, CreateSchedule > ScheduleList
Definition Bridge.h:145
hueplusplus::Bridge::scenes
SceneList & scenes()
Provides access to the Scenes on the bridge.
Definition Bridge.cpp:370
hueplusplus::Bridge::BridgeFinder
friend class BridgeFinder
Definition Bridge.h:140
hueplusplus::Bridge::config
BridgeConfig & config()
Provides access to the configuration of the bridge.
Definition Bridge.cpp:330
hueplusplus::Bridge::getBridgeIP
std::string getBridgeIP() const
Function to get the ip address of the hue bridge.
Definition Bridge.cpp:198
hueplusplus::Bridge::LightList
SearchableResourceList< Light > LightList
Definition Bridge.h:143
hueplusplus::Bridge::requestUsername
std::string requestUsername()
Send a username request to the Hue bridge.
Definition Bridge.cpp:208
hueplusplus::Bridge::SceneList
CreateableResourceList< ResourceList< Scene, std::string >, CreateScene > SceneList
Definition Bridge.h:146
hueplusplus::Bridge::RuleList
CreateableResourceList< ResourceList< Rule, int >, CreateRule > RuleList
Definition Bridge.h:147
hueplusplus::Bridge::Bridge
Bridge(const std::string &ip, const int port, const std::string &username, std::shared_ptr< const IHttpHandler > handler, const std::string &clientkey="", std::chrono::steady_clock::duration refreshDuration=std::chrono::seconds(10), bool sharedState=false)
Constructor of Bridge class.
Definition Bridge.cpp:156
hueplusplus::Bridge::GroupList
GroupResourceList< Group, CreateGroup > GroupList
Definition Bridge.h:144
hueplusplus::Bridge::stopStreaming
bool stopStreaming(std::string group_identifier)
Function to set stream mode to active for entertainment mode.
Definition Bridge.cpp:282
hueplusplus::Bridge::lights
LightList & lights()
Provides access to the Lights on the bridge.
Definition Bridge.cpp:340
hueplusplus::Bridge::getUsername
std::string getUsername() const
Function that returns the username.
Definition Bridge.cpp:310
hueplusplus::Bridge::getClientKey
std::string getClientKey() const
Function that returns the client key.
Definition Bridge.cpp:315
hueplusplus::Bridge::groups
GroupList & groups()
Provides access to the Groups on the bridge.
Definition Bridge.cpp:350
hueplusplus::Bridge::startStreaming
bool startStreaming(std::string group_identifier)
Function to set stream mode to active for entertainment mode.
Definition Bridge.cpp:259
hueplusplus::Bridge::rules
RuleList & rules()
Provides access to the Rules on the bridge.
Definition Bridge.cpp:390
hueplusplus::Bridge::refresh
void refresh()
Refreshes the bridge state.
Definition Bridge.cpp:181
hueplusplus::Bridge::getBridgePort
int getBridgePort() const
Function to get the port of the hue bridge.
Definition Bridge.cpp:203
hueplusplus::Bridge::sensors
SensorList & sensors()
Provides access to the Sensors on the bridge.
Definition Bridge.cpp:380
hueplusplus::Bridge::setRefreshDuration
void setRefreshDuration(std::chrono::steady_clock::duration refreshDuration)
Sets refresh interval for the whole bridge state.
Definition Bridge.cpp:186
hueplusplus::Bridge::setPort
void setPort(const int port)
Function to set the port of this class representing a bridge.
Definition Bridge.cpp:325
hueplusplus::Bridge::setIP
void setIP(const std::string &ip)
Function to set the ip address of this class representing a bridge.
Definition Bridge.cpp:320
hueplusplus::Bridge::schedules
ScheduleList & schedules()
Provides access to the Schedules on the bridge.
Definition Bridge.cpp:360
hueplusplus::CreateRule
Parameters for creating a new Rule.
Definition Rule.h:151
hueplusplus::CreateScene
Parameters for creating a new Scene.
Definition Scene.h:268
hueplusplus::CreateSchedule
Parameters for creating a new Schedule.
Definition Schedule.h:151
hueplusplus::CreateableResourceList
Handles a ResourceList where Resources can be added by the user.
Definition ResourceList.h:286
hueplusplus::GroupResourceList
Handles a group list with the special group 0.
Definition ResourceList.h:332
hueplusplus::SearchableResourceList
Handles a ResourceList of physical devices which can be searched for.
Definition ResourceList.h:240
hueplusplus::SensorList
Handles a list of Sensors with type specific getters.
Definition SensorList.h:34
hueplusplus
Namespace for the hueplusplus library.
Definition Action.h:28
hueplusplus::BridgeFinder::BridgeIdentification
Definition Bridge.h:65
hueplusplus::BridgeFinder::BridgeIdentification::ip
std::string ip
Definition Bridge.h:66
hueplusplus::BridgeFinder::BridgeIdentification::mac
std::string mac
Definition Bridge.h:68
hueplusplus::BridgeFinder::BridgeIdentification::port
int port
Definition Bridge.h:67