本文整理汇总了Python中json.htm方法的典型用法代码示例。如果您正苦于以下问题:Python json.htm方法的具体用法?Python json.htm怎么用?Python json.htm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类json
的用法示例。
在下文中一共展示了json.htm方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: DomoticzAPI
# 需要导入模块: import json [as 别名]
# 或者: from json import htm [as 别名]
def DomoticzAPI(APICall):
resultJson = None
url = "http://{}:{}/json.htm?{}".format(Parameters["Address"], Parameters["Port"], parse.quote(APICall, safe="&="))
Domoticz.Debug("Calling domoticz API: {}".format(url))
try:
req = request.Request(url)
if Parameters["Username"] != "":
Domoticz.Debug("Add authentification for user {}".format(Parameters["Username"]))
credentials = ('%s:%s' % (Parameters["Username"], Parameters["Password"]))
encoded_credentials = base64.b64encode(credentials.encode('ascii'))
req.add_header('Authorization', 'Basic %s' % encoded_credentials.decode("ascii"))
response = request.urlopen(req)
if response.status == 200:
resultJson = json.loads(response.read().decode('utf-8'))
if resultJson["status"] != "OK":
Domoticz.Error("Domoticz API returned an error: status = {}".format(resultJson["status"]))
resultJson = None
else:
Domoticz.Error("Domoticz API: http error = {}".format(response.status))
except:
Domoticz.Error("Error calling '{}'".format(url))
return resultJson
示例2: execute
# 需要导入模块: import json [as 别名]
# 或者: from json import htm [as 别名]
def execute(self, command, params):
"""Execute an OnOff command."""
domain = self.state.domain
protected = self.state.protected
if domain not in [domains['sensor'], domains['smokedetektor']]:
if domain == domains['group']:
url = DOMOTICZ_URL + '/json.htm?type=command¶m=switchscene&idx=' + self.state.id + '&switchcmd=' + (
'On' if params['on'] else 'Off')
else:
url = DOMOTICZ_URL + '/json.htm?type=command¶m=switchlight&idx=' + self.state.id + '&switchcmd=' + (
'On' if params['on'] else 'Off')
if protected:
url = url + '&passcode=' + configuration['Domoticz']['switchProtectionPass']
r = requests.get(url, auth=CREDITS)
if protected:
status = r.json()
err = status.get('status')
if err == 'ERROR':
raise SmartHomeError(ERR_WRONG_PIN,
'Unable to execute {} for {} check your settings'.format(command,
self.state.entity_id))
示例3: _execute_set_volume
# 需要导入模块: import json [as 别名]
# 或者: from json import htm [as 别名]
def _execute_set_volume(self, params):
level = params['volumeLevel']
url = DOMOTICZ_URL + '/json.htm?type=command¶m=switchlight&idx=' + self.state.id + '&switchcmd=Set%20Level&level=' + str(
int(level * self.state.maxdimlevel / 100))
r = requests.get(url, auth=CREDITS)
示例4: _execute_volume_relative
# 需要导入模块: import json [as 别名]
# 或者: from json import htm [as 别名]
def _execute_volume_relative(self, params):
# This could also support up/down commands using relativeSteps
relative = params['volumeRelativeLevel']
current = level = self.state.level
url = DOMOTICZ_URL + '/json.htm?type=command¶m=switchlight&idx=' + self.state.id + '&switchcmd=Set%20Level&level=' + str(
int(current + relative * self.state.maxdimlevel / 100))
r = requests.get(url, auth=CREDITS)
示例5: domoticz_control
# 需要导入模块: import json [as 别名]
# 或者: from json import htm [as 别名]
def domoticz_control(query,index,devicename):
global hexcolour,bright,devorder
try:
for j in range(0,len(domoticz_devices['result'])):
if domoticz_devices['result'][j]['idx']==index:
devorder=j
break
if (' ' + custom_action_keyword['Dict']['On'] + ' ') in query or (' ' + custom_action_keyword['Dict']['On']) in query or (custom_action_keyword['Dict']['On'] + ' ') in query:
devreq=requests.head("https://" + configuration['Domoticz']['Server_IP'][0] + ":" + configuration['Domoticz']['Server_port'][0] + "/json.htm?type=command¶m=switchlight&idx=" + index + "&switchcmd=On",verify=False)
say('Turning on ' + devicename )
if custom_action_keyword['Dict']['Off'] in query:
devreq=requests.head("https://" + configuration['Domoticz']['Server_IP'][0] + ":" + configuration['Domoticz']['Server_port'][0] + "/json.htm?type=command¶m=switchlight&idx=" + index + "&switchcmd=Off",verify=False)
say('Turning off ' + devicename )
if 'toggle' in query:
devreq=requests.head("https://" + configuration['Domoticz']['Server_IP'][0] + ":" + configuration['Domoticz']['Server_port'][0] + "/json.htm?type=command¶m=switchlight&idx=" + index + "&switchcmd=Toggle",verify=False)
say('Toggling ' + devicename )
if custom_action_keyword['Dict']['Colour'] in query:
if 'RGB' in domoticz_devices['result'][devorder]['SubType']:
rcolour,gcolour,bcolour,hexcolour,colour=getcolours(query)
hexcolour=hexcolour.replace("#","",1)
hexcolour=hexcolour.strip()
print(hexcolour)
if bright=='':
bright=str(domoticz_devices['result'][devorder]['Level'])
devreq=requests.head("https://" + configuration['Domoticz']['Server_IP'][0] + ":" + configuration['Domoticz']['Server_port'][0] + "/json.htm?type=command¶m=setcolbrightnessvalue&idx=" + index + "&hex=" + hexcolour + "&brightness=" + bright + "&iswhite=false",verify=False)
say('Setting ' + devicename + ' to ' + colour )
else:
say('The requested light is not a colour bulb')
if custom_action_keyword['Dict']['Brightness'] in query:
if domoticz_devices['result'][devorder]['HaveDimmer']:
if 'hundred' in query or 'hundred'.lower() in query or custom_action_keyword['Dict']['Maximum'] in query:
bright=str(100)
elif 'zero' in query or custom_action_keyword['Dict']['Minimum'] in query:
bright=str(0)
else:
bright=re.findall('\d+', query)
bright=bright[0]
devreq=requests.head("https://" + configuration['Domoticz']['Server_IP'][0] + ":" + configuration['Domoticz']['Server_port'][0] + "/json.htm?type=command¶m=switchlight&idx=" + index + "&switchcmd=Set%20Level&level=" + bright ,verify=False)
say('Setting ' + devicename + ' brightness to ' + str(bright) + ' percent.')
else:
say('The requested light does not have a dimer')
except (requests.exceptions.ConnectionError,TypeError) as errors:
if str(errors)=="'NoneType' object is not iterable":
print("Type Error")
else:
say("Device or Domoticz server is not online")
#------------------------End of Domoticz Control Functions----------------------
#------------------------Start of Gaana Functions-------------------------------