import logging; logger = logging.getLogger("morse." + __name__)

import morse.core.sensor

from morse.core.services import service, async_service
from morse.core import status
from morse.helpers.components import add_data, add_property

class Pressure(morse.core.sensor.Sensor):
    _name = "Pressure"
    _short_desc = "Measure the pressure"
    #_precision = 0.2
    # define here the data fields exported by your sensor
    # format is: field name, default initial value, type, description
    add_data('pressure', 0.0, 'value', 'depth of the robot')

    def __init__(self, obj, parent=None):
        logger.info("%s initialization" % obj.name)
        # Call the constructor of the parent class
        morse.core.sensor.Sensor.__init__(self, obj, parent)

        logger.info('Component initialized')

    @service
    def get_current_pressure(self):
        
        #logger.info("%s is %sm deep" % (self.name, self.local_data['pressure']))
        return self.local_data['pressure']

    def default_action(self):

        self.local_data['pressure'] = - self.position_3d.z # distance along Z in world coordinates

