Source code for sensirion_i2c_sht4x.device

#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# (c) Copyright 2024 Sensirion AG, Switzerland
#
#     THIS FILE IS AUTOMATICALLY GENERATED!
#
# Generator:     sensirion-driver-generator 0.40.0
# Product:       sht4x
# Model-Version: 2.1.1
#
"""
The class Sht4xDeviceBase implements the low level interface of the sensor.
The class Sht4xDevice extends the Sht4xDeviceBase. It provides additional functions to ease the use of the
sensor.
"""

from sensirion_driver_adapters.transfer import execute_transfer
from sensirion_driver_support_types.mixin_access import MixinAccess
from sensirion_i2c_sht4x.commands import (ActivateHighestHeaterPowerLongTicks, ActivateHighestHeaterPowerShortTicks,
                                          ActivateLowestHeaterPowerLongTicks, ActivateLowestHeaterPowerShortTicks,
                                          ActivateMediumHeaterPowerLongTicks, ActivateMediumHeaterPowerShortTicks,
                                          MeasureHighPrecisionTicks, MeasureLowestPrecisionTicks,
                                          MeasureMediumPrecisionTicks, SerialNumber, SoftReset)

from sensirion_i2c_sht4x.result_types import (SignalHumidity, SignalTemperature)


[docs]class Sht4xDeviceBase: """Low level API implementation of SHT4X"""
[docs] def __init__(self, channel): self._channel = channel
@property def channel(self): return self._channel
[docs] def measure_high_precision_ticks(self): """ SHT4x command for a single shot measurement with high repeatability. :return temperature_ticks: Temperature ticks. Convert to degrees celsius by (175 * value / 65535) - 45 :return humidity_ticks: Humidity ticks. Convert to degrees celsius by (125 * value / 65535) - 6 """ transfer = MeasureHighPrecisionTicks() return execute_transfer(self._channel, transfer)
[docs] def measure_medium_precision_ticks(self): """ SHT4x command for a single shot measurement with medium repeatability. :return temperature_ticks: Temperature ticks. Convert to degrees celsius by (175 * value / 65535) - 45 :return humidity_ticks: Humidity ticks. Convert to degrees celsius by (125 * value / 65535) - 6 """ transfer = MeasureMediumPrecisionTicks() return execute_transfer(self._channel, transfer)
[docs] def measure_lowest_precision_ticks(self): """ SHT4x command for a single shot measurement with lowest repeatability. :return temperature_ticks: Temperature ticks. Convert to degrees celsius by (175 * value / 65535) - 45 :return humidity_ticks: Humidity ticks. Convert to degrees celsius by (125 * value / 65535) - 6 """ transfer = MeasureLowestPrecisionTicks() return execute_transfer(self._channel, transfer)
[docs] def activate_highest_heater_power_long_ticks(self): """ SHT4x command to activate highest heater power and perform a single shot high precision measurement for 1s. :return temperature_ticks: Temperature ticks. Convert to degrees celsius by (175 * value / 65535) - 45 :return humidity_ticks: Humidity ticks. Convert to degrees celsius by (125 * value / 65535) - 6 """ transfer = ActivateHighestHeaterPowerLongTicks() return execute_transfer(self._channel, transfer)
[docs] def activate_highest_heater_power_short_ticks(self): """ SHT4x command to activate highest heater power and perform a single shot high precision measurement for 0.1s. :return temperature_ticks: Temperature ticks. Convert to degrees celsius by (175 * value / 65535) - 45 :return humidity_ticks: Humidity ticks. Convert to degrees celsius by (125 * value / 65535) - 6 """ transfer = ActivateHighestHeaterPowerShortTicks() return execute_transfer(self._channel, transfer)
[docs] def activate_medium_heater_power_long_ticks(self): """ SHT4x command to activate medium heater power and perform a single shot high precision measurement for 1s. :return temperature_ticks: Temperature ticks. Convert to degrees celsius by (175 * value / 65535) - 45 :return humidity_ticks: Humidity ticks. Convert to degrees celsius by (125 * value / 65535) - 6 """ transfer = ActivateMediumHeaterPowerLongTicks() return execute_transfer(self._channel, transfer)
[docs] def activate_medium_heater_power_short_ticks(self): """ SHT4x command to activate medium heater power and perform a single shot high precision measurement for 0.1s. :return temperature_ticks: Temperature ticks. Convert to degrees celsius by (175 * value / 65535) - 45 :return humidity_ticks: Humidity ticks. Convert to degrees celsius by (125 * value / 65535) - 6 """ transfer = ActivateMediumHeaterPowerShortTicks() return execute_transfer(self._channel, transfer)
[docs] def activate_lowest_heater_power_long_ticks(self): """ SHT4x command to activate lowest heater power and perform a single shot high precision measurement for 1s. :return temperature_ticks: Temperature ticks. Convert to degrees celsius by (175 * value / 65535) - 45 :return humidity_ticks: Humidity ticks. Convert to degrees celsius by (125 * value / 65535) - 6 """ transfer = ActivateLowestHeaterPowerLongTicks() return execute_transfer(self._channel, transfer)
[docs] def activate_lowest_heater_power_short_ticks(self): """ SHT4x command to activate lowest heater power and perform a single shot high precision measurement for 0.1s. :return temperature_ticks: Temperature ticks. Convert to degrees celsius by (175 * value / 65535) - 45 :return humidity_ticks: Humidity ticks. Convert to degrees celsius by (125 * value / 65535) - 6 """ transfer = ActivateLowestHeaterPowerShortTicks() return execute_transfer(self._channel, transfer)
[docs] def serial_number(self): """ Read out the serial number :return serial_number: Unique serial number .. note:: Each sensor has a unique serial number that is assigned by Sensirion during production.It is stored in the one-time-programmable memory and cannot be manipulated after production. """ transfer = SerialNumber() return execute_transfer(self._channel, transfer)[0]
[docs] def soft_reset(self): """ Perform a soft reset. .. note:: A reset of the sensor can be achieved in three ways: • Soft reset: use this function • I2C general call: all devices on the I2C bus are reset by sending the command 0x06 to the I2C address 0x00. • Power down (incl.pulling SCL and SDA low) """ transfer = SoftReset() return execute_transfer(self._channel, transfer)
[docs]class Sht4xDevice(Sht4xDeviceBase): """Driver class implementation of SHT4X""" #: Access to base class sht4x = MixinAccess()
[docs] def __init__(self, channel): super().__init__(channel)
[docs] def measure_high_precision(self): """ SHT4x command for a single shot measurement with high repeatability. :return a_temperature: Converted from ticks to degrees celsius by (175 * ticks_value / 65535) - 45 :return a_humidity: Converted from ticks to percent relative humdity by (125 * ticks_value / 65535) - 6 """ (temp_ticks, humi_ticks ) = self.sht4x.measure_high_precision_ticks() return (SignalTemperature(temp_ticks), SignalHumidity(humi_ticks))
[docs] def measure_medium_precision(self): """ SHT4x command for a single shot measurement with medium repeatability. :return a_temperature: Converted from ticks to degrees celsius by (175 * ticks_value / 65535) - 45 :return a_humidity: Converted from ticks to percent relative humdity by (125 * ticks_value / 65535) - 6 """ (temp_ticks, humi_ticks ) = self.sht4x.measure_medium_precision_ticks() return (SignalTemperature(temp_ticks), SignalHumidity(humi_ticks))
[docs] def measure_lowest_precision(self): """ SHT4x command for a single shot measurement with low repeatability. :return a_temperature: Converted from ticks to degrees celsius by (175 * ticks_value / 65535) - 45 :return a_humidity: Converted from ticks to percent relative humdity by (125 * ticks_value / 65535) - 6 """ (temp_ticks, humi_ticks ) = self.sht4x.measure_lowest_precision_ticks() return (SignalTemperature(temp_ticks), SignalHumidity(humi_ticks))
[docs] def activate_highest_heater_power_long(self): """ SHT4x command to activate highest heater power and perform a single shot high precision measurement for 1s. :return a_temperature: Converted from ticks to degrees celsius by (175 * ticks_value / 65535) - 45 :return a_humidity: Converted from ticks to percent relative humdity by (125 * ticks_value / 65535) - 6 """ (temp_ticks, humi_ticks ) = self.sht4x.activate_highest_heater_power_long_ticks() return (SignalTemperature(temp_ticks), SignalHumidity(humi_ticks))
[docs] def activate_highest_heater_power_short(self): """ SHT4x command to activate highest heater power and perform a single shot high precision measurement for 0.1s. :return a_temperature: Converted from ticks to degrees celsius by (175 * ticks_value / 65535) - 45 :return a_humidity: Converted from ticks to percent relative humdity by (125 * ticks_value / 65535) - 6 """ (temp_ticks, humi_ticks ) = self.sht4x.activate_highest_heater_power_short_ticks() return (SignalTemperature(temp_ticks), SignalHumidity(humi_ticks))
[docs] def activate_medium_heater_power_long(self): """ SHT4x command to activate medium heater power and perform a single shot high precision measurement for 1s. :return a_temperature: Converted from ticks to degrees celsius by (175 * ticks_value / 65535) - 45 :return a_humidity: Converted from ticks to percent relative humdity by (125 * ticks_value / 65535) - 6 """ (temp_ticks, humi_ticks ) = self.sht4x.activate_medium_heater_power_long_ticks() return (SignalTemperature(temp_ticks), SignalHumidity(humi_ticks))
[docs] def activate_medium_heater_power_short(self): """ SHT4x command to activate medium heater power and perform a single shot high precision measurement for 0.1s. :return a_temperature: Converted from ticks to degrees celsius by (175 * ticks_value / 65535) - 45 :return a_humidity: Converted from ticks to percent relative humdity by (125 * ticks_value / 65535) - 6 """ (temp_ticks, humi_ticks ) = self.sht4x.activate_medium_heater_power_short_ticks() return (SignalTemperature(temp_ticks), SignalHumidity(humi_ticks))
[docs] def activate_lowest_heater_power_long(self): """ SHT4x command to activate lowest heater power and perform a single shot high precision measurement for 1s. :return a_temperature: Converted from ticks to degrees celsius by (175 * ticks_value / 65535) - 45 :return a_humidity: Converted from ticks to percent relative humdity by (125 * ticks_value / 65535) - 6 """ (temp_ticks, humi_ticks ) = self.sht4x.activate_lowest_heater_power_long_ticks() return (SignalTemperature(temp_ticks), SignalHumidity(humi_ticks))
[docs] def activate_lowest_heater_power_short(self): """ SHT4x command to activate lowest heater power and perform a single shot high precision measurement for 0.1s. :return a_temperature: Converted from ticks to degrees celsius by (175 * ticks_value / 65535) - 45 :return a_humidity: Converted from ticks to percent relative humdity by (125 * ticks_value / 65535) - 6 """ (temp_ticks, humi_ticks ) = self.sht4x.activate_lowest_heater_power_short_ticks() return (SignalTemperature(temp_ticks), SignalHumidity(humi_ticks))