Beispiel #1
0
def setup_platform(opp, config, add_entities, discovery_info=None):
    """Set up the sensor platform."""

    i2c_address = config.get(CONF_I2C_ADDRESS)
    sensor = SHT31(address=i2c_address)

    try:
        if sensor.read_status() is None:
            raise ValueError("CRC error while reading SHT31 status")
    except (OSError, ValueError):
        _LOGGER.error("SHT31 sensor not detected at address %s", hex(i2c_address))
        return
    sensor_client = SHTClient(sensor)

    sensor_classes = {
        SENSOR_TEMPERATURE: SHTSensorTemperature,
        SENSOR_HUMIDITY: SHTSensorHumidity,
    }

    devs = []
    for sensor_type, sensor_class in sensor_classes.items():
        name = f"{config.get(CONF_NAME)} {sensor_type.capitalize()}"
        devs.append(sensor_class(sensor_client, name))

    add_entities(devs)
Beispiel #2
0
    def __init__(self, input_dev, testing=False):
        super(InputModule, self).__init__()
        self.setup_logger(testing=testing, name=__name__, input_dev=input_dev)
        self.measurement_count = 0
        self.heater_enable = None
        self.heater_seconds = None
        self.heater_measurements = None

        if not testing:
            from Adafruit_SHT31 import SHT31

            self.device_measurements = db_retrieve_table_daemon(
                DeviceMeasurements).filter(
                    DeviceMeasurements.device_id == input_dev.unique_id)

            if input_dev.custom_options:
                for each_option in input_dev.custom_options.split(';'):
                    option = each_option.split(',')[0]
                    value = each_option.split(',')[1]
                    if option == 'heater_enable':
                        self.heater_enable = bool(value)
                    elif option == 'heater_seconds':
                        self.heater_seconds = float(value)
                    elif option == 'heater_measurements':
                        self.heater_measurements = int(value)

            self.i2c_address = int(str(input_dev.i2c_location), 16)
            self.i2c_bus = input_dev.i2c_bus
            self.sensor = SHT31(address=self.i2c_address, busnum=self.i2c_bus)
Beispiel #3
0
def setup_platform(
    hass: HomeAssistant,
    config: ConfigType,
    add_entities: AddEntitiesCallback,
    discovery_info: DiscoveryInfoType | None = None,
) -> None:
    """Set up the sensor platform."""
    _LOGGER.warning(
        "The Sensirion SHT31 integration is deprecated and will be removed "
        "in Home Assistant Core 2022.4; this integration is removed under "
        "Architectural Decision Record 0019, more information can be found here: "
        "https://github.com/home-assistant/architecture/blob/master/adr/0019-GPIO.md"
    )

    name = config[CONF_NAME]
    monitored_conditions = config[CONF_MONITORED_CONDITIONS]
    i2c_address = config[CONF_I2C_ADDRESS]
    sensor = SHT31(address=i2c_address)

    try:
        if sensor.read_status() is None:
            raise ValueError("CRC error while reading SHT31 status")
    except (OSError, ValueError):
        _LOGGER.error("SHT31 sensor not detected at address %s",
                      hex(i2c_address))
        return
    sensor_client = SHTClient(sensor)

    entities = [
        SHTSensor(sensor_client, name, description)
        for description in SENSOR_TYPES
        if description.key in monitored_conditions
    ]

    add_entities(entities)
Beispiel #4
0
    def __init__(self, input_dev, testing=False):
        super(InputModule, self).__init__(input_dev,
                                          testing=testing,
                                          name=__name__)

        self.measurement_count = 0

        # Initialize custom options
        self.heater_enable = None
        self.heater_seconds = None
        self.heater_measurements = None
        # Set custom options
        self.setup_custom_options(INPUT_INFORMATION['custom_options'],
                                  input_dev)

        if not testing:
            from Adafruit_SHT31 import SHT31

            self.i2c_address = int(str(input_dev.i2c_location), 16)
            self.i2c_bus = input_dev.i2c_bus
            self.sensor = SHT31(address=self.i2c_address, busnum=self.i2c_bus)
Beispiel #5
0
def setup_platform(hass, config, add_entities, discovery_info=None):
    """Set up the sensor platform."""
    name = config[CONF_NAME]
    monitored_conditions = config[CONF_MONITORED_CONDITIONS]
    i2c_address = config[CONF_I2C_ADDRESS]
    sensor = SHT31(address=i2c_address)

    try:
        if sensor.read_status() is None:
            raise ValueError("CRC error while reading SHT31 status")
    except (OSError, ValueError):
        _LOGGER.error("SHT31 sensor not detected at address %s",
                      hex(i2c_address))
        return
    sensor_client = SHTClient(sensor)

    entities = [
        SHTSensor(sensor_client, name, description)
        for description in SENSOR_TYPES
        if description.key in monitored_conditions
    ]

    add_entities(entities)
Beispiel #6
0
printerr(f'{colorama.Style.DIM}Initialising TCA9548A{colorama.Style.RESET_ALL}',end="\t")

passed = False
for tried in range(10):
    try:
        TCA9548A = I2C.get_i2c_device(0x70)
        select_I2C_channel(0)
        break
    except Exception as e:
        if tried>8:
            printerr(f'{colorama.Fore.RED}[FAIL]{colorama.Style.RESET_ALL}')
            raise
printerr(f'{colorama.Fore.GREEN}[OK]{colorama.Style.RESET_ALL}')

printerr(f'{colorama.Style.DIM}Initialising SHT31{colorama.Style.RESET_ALL}',end="\t")
sht = SHT31(0x44)
printerr(f'{colorama.Fore.GREEN}[OK]{colorama.Style.RESET_ALL}')

mics = MICS(adcs5V[0], 0, 1,2)
mics2 = MICS(adcs5V[1], 0)


gps_serial = serial.Serial(gps_port, 9600, 8, 'N', 1, timeout=1)

time.sleep(1)

if False:
    printerr(f'{colorama.Style.DIM}Initialising MCP23017{colorama.Style.RESET_ALL}',end="\t")
    try:
        mcp = MCP230XX('MCP23017', 0x20, '16bit')
        # Setup outputs
Beispiel #7
0
    def initialize_input(self):
        from Adafruit_SHT31 import SHT31

        self.sensor = SHT31(address=int(str(self.input_dev.i2c_location), 16),
                            busnum=self.input_dev.i2c_bus)
Beispiel #8
0
 def __init__(self, TCA9548A_address=0x70, N_SHTs=8):
     self.sht = SHT31()  # Handle to all sensors in the array!
     self.TCA9548A = I2C.get_i2c_device(TCA9548A_address)
     self.N_SHTs = N_SHTs
     gpio = Adafruit_GPIO.get_platform_gpio()  #? is this neccessary?