hueplusplus  1.0.0
Public Types | Public Member Functions | Friends | List of all members
hueplusplus::Bridge Class Reference

Bridge class for a bridge. More...

#include <hueplusplus/Bridge.h>

Public Types

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 Member Functions

 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. More...
 
void refresh ()
 Refreshes the bridge state. More...
 
void setRefreshDuration (std::chrono::steady_clock::duration refreshDuration)
 Sets refresh interval for the whole bridge state. More...
 
std::string getBridgeIP () const
 Function to get the ip address of the hue bridge. More...
 
bool startStreaming (std::string group_identifier)
 Function to set stream mode to active for entertainment mode. More...
 
bool stopStreaming (std::string group_identifier)
 Function to set stream mode to active for entertainment mode. More...
 
int getBridgePort () const
 Function to get the port of the hue bridge. More...
 
std::string requestUsername ()
 Send a username request to the Hue bridge. More...
 
std::string getUsername () const
 Function that returns the username. More...
 
std::string getClientKey () const
 Function that returns the client key. More...
 
void setIP (const std::string &ip)
 Function to set the ip address of this class representing a bridge. More...
 
void setPort (const int port)
 Function to set the port of this class representing a bridge. More...
 
BridgeConfigconfig ()
 Provides access to the configuration of the bridge. More...
 
const BridgeConfigconfig () const
 Provides access to the configuration of the bridge. More...
 
LightListlights ()
 Provides access to the Lights on the bridge. More...
 
const LightListlights () const
 Provides access to the Lights on the bridge. More...
 
GroupListgroups ()
 Provides access to the Groups on the bridge. More...
 
const GroupListgroups () const
 Provides access to the Groups on the bridge. More...
 
ScheduleListschedules ()
 Provides access to the Schedules on the bridge. More...
 
const ScheduleListschedules () const
 Provides access to the Schedules on the bridge. More...
 
SceneListscenes ()
 Provides access to the Scenes on the bridge. More...
 
const SceneListscenes () const
 Provides access to the Scenes on the bridge. More...
 
SensorListsensors ()
 Provides access to the Sensors on the bridge. More...
 
const SensorListsensors () const
 Provides access to the Sensors on the bridge. More...
 
RuleListrules ()
 Provides access to the Rules on the bridge. More...
 
const RuleListrules () const
 Provides access to the Rules on the bridge. More...
 

Friends

class BridgeFinder
 

Detailed Description

Bridge class for a bridge.

This is the main class used to interact with the Hue bridge.

Member Typedef Documentation

◆ GroupList

◆ LightList

◆ RuleList

◆ SceneList

◆ ScheduleList

Constructor & Destructor Documentation

◆ Bridge()

hueplusplus::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.

Parameters
ipIP address in dotted decimal notation like "192.168.2.1"
portPort of the hue bridge
usernameString that specifies the username that is used to control the bridge. Can be left empty and acquired in requestUsername.
handlerHttpHandler for communication with the bridge
clientkeyOptional client key for streaming
refreshDurationTime between refreshing the cached state.
sharedStateUses a single, shared cache for all objects on the bridge.

Member Function Documentation

◆ config() [1/2]

BridgeConfig & hueplusplus::Bridge::config ( )

Provides access to the configuration of the bridge.

◆ config() [2/2]

const BridgeConfig & hueplusplus::Bridge::config ( ) const

Provides access to the configuration of the bridge.

Note
Does not refresh state.

◆ getBridgeIP()

std::string hueplusplus::Bridge::getBridgeIP ( ) const

Function to get the ip address of the hue bridge.

Returns
string containing ip

◆ getBridgePort()

int hueplusplus::Bridge::getBridgePort ( ) const

Function to get the port of the hue bridge.

Returns
integer containing port

◆ getClientKey()

std::string hueplusplus::Bridge::getClientKey ( ) const

Function that returns the client key.

Returns
The client key used for Entertainment Mode API access

◆ getUsername()

std::string hueplusplus::Bridge::getUsername ( ) const

Function that returns the username.

Returns
The username used for API access

◆ groups() [1/2]

Bridge::GroupList & hueplusplus::Bridge::groups ( )

Provides access to the Groups on the bridge.

◆ groups() [2/2]

