# Path: IoTPy/errors.py
# class IoTPy_ThingError(Exception):
#     pass


from struct import unpack
from IoTPy.errors import IoTPy_ThingError

    def humidity(self):
        """
        Read, convert and return humidity.

        :return: Humidity value in percent.
        :rtype: float
        :raise: IoTPy_ThingError
        """
        try:
            data, err = self.interface.transaction(self.address, SI70xx_CMD_RH_HOLD, 2)
            result_integer = unpack('>H', data[:2])[0]
            rh = (125.0 * result_integer)/65536 - 6
        except IoTPy_ThingError:
            raise IoTPy_ThingError("Si7020 - humidity reading error.")
        return rh

    def analog(self):
        """
        Read, convert and return analog sensor value.

        :return: Analog ADC value
        :rtype: int
        :raise: IoTPy_ThingError
        """
        try:
            data, err = self.interface.transaction(self.address, SI70xx_CMD_ANALOG, 2)
            result_integer = unpack('>H', data[:2])[0]
            return result_integer
        except IoTPy_ThingError:

# Path: IoTPy/errors.py
# class IoTPy_ThingError(Exception):
#     pass


# Path: IoTPy/things/si70xx.py
from struct import unpack
from IoTPy.errors import IoTPy_ThingError


    def humidity(self):
        """
        Read, convert and return humidity.

        :return: Humidity value in percent.
        :rtype: float
        :raise: IoTPy_ThingError
        """
        try:
            data, err = self.interface.transaction(self.address, SI70xx_CMD_RH_HOLD, 2)
            result_integer = unpack('>H', data[:2])[0]
            rh = (125.0 * result_integer)/65536 - 6
        except IoTPy_ThingError:
            raise IoTPy_ThingError("Si7020 - humidity reading error.")
        return rh

    def analog(self):
        """
        Read, convert and return analog sensor value.

        :return: Analog ADC value
        :rtype: int
        :raise: IoTPy_ThingError
        """
        try:
            data, err = self.interface.transaction(self.address, SI70xx_CMD_ANALOG, 2)
            result_integer = unpack('>H', data[:2])[0]
            return result_integer
        except IoTPy_ThingError:

            raise IoTPy_ThingError("Si7020 - analog reading error.")