本文整理汇总了Python中phue.PhueRegistrationException方法的典型用法代码示例。如果您正苦于以下问题:Python phue.PhueRegistrationException方法的具体用法?Python phue.PhueRegistrationException怎么用?Python phue.PhueRegistrationException使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类phue
的用法示例。
在下文中一共展示了phue.PhueRegistrationException方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: try_bridge_connection
# 需要导入模块: import phue [as 别名]
# 或者: from phue import PhueRegistrationException [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)
示例2: _register_with_bridge
# 需要导入模块: import phue [as 别名]
# 或者: from phue import PhueRegistrationException [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')
示例3: test_change_light_color_no_bridge
# 需要导入模块: import phue [as 别名]
# 或者: from phue import PhueRegistrationException [as 别名]
def test_change_light_color_no_bridge(self, mockedPhue):
mockedPhue.PhueRegistrationException = phue.PhueRegistrationException
bridge = mock.MagicMock()
bridge.connect.side_effect = mockedPhue.PhueRegistrationException(0, "error")
mockedPhue.Bridge.return_value = bridge
action.ChangeLightColor(self._say, "philips-hue", "Lounge Lamp", "0077be").run()
self.assertEqual(self._say_text,
"No bridge registered, press button on bridge and try again")
示例4: find_bridge
# 需要导入模块: import phue [as 别名]
# 或者: from phue import PhueRegistrationException [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
#
示例5: connect
# 需要导入模块: import phue [as 别名]
# 或者: from phue import PhueRegistrationException [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
示例6: _connect_to_bridge
# 需要导入模块: import phue [as 别名]
# 或者: from phue import PhueRegistrationException [as 别名]
def _connect_to_bridge(self, acknowledge_successful_connection=False):
"""
Calls _attempt_connection, handling various exceptions
by either alerting the user to issues with the config/setup,
or registering the application with the bridge.
Parameters
----------
acknowledge_successful_connection : bool
Speak when a successful connection is established.
Returns
-------
bool
True if a connection is established.
"""
try:
self._attempt_connection()
except DeviceNotFoundException:
self.speak_dialog('bridge.not.found')
return False
except ConnectionError:
self.speak_dialog('failed.to.connect')
if self.user_supplied_ip:
self.speak_dialog('ip.in.config')
return False
except socket.error as e:
if 'No route to host' in e.args:
self.speak_dialog('no.route')
else:
self.speak_dialog('failed.to.connect')
return False
except UnauthorizedUserException:
if self.user_supplied_username:
self.speak_dialog('invalid.user')
return False
else:
self._register_with_bridge()
except PhueRegistrationException:
self._register_with_bridge()
if not self.connected:
return False
if acknowledge_successful_connection:
self.speak_dialog('successfully.connected')
self._update_bridge_data()
return True