-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add notion of bridge ID * Version bump to 1.10.0
- Loading branch information
Showing
4 changed files
with
38 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
from .bridge import Bridge | ||
from .util import normalize_bridge_id | ||
|
||
URL_NUPNP = 'https://www.meethue.com/api/nupnp' | ||
|
||
|
||
async def discover_nupnp(websession): | ||
"""Discover bridges via NUPNP.""" | ||
async with websession.get(URL_NUPNP) as res: | ||
return [Bridge(item['internalipaddress'], websession=websession) | ||
return [Bridge(item['internalipaddress'], | ||
bridge_id=normalize_bridge_id(item['id']), | ||
websession=websession) | ||
for item in (await res.json())] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
"""Utils for aiohue.""" | ||
import logging | ||
|
||
|
||
def normalize_bridge_id(bridge_id: str): | ||
"""Normalize a bridge identifier.""" | ||
# zeroconf: properties['id'], field contains semicolons after each 2 char | ||
if len(bridge_id) == 17 and sum(True for c in "aa:bb:cc:dd:ee:ff" | ||
if c == ":"): | ||
return bridge_id.replace(':', '') | ||
|
||
# nupnp: contains 4 extra characters in the middle: "fffe" | ||
if len(bridge_id) == 16 and "fffe" in bridge_id: | ||
return bridge_id[0:6] + bridge_id[-6:] | ||
|
||
# SSDP/UPNP and Hue Bridge API contains right ID. | ||
if len(bridge_id) == 12: | ||
return bridge_id | ||
|
||
logging.getLogger(__name__).warn("Received unexpected bridge id: %s", | ||
bridge_id) | ||
|
||
return bridge_id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters