Exemplo n.º 1
0
 def get(self, token):
     headers = {
         'Content-Type': 'application/json',
         'Authorization': "Bearer " + token
     }
     res = requests.get(self.server.url + self.uri, headers=headers)
     return process_res(res)
Exemplo n.º 2
0
 def get(self,
         year=False,
         year_n=0,
         month=False,
         month_n=0,
         day=False,
         day_n=0):
     is_year = 0
     is_month = 0
     is_day = 0
     if year is True:
         is_year = 1
     if month is True:
         is_month = 1
     if day is True:
         is_day = 1
     params = {
         'raspberry_group': self.device_setting.group,
         'raspberry_id': self.device_setting.id,
         'year': is_year,
         'year_n': year_n,
         'month': is_month,
         'month_n': month_n,
         'day': is_day,
         'day_n': day_n
     }
     res = requests.get(self.server.url + self.uri, params=params)
     return process_res(res)
Exemplo n.º 3
0
 def get_year(self, year):
     params = {
         'raspberry_group': self.device_setting.group,
         'raspberry_id': self.device_setting.id
     }
     res = requests.get(self.server.url + self.uri + '/' + str(year),
                        params=params)
     return process_res(res)
Exemplo n.º 4
0
 def get(self, device_id, device_type, token):
     headers = {
         'Content-Type': 'application/json',
         'Authorization': "Bearer " + token
     }
     params = {'device_id': device_id, 'device_type': device_type}
     res = requests.get(self.server.url + self.uri,
                        headers=headers,
                        params=params)
     return process_res(res)
Exemplo n.º 5
0
 def connect(self):
     headers = {'Content-Type': 'application/json'}
     data = {
         'raspberry_group': self.device_setting.group,
         'raspberry_id': self.device_setting.id,
         'raspberry_pw': self.device_setting.password
     }
     res = requests.post(self.server.url + self.uri + '/connect',
                         headers=headers,
                         data=json.dumps(data))
     return process_res(res)
Exemplo n.º 6
0
 def post(self):
     headers = {'Content-Type': 'application/json'}
     data = {
         'raspberry_group': self.device_setting.group,
         'raspberry_id': self.device_setting.id,
         'raspberry_pw': self.device_setting.password,
         'remote_control': self.device_setting.remote_control,
         'devices': get_devices_info(self.device_setting.devices)
     }
     res = requests.post(self.server.url + self.uri,
                         headers=headers,
                         data=json.dumps(data))
     return process_res(res)
Exemplo n.º 7
0
    def put(self, token):
        headers = {
            'Content-Type': 'application/json',
            'Authorization': "Bearer " + token
        }
        data = {
            'raspberry_group': self.device_setting.group,
            'raspberry_id': self.device_setting.id,
            'raspberry_pw': self.device_setting.password,
            'remote_control': self.device_setting.remote_control
        }

        res = requests.put(self.server.url + self.uri,
                           headers=headers,
                           data=json.dumps(data))
        return process_res(res)
Exemplo n.º 8
0
def device_control_api(server_url, device_id, device_type, on_off, unit_index,
                       token):
    headers = {
        'Content-Type': 'application/json',
        'Authorization': "Bearer " + token
    }
    data = {
        'device_id': device_id,
        'device_type': device_type,
        'on_off': on_off,
        'unit_index': unit_index
    }
    res = requests.post(server_url + '/api/device/control',
                        headers=headers,
                        data=json.dumps(data))
    return process_res(res)
Exemplo n.º 9
0
 def delete(self, token):
     headers = {'Authentication': "Bearer " + token}
     res = requests.delete(self.server.url + self.uri, headers=headers)
     return process_res(res)
Exemplo n.º 10
0
 def get_devices(self, token):
     headers = {'Authentication': "Bearer " + token}
     res = requests.get(self.server.url + '/api/web/devices',
                        headers=headers)
     return process_res(res)