當前位置: 首頁>>代碼示例>>Python>>正文


Python json.htm方法代碼示例

本文整理匯總了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 
開發者ID:999LV,項目名稱:SmartVirtualThermostat,代碼行數:26,代碼來源:plugin.py

示例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&param=switchscene&idx=' + self.state.id + '&switchcmd=' + (
                    'On' if params['on'] else 'Off')
            else:
                url = DOMOTICZ_URL + '/json.htm?type=command&param=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)) 
開發者ID:DewGew,項目名稱:Domoticz-Google-Assistant,代碼行數:26,代碼來源:trait.py

示例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&param=switchlight&idx=' + self.state.id + '&switchcmd=Set%20Level&level=' + str(
            int(level * self.state.maxdimlevel / 100))
        r = requests.get(url, auth=CREDITS) 
開發者ID:DewGew,項目名稱:Domoticz-Google-Assistant,代碼行數:8,代碼來源:trait.py

示例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&param=switchlight&idx=' + self.state.id + '&switchcmd=Set%20Level&level=' + str(
            int(current + relative * self.state.maxdimlevel / 100))
        r = requests.get(url, auth=CREDITS) 
開發者ID:DewGew,項目名稱:Domoticz-Google-Assistant,代碼行數:10,代碼來源:trait.py

示例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&param=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&param=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&param=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&param=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&param=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------------------------------- 
開發者ID:shivasiddharth,項目名稱:GassistPi,代碼行數:53,代碼來源:actions.py


注:本文中的json.htm方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。