本文整理汇总了Python中phue.Bridge方法的典型用法代码示例。如果您正苦于以下问题:Python phue.Bridge方法的具体用法?Python phue.Bridge怎么用?Python phue.Bridge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类phue
的用法示例。
在下文中一共展示了phue.Bridge方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import phue [as 别名]
# 或者: from phue import Bridge [as 别名]
def __init__(self, num, ip, nameMap=None):
super(DriverHue, self).__init__(num)
if nameMap and len(nameMap) != self.numLEDs:
raise ValueError(
"nameMap must have the same number of entries as the number of LEDs.")
self._bridge = Bridge(ip)
self._bridge.connect()
self._transitionTime = 0
self._brightness = 254
if nameMap:
self._lights = self._bridge.get_light_objects('name')
self._ids = nameMap
else:
self._lights = self._bridge.get_light_objects('id')
self._ids = [l for l in self._lights]
if len(self._lights) < self.numLEDs:
raise ValueError(
"More LEDs were specified than there are available Hue lights.")
self.setTransitionTime(0) # start with no transition time
示例2: try_bridge_connection
# 需要导入模块: import phue [as 别名]
# 或者: from phue import Bridge [as 别名]
def try_bridge_connection(self, cb):
import phue
while True:
try:
bridge = phue.Bridge(ip=self.selected_bridge)
except phue.PhueRegistrationException:
time.sleep(1)
except Exception:
import traceback
traceback.print_exc()
break
else:
self.bridge = bridge
break
GLib.idle_add(cb)
示例3: _register_with_bridge
# 需要导入模块: import phue [as 别名]
# 或者: from phue import Bridge [as 别名]
def _register_with_bridge(self):
"""
Helper for connecting to the bridge. If we don't
have a valid username for the bridge (ip) we are trying
to use, this will cause one to be generated.
"""
self.speak_dialog('connect.to.bridge')
i = 0
while i < 30:
sleep(1)
try:
self.bridge = Bridge(self.ip)
except PhueRegistrationException:
continue
else:
break
if not self.connected:
self.speak_dialog('failed.to.register')
else:
self.speak_dialog('successfully.registered')
示例4: create_lights
# 需要导入模块: import phue [as 别名]
# 或者: from phue import Bridge [as 别名]
def create_lights(self, light_ids):
reachable_lights = None
try:
reachable_lights = self.filter_reachable(light_ids)
except ConnectionResetError:
# TODO: add a library wrapper to handle the issue properly, this is a workaround
logger.error("Hue Bridge not reachable, handle exception")
except socket.error as socketerror:
logger.error("Socket Error: ", socketerror)
if not reachable_lights:
lights = EmptyLightSet()
elif len(reachable_lights) > 10:
lights = Group(self.bridge, reachable_lights, self.group_num, self.first)
else:
lights = LightSet(self.bridge, reachable_lights, self.group_num, self.first)
return lights
示例5: run
# 需要导入模块: import phue [as 别名]
# 或者: from phue import Bridge [as 别名]
def run(self):
prev_sync_time = time()
prev_update_time = time()
while not self.stopped:
now = time()
if self.delta and now - prev_update_time >= self.lights.update_interval:
self.send_updates()
self.delta = 0
prev_update_time = now
if now - max([prev_sync_time, prev_update_time]) >= self.lights.sync_interval:
try:
self.lights.update_state()
except ConnectionResetError:
# TODO: add a library wrapper to handle the issue properly, this is a workaround
logger.error("connection with Hue Bridge reset by peer, handle exception")
except socket.error as socketerror:
logger.error("Socket Error: ", socketerror)
prev_sync_time = now
sleep(0.05)
示例6: parse_args
# 需要导入模块: import phue [as 别名]
# 或者: from phue import Bridge [as 别名]
def parse_args():
"""
This method creates an ArgumentParser object, creates and defines all
arguments to be used by run_sms_bot.py, and returns all captured
arguments as an argparse object"""
## create parser
parser = argparse.ArgumentParser(description='''Run Alfred, a simple
Flask app which recieves messages sent to a Twilio number and returns
a response back to the sender. This app interacts with other APIs
such as the Philips Hues API, WolframAlpha API, and OWM API in order
to carry out actions.''')
## add arguments
# --config
parser.add_argument('--config', metavar = '<configuration file>',
type = str, help = '''Enter the path to the configuration file. Default is
at src/config.ini''', default = 'config.ini')
# --connectBridge
parser.add_argument('--connectBridge', action = 'store_true', help = '''If
you intend to use the script with you Hue Bridge, set this to True when you
run the script for the first time''', default = False)
# --test
parser.add_argument('--test', action = 'store_true', help = '''Pass this flag
in order to run a testing loop which allows you to enter text to Alfred from the
command line''', default = False)
# --setup
parser.add_argument('--setup', action = 'store_true', help = '''Pass this flag
in order to run a guided setup with Alfred''', default = False)
try:
arguments = parser.parse_args()
except:
parser.print_help()
sys.exit(0)
return arguments
示例7: find_bridge
# 需要导入模块: import phue [as 别名]
# 或者: from phue import Bridge [as 别名]
def find_bridge(self):
try:
bridge = phue.Bridge(self.bridge_address)
bridge.connect()
return bridge
except phue.PhueRegistrationException:
logging.info("hue: No bridge registered, press button on bridge and try again")
self.say(_("No bridge registered, press button on bridge and try again"))
# Power: Shutdown or reboot the pi
# ================================
# Shuts down the pi or reboots with a response
#
示例8: connect
# 需要导入模块: import phue [as 别名]
# 或者: from phue import Bridge [as 别名]
def connect(self):
""" Connect to Phillips Hue Hub """
# pylint: disable=broad-except
# get hub settings
hub = self.nodes['hub']
ip_addr = '{}.{}.{}.{}'.format(
hub.get_driver('GV1')[0], hub.get_driver('GV2')[0],
hub.get_driver('GV3')[0], hub.get_driver('GV4')[0])
# try to authenticate with the hub
try:
self.hub = phue.Bridge(
ip_addr, config_file_path=os.path.join(os.getcwd(), 'bridges'))
except phue.PhueRegistrationException:
self.poly.send_error('IP Address OK. Node Server not registered.')
return False
except Exception:
self.poly.send_error('Cannot find hub at {}'.format(ip_addr))
return False # bad ip Addressse:
else:
# ensure hub is connectable
api = self._get_api()
if api:
hub.set_driver('GV5', 1)
hub.report_driver()
return True
else:
self.hub = None
return False
示例9: _get_api
# 需要导入模块: import phue [as 别名]
# 或者: from phue import Bridge [as 别名]
def _get_api(self):
""" get hue hub api data. """
try:
api = self.hub.get_api()
except BadStatusLine:
self.poly.send_error('Hue Bridge returned bad status line.')
return False
except phue.PhueRequestTimeout:
self.poly.send_error('Timed out trying to connect to Hue Bridge.')
return False
except socket.error:
self.poly.send_error("Can't contact Hue Bridge. " +
"Network communication issue.")
return False
return api
示例10: discover
# 需要导入模块: import phue [as 别名]
# 或者: from phue import Bridge [as 别名]
def discover():
args = getargs()
pp = pprint.PrettyPrinter()
bridge = phue.Bridge(config_file_path=args.conf)
bridge.connect()
print("List of Groups")
pp.pprint(bridge.groups)
print("List of Scenes")
pp.pprint(bridge.scenes)
示例11: __init__
# 需要导入模块: import phue [as 别名]
# 或者: from phue import Bridge [as 别名]
def __init__(self, hue_bridge_ip, state):
"""Connect to Hue bridge and set up callback handlers in state."""
self.bridge = Bridge(hue_bridge_ip)
self.all_lights = AllLights(self.bridge)
print("HueBot connected with Hue Bridge!")
state.on_failure = self.indicate_failure
state.on_warning = self.indicate_warning
state.on_normal = self.back_to_normal
示例12: _connect
# 需要导入模块: import phue [as 别名]
# 或者: from phue import Bridge [as 别名]
def _connect(self, host, username):
if host and username:
self.bridge = phue.Bridge(
self.host,
username=username
)
self._init()
else:
self._setup()
示例13: __init__
# 需要导入模块: import phue [as 别名]
# 或者: from phue import Bridge [as 别名]
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._bridge = None
self.available_bridges = {}
self.selected_bridge = None
self.connect('prepare', self._on_prepare)
self.set_position(Gtk.WindowPosition.CENTER)
geometry = Gdk.Geometry()
geometry.min_height = 450
geometry.min_width = 500
self.set_geometry_hints(None, geometry, Gdk.WindowHints.MIN_SIZE)
builder = Gtk.Builder()
builder.add_from_resource(get_resource_path('ui/setup.ui'))
builder.connect_signals(self)
self.search_page = builder.get_object('search-page')
self.append_page(self.search_page)
self.set_page_title(self.search_page, 'Discover Bridge(s)')
self.set_page_type(self.search_page, Gtk.AssistantPageType.INTRO)
self.results_list = builder.get_object('results-list')
self.results_page = builder.get_object('results-page')
self.append_page(self.results_page)
self.set_page_title(self.results_page, 'Select Bridge')
self.set_page_type(self.results_page, Gtk.AssistantPageType.CONTENT)
self.link_button_page = builder.get_object('link-button-page')
self.append_page(self.link_button_page)
self.set_page_title(self.link_button_page, 'Establish Connection')
self.set_page_type(self.link_button_page, Gtk.AssistantPageType.CUSTOM)
示例14: _attempt_connection
# 需要导入模块: import phue [as 别名]
# 或者: from phue import Bridge [as 别名]
def _attempt_connection(self):
"""
This will attempt to connect to the bridge,
but will not handle any errors on it's own.
Raises
------
UnauthorizedUserException
If self.username is not None, and is not registered with the bridge
"""
if self.user_supplied_ip:
self.ip = self.config.get('ip')
else:
self.ip = _discover_bridge()
if self.username:
url = 'http://{ip}/api/{user}'.format(ip=self.ip,
user=self.username)
data = get(url).json()
data = data[0] if isinstance(data, list) else data
error = data.get('error')
if error:
description = error.get('description')
if description == "unauthorized user":
raise UnauthorizedUserException(self.username)
else:
raise Exception('Unknown Error: {0}'.format(description))
self.bridge = Bridge(self.ip, self.username)
示例15: homewizard_reconnect
# 需要导入模块: import phue [as 别名]
# 或者: from phue import Bridge [as 别名]
def homewizard_reconnect():
global homewizardBaseUrl
homewizardBaseUrl = homewizard_connect(username, password, local, ip)
#
# Connect to a Hue Bridge
#