如何在同一类的另一个方法中调用方法

时间:2019-04-03 11:20:31

标签: python python-3.x

编码新手,对面向对象的编程并不真正熟悉,我在一个类中设置了两个方法,但是上面的方法没有运行,其余的varablie都在运行。所以这里的任何人都可以帮我一个忙有这个问题吗?

def send_notification_via_pushbullet(self,title, body):
        """ Sending notification via pushbullet.
            Args:
                title (str) : title of text.
                body (str) : Body of text.
        """
        data_send = {"type": "note", "title": title, "body": body}

        resp = requests.post('https://api.pushbullet.com/v2/pushes', data=json.dumps(data_send),
                            headers={'Authorization': 'Bearer ' + ACCESS_TOKEN, 
                            'Content-Type': 'application/json'})
        self.resp=resp
        if resp.status_code != 200:
            raise Exception('Something wrong')
        else:
            print('complete sending')   

def getData(self): 
      sense = SenseHat()
      sensorTemp = sense.get_temperature_from_humidity()
      cpuTemp = self.get_cpu_temp()
      roomTemp = sensorTemp - ((cpuTemp-sensorTemp)/1.5)
      humid = sense.get_humidity()
      os.environ['TZ'] = 'Australia/Melbourne'
      time.tzset()
      nowTime = time.strftime('%Y-%m-%d %H:%M:%S')
      if roomTemp is not None:
          if humid is not None:
              roomTemp = round(roomTemp, 1)
              humid = round(humid, 1)
              self.rT=roomTemp
              self.humid=humid

      nearbyDevices = bluetooth.discover_devices()
      for macAddress in nearbyDevices:
            print("Found device with mac-address: " + macAddress)
            if macAddress == self.a:
                with open('config.json') as myfile:
                    data=json.load(myfile)
                    tmin = data['min_temperature']
                    tmax = data['max_temperature']
                    hmin = data['min_humidity']
                    hmax = data['max_humidity']
                if (tmin<= roomTemp <= tmax and hmin <= humid <= hmax)!=1:
                    message1=(("Current time is " + str(nowTime) + " Temperature is " + str(roomTemp) +"Celsius " + "Humidity rate is"+ str(humid)+"percent"))
                    message2=("Either temperature or humidity rate is Out of range")
                    self.send_notification_via_pushbullet(message1, message2)
                else:
                    message3=(("Current time is " + str(nowTime) + " Temperature is " + str(roomTemp) +"Celsius " + "Humidity rate is"+ str(humid)+"percent"))
                    message4=("Both temperature and humidity rate is within the range")
                    self.send_notification_via_pushbullet(message3, message4)

0 个答案:

没有答案