本文整理汇总了Python中configuration.Configuration.loadConfig方法的典型用法代码示例。如果您正苦于以下问题:Python Configuration.loadConfig方法的具体用法?Python Configuration.loadConfig怎么用?Python Configuration.loadConfig使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类configuration.Configuration
的用法示例。
在下文中一共展示了Configuration.loadConfig方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: runMain
# 需要导入模块: from configuration import Configuration [as 别名]
# 或者: from configuration.Configuration import loadConfig [as 别名]
def runMain():
# First, we import our devices from our configuration file. These will be split into two different groups, those
# controlled by Philips Hue and those controlled by Insteon.
configuration = Configuration()
config = configuration.loadConfig()
hueDevices = {}
insteonDevices = {}
for device in config['devices']['hue']:
hueDevices[device] = config['devices']['hue'][device]
for device in config['devices']['insteon']:
insteonDevices[device] = config['devices']['insteon'][device]
insteon = Insteon()
hue = Hue()
roomba = Roomba()
# Now we set up the voice recognition using Pocketsphinx from CMU Sphinx.
pocketSphinxListener = PocketSphinxListener()
# We want to run forever, or until the user presses control-c, whichever comes first.
while True:
try:
command = pocketSphinxListener.getCommand().lower()
command = command.replace('the', '')
if command.startswith('turn'):
onOrOff = command.split()[1]
deviceName = ''.join(command.split()[2:])
if deviceName in hueDevices:
deviceId = hueDevices[deviceName]['deviceID']
hue.turn(deviceId=deviceId, onOrOff=onOrOff)
if deviceName in insteonDevices:
deviceId = insteonDevices[deviceName]['deviceID']
insteon.turn(deviceId=deviceId, onOrOff=onOrOff)
if deviceName == 'roomba':
roomba.turn(onOrOff)
elif command.startswith('roomba'):
action = ' '.join(command.split()[1:])
if action == 'clean':
roomba.clean()
if action == 'go home':
roomba.goHome()
# This will allow us to be good cooperators and sleep for a second.
# This will give the other greenlets which we have created for talking
# to the Hue and Insteon hubs a chance to run.
gevent.sleep(1)
except (KeyboardInterrupt, SystemExit):
print 'People sometimes make mistakes, Goodbye.'
sys.exit()
except Exception as e:
exc_type, exc_value, exc_traceback = sys.exc_info()
traceback.print_exception(exc_type, exc_value, exc_traceback,
limit=2,
file=sys.stdout)
sys.exit()
示例2: concurrency
# 需要导入模块: from configuration import Configuration [as 别名]
# 或者: from configuration.Configuration import loadConfig [as 别名]
# Coroutine concurrency (http://sdiehl.github.io/gevent-tutorial/#core) imports
import grequests
import gevent
# This method is used as a callback for the asynchronous network communications used to speak to the hub.
# Our version is very simplistic and just outputs the HTTP Response Code to the console.
def printStatus(response, **kwargs):
print "Insteon response was {}".format(response.status_code)
# The following allows us to specify the IP address, username and password in a more friendly JSON configuration file rather than
# hardcoding the values in the Python source.
configuration = Configuration()
config = configuration.loadConfig()
hub = config['insteon']
class Insteon():
def turn(self, deviceId='', onOrOff=''):
if onOrOff == 'on':
self.turnLightOn(deviceId)
if onOrOff == 'off':
self.turnLightOff(deviceId)
def turnLightOn(self, deviceId):
# The grequests library sends the request as soon as we create "job" below. We then yield to the greenlet every hundredth of a second
# in the main update method to ensure we capture the result.
base64string = base64.encodestring(
'%s:%s' % (hub['username'], hub['password'])).replace('\n', '')