const Bridge::GroupList & hueplusplus::Bridge::groups ( ) const

Provides access to the Groups on the bridge.

Note
Does not refresh state.

◆ lights() [1/2]

Bridge::LightList & hueplusplus::Bridge::lights ( )

Provides access to the Lights on the bridge.

◆ lights() [2/2]

const Bridge::LightList & hueplusplus::Bridge::lights ( ) const

Provides access to the Lights on the bridge.

Note
Does not refresh state.

◆ refresh()

void hueplusplus::Bridge::refresh ( )

Refreshes the bridge state.

Should only be called rarely, as a full refresh is costly and usually not necessary. Instead refresh only the parts you are interested in or rely on periodic refreshes that happen automatically when calling non-const methods.

Exceptions
std::system_errorwhen system or socket operations fail
HueExceptionwhen response contained no body
HueAPIResponseExceptionwhen response contains an error
nlohmann::json::parse_errorwhen response could not be parsed

◆ requestUsername()

std::string hueplusplus::Bridge::requestUsername ( )

Send a username request to the Hue bridge.

Blocks for about 30 seconds and 5 seconds to prepare. It automatically sets the username variable according to the username received and returns 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.

Returns
username for API usage
Exceptions
std::system_errorwhen system or socket operations fail
HueExceptionwhen response contained no body
HueAPIResponseExceptionwhen response contains an error except link button not pressed.
nlohmann::json::parse_errorwhen response could not be parsed

◆ rules() [1/2]

Bridge::RuleList & hueplusplus::Bridge::rules ( )

Provides access to the Rules on the bridge.

◆ rules() [2/2]

const Bridge::RuleList & hueplusplus::Bridge::rules ( ) const

Provides access to the Rules on the bridge.

Note
Does not refresh state.

◆ scenes() [1/2]

Bridge::SceneList & hueplusplus::Bridge::scenes ( )

Provides access to the Scenes on the bridge.

◆ scenes() [2/2]

const Bridge::SceneList & hueplusplus::Bridge::scenes ( ) const

Provides access to the Scenes on the bridge.

Note
Does not refresh state.

◆ schedules() [1/2]

Bridge::ScheduleList & hueplusplus::Bridge::schedules ( )

Provides access to the Schedules on the bridge.

◆ schedules() [2/2]

const Bridge::ScheduleList & hueplusplus::Bridge::schedules ( ) const

Provides access to the Schedules on the bridge.

Note
Does not refresh state.

◆ sensors() [1/2]

hueplusplus::SensorList & hueplusplus::Bridge::sensors ( )

Provides access to the Sensors on the bridge.

◆ sensors() [2/2]

const hueplusplus::SensorList & hueplusplus::Bridge::sensors ( ) const

Provides access to the Sensors on the bridge.

Note
Does not refresh state.

◆ setIP()

void hueplusplus::Bridge::setIP ( const std::string &  ip)

Function to set the ip address of this class representing a bridge.

Parameters
ipString that specifies the ip in dotted decimal notation like "192.168.2.1"

◆ setPort()

void hueplusplus::Bridge::setPort ( const int  port)

Function to set the port of this class representing a bridge.

Parameters
portInteger that specifies the port of an address like "192.168.2.1:8080"

◆ setRefreshDuration()

void hueplusplus::Bridge::setRefreshDuration ( std::chrono::steady_clock::duration  refreshDuration)

Sets refresh interval for the whole bridge state.

Parameters
refreshDurationThe new minimum duration between refreshes. May be 0 or c_refreshNever.

Also sets refresh duration on all resource lists on the bridge, but not on already existing lights. The resource lists (such as lights()) can have their own durations, but those must be set after calling this function.

◆ startStreaming()

bool hueplusplus::Bridge::startStreaming ( std::string  group_identifier)

Function to set stream mode to active for entertainment mode.

Returns
bool - whether stream request was successful

◆ stopStreaming()

bool hueplusplus::Bridge::stopStreaming ( std::string  group_identifier)

Function to set stream mode to active for entertainment mode.

Returns
bool - whether stream request was successful

Friends And Related Function Documentation

◆ BridgeFinder

friend class BridgeFinder
friend

The documentation for this class was generated from the following files: