Loading...
Searching...
No Matches
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.
void | refresh ()
| Refreshes the bridge state.
void | setRefreshDuration (std::chrono::steady_clock::duration refreshDuration)
| Sets refresh interval for the whole bridge state.
std::string | getBridgeIP () const
| Function to get the ip address of the hue bridge.
bool | startStreaming (std::string group_identifier)
| Function to set stream mode to active for entertainment mode.
bool | stopStreaming (std::string group_identifier)
| Function to set stream mode to active for entertainment mode.
int | getBridgePort () const
| Function to get the port of the hue bridge.
std::string | requestUsername ()
| Send a username request to the Hue bridge.
std::string | getUsername () const
| Function that returns the username.
std::string | getClientKey () const
| Function that returns the client key.
void | setIP (const std::string &ip)
| Function to set the ip address of this class representing a bridge.
void | setPort (const int port)
| Function to set the port of this class representing a bridge.
BridgeConfig & | config ()
| Provides access to the configuration of the bridge.
const BridgeConfig & | config () const
| Provides access to the configuration of the bridge.
LightList & | lights ()
| Provides access to the Lights on the bridge.
const LightList & | lights () const
| Provides access to the Lights on the bridge.
GroupList & | groups ()
| Provides access to the Groups on the bridge.
const GroupList & | groups () const
| Provides access to the Groups on the bridge.
ScheduleList & | schedules ()
| Provides access to the Schedules on the bridge.
const ScheduleList & | schedules () const
| Provides access to the Schedules on the bridge.
SceneList & | scenes ()
| Provides access to the Scenes on the bridge.
const SceneList & | scenes () const
| Provides access to the Scenes on the bridge.
SensorList & | sensors ()
| Provides access to the Sensors on the bridge.
const SensorList & | sensors () const
| Provides access to the Sensors on the bridge.
RuleList & | rules ()
| Provides access to the Rules on the bridge.
const RuleList & | rules () const
| Provides access to the Rules on the bridge.

## Friends

class | BridgeFinder

## Detailed Description

Bridge class for a bridge.

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

Examples
  BridgeSetup.cpp, LightsOff.cpp, and UsernameConfig.cpp.

## Member Typedef Documentation

## GroupList

using hueplusplus::Bridge::GroupList = GroupResourceList<Group, CreateGroup>

## LightList

using hueplusplus::Bridge::LightList = SearchableResourceList<Light>

## RuleList

using hueplusplus::Bridge::RuleList = CreateableResourceList<ResourceList<Rule, int>, CreateRule>

## SceneList

using hueplusplus::Bridge::SceneList = CreateableResourceList<ResourceList<Scene, std::string>, CreateScene>

## ScheduleList

using hueplusplus::Bridge::ScheduleList = CreateableResourceList<ResourceList<Schedule, int>, CreateSchedule>

## 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

  ip | IP address in dotted decimal notation like "192.168.2.1"
  port | Port of the hue bridge
  username | String that specifies the username that is used to control the bridge. Can be left empty and acquired in requestUsername.
  handler | HttpHandler for communication with the bridge
  clientkey | Optional client key for streaming
  refreshDuration | Time between refreshing the cached state.
  sharedState | Uses 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_error | when system or socket operations fail
  HueException | when response contained no body
  HueAPIResponseException | when response contains an error
  nlohmann::json::parse_error | when 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_error | when system or socket operations fail
  HueException | when response contained no body
  HueAPIResponseException | when response contains an error except link button not pressed.
  nlohmann::json::parse_error | when 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

  ip | String 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

  port | Integer 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

  refreshDuration | The 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 Symbol Documentation

## BridgeFinder

friend class BridgeFinder

friend

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

- include/hueplusplus/Bridge.h
- src/Bridge.cpp