import json

class DataObject():
    def __init__(self):
        self.currentSpeed = 0
        self.speed2AVG = 0
        self.speed10AVG = 0
        self.speed2Max = 0
        self.speed10Max = 0
        self.compass = 0

    def data(self, client, userdata, msg):

        m_in= self.decode( msg.payload )

        try:
            self.currentSpeed = m_in['windspeed']
            self.speed2AVG = m_in['speed2AVG']
            self.speed10AVG = m_in['speed10AVG']
            self.speed2Max = m_in['speed2max']
            self.speed10Max = m_in['speed10max']
            self.compass = m_in['winddirection']
        except:
            pass

    def config(self, client, userdata, msg):
        
        m_in= self.decode( msg.payload )

        try:
            self.warning = m_in['warning_level']
            self.alert = m_in['alert_level']
        except:
            pass

    def decode(self,payload):
        return json.loads( payload.decode("utf-8", "ignore") )