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


from struct import unpack
from IoTPy.errors import IoTPy_ThingError


class Si7013:
    """
    Si7013 humidity and temperature sensor class.

    :param interface:  I2C communication interface.
    :type interface: :class:`IoTPy.pyuper.i2c.I2C`
    :param int address: Si7013 sensor I2C address. Optional, default 0x40 (64)
    """

    def __init__(self, interface, address=0x40):
        self.interface = interface
        self.address = address

    def __enter__(self):
        return self

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

        :return: Temperature value in celsius.
        :rtype: float
        :raise: IoTPy_ThingError
        """
        try:
            data, err = self.interface.transaction(self.address, SI70xx_CMD_TEMP_HOLD, 2)
            result_integer = unpack('>H', data[:2])[0]
            temp = (175.72 * result_integer)/65536 - 46.85

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


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



class Si7013:
    """
    Si7013 humidity and temperature sensor class.

    :param interface:  I2C communication interface.
    :type interface: :class:`IoTPy.pyuper.i2c.I2C`
    :param int address: Si7013 sensor I2C address. Optional, default 0x40 (64)
    """

    def __init__(self, interface, address=0x40):
        self.interface = interface
        self.address = address

    def __enter__(self):
        return self

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

        :return: Temperature value in celsius.
        :rtype: float
        :raise: IoTPy_ThingError
        """
        try:
            data, err = self.interface.transaction(self.address, SI70xx_CMD_TEMP_HOLD, 2)
            result_integer = unpack('>H', data[:2])[0]
            temp = (175.72 * result_integer)/65536 - 46.85

        except IoTPy_ThingError: