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)
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)
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)
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)
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)
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)
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)
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)
def delete(self, token): headers = {'Authentication': "Bearer " + token} res = requests.delete(self.server.url + self.uri, headers=headers) return process_res(res)
def get_devices(self, token): headers = {'Authentication': "Bearer " + token} res = requests.get(self.server.url + '/api/web/devices', headers=headers) return process_res(res)