Get temperature of a specific sensor
11359
def get(id_, hwid, type_, unit, precision, as_json):
    """"""
    if id_ and (hwid or type_):
        raise click.BadOptionUsage(
            "If --id is given --hwid and --type are not allowed."
        )

    if id_:
        try:
            sensor = W1ThermSensor.get_available_sensors()[id_ - 1]
        except IndexError:
            raise click.BadOptionUsage(
                "No sensor with id {0} available. "
                "Use the ls command to show all available sensors.".format(id_)
            )
    else:
        sensor = W1ThermSensor(type_, hwid)

    if precision:
        sensor.set_precision(precision, persist=False)

    temperature = sensor.get_temperature(unit)

    if as_json:
        data = {
            "hwid": sensor.id,
            "type": sensor.type_name,
            "temperature": temperature,
            "unit": unit,
        }
        click.echo(json.dumps(data, indent=4, sort_keys=True))
    else:
        click.echo(
            "Sensor {0} measured temperature: {1} {2}".format(
                click.style(sensor.id, bold=True),
                click.style(str(temperature), bold=True),
                click.style(unit, bold=True),
            )
        )
1126331
def temp_unit(self):
        """"""
        if CONST.UNIT_FAHRENHEIT in self._get_status(CONST.TEMP_STATUS_KEY):
            return CONST.UNIT_FAHRENHEIT
        elif CONST.UNIT_CELSIUS in self._get_status(CONST.TEMP_STATUS_KEY):
            return CONST.UNIT_CELSIUS
        return None
903858
def disableTemperature(self):
        
        logger.debug("Disabling temperature sensor")
        self.fifoSensorMask &= ~self.enableTemperatureMask
        self._setSampleSizeBytes()
1342334
def all(types, unit, precision, as_json):  # pylint: disable=redefined-builtin
    """"""
    sensors = W1ThermSensor.get_available_sensors(types)
    temperatures = []
    for sensor in sensors:
        if precision:
            sensor.set_precision(precision, persist=False)

        temperatures.append(sensor.get_temperature(unit))

    if as_json:
        data = [
            {"id": i, "hwid": s.id, "type": s.type_name, "temperature": t, "unit": unit}
            for i, s, t in zip(count(start=1), sensors, temperatures)
        ]
        click.echo(json.dumps(data, indent=4, sort_keys=True))
    else:
        click.echo(
            "Got temperatures of {0} sensors:".format(
                click.style(str(len(sensors)), bold=True)
            )
        )
        for i, sensor, temperature in zip(count(start=1), sensors, temperatures):
            click.echo(
                "  Sensor {0} ({1}) measured temperature: {2} {3}".format(
                    click.style(str(i), bold=True),
                    click.style(sensor.id, bold=True),
                    click.style(str(round(temperature, 2)), bold=True),
                    click.style(unit, bold=True),
                )
            )
1363294
private function _temperature()
    {
        if (isset($this->_filecontent["temp"]) && (trim($this->_filecontent["temp"]) !== "")) {
            $values = preg_split("/ /", trim($this->_filecontent["temp"]));
            foreach ($values as $id=>$value) {
                $dev = new SensorDevice();
                $dev->setName("temp".$id);
                $dev->setValue($value);
                $this->mbinfo->setMbTemp($dev);
            }
        }
    }
390622
def get_target_temperature(self):
        
        value = self.box.homeautoswitch("gethkrtsoll", self.actor_id)
        self.target_temperature = self.__get_temp(value)
        return self.target_temperature
1205032
private function _temperature()
    {
        foreach ($this->_lines as $line) {
            $buffer = preg_split("/\s*\|\s*/", $line);
            if ($buffer[2] == "Temperature" && $buffer[11] != "N/A" && $buffer[4] == "C") {
                $dev = new SensorDevice();
                $dev->setName($buffer[1]);
                $dev->setValue($buffer[3]);
                if ($buffer[9] != "N/A") $dev->setMax($buffer[9]);
                if ($buffer[11] != "'OK'") $dev->setEvent(trim($buffer[11], "'"));
                $this->mbinfo->setMbTemp($dev);
            }
        }
    }
533126
def get_temperature(self, channel, sensor='VNTC'):
        '''
        '''
#         NTC type SEMITEC 103KT1608 http://www.semitec.co.jp/english/products/pdf/KT_Thermistor.pdf
#
#         R_NTC = R_25 * exp(B_NTC * (1/T - 1/T_25))
#
#         R_NTC       measured NTC resistance
#         R_NTC_25    resistance @ 25C
#         B_NTC       temperature coefficient
#         Temperature current temperature (Kelvin)
#         T_25        298,15 K (25C)
#
#         B_NTC       NTC 'b' coefficient, NTC Semitec 103KT1608-1P
#         R_NTC_25    NTC 25C resistance, NTC Semitec 103KT1608-1P
#         R1          resistor value for NTC voltage divider
#         R2          value of R2 in the reference voltage divider
#         R4          value of R4 in the reference voltage divider
#         VREF        supply voltage of the resistor bridge
#

        kwargs = self._ch_map[channel][sensor]
        temp_raw = self._get_adc_value(**kwargs)

        v_adc = ((temp_raw - self._ch_cal.items()[0][1]['ADCV']['offset']) / self._ch_cal.items()[0][1]['ADCV']['gain'])  # voltage, VDDA1
        k = self._ch_cal[channel][sensor]['R4'] / (self._ch_cal[channel][sensor]['R2'] + self._ch_cal[channel][sensor]['R4'])  # reference voltage divider
        r_ntc = self._ch_cal[channel][sensor]['R1'] * (k - v_adc / self._ch_cal[channel][sensor]['VREF']) / (1 - k + v_adc / self._ch_cal[channel][sensor]['VREF'])  # NTC resistance

        return (self._ch_cal[channel][sensor]['B_NTC'] / (log(r_ntc) - log(self._ch_cal[channel][sensor]['R_NTC_25']) + self._ch_cal[channel][sensor]['B_NTC'] / self.T_KELVIN_25)) - self.T_KELVIN_0
28320
def _get_sensor_names(self):
        """"""
        # if the user didn't tell us what sensors to work with, let's figure it
        # out
        if not self.attrs.get('sensor'):
            # reader finder could return multiple readers
            return set([sensor for reader_instance in self.readers.values()
                        for sensor in reader_instance.sensor_names])
        elif not isinstance(self.attrs['sensor'], (set, tuple, list)):
            return set([self.attrs['sensor']])
        else:
            return set(self.attrs['sensor'])
716582
def update_humidity_temp(self):
        
        # Create mask for STATUS (first two bits of 64 bit wide result)
        STATUS = 0b11 << 6

        TCA_select(SensorCluster.bus, self.mux_addr, SensorCluster.humidity_chan)
        SensorCluster.bus.write_quick(SensorCluster.humidity_addr)  # Begin conversion
        sleep(.25)
        # wait 100ms to make sure the conversion takes place.
        data = SensorCluster.bus.read_i2c_block_data(SensorCluster.humidity_addr, 0, 4)
        status = (data[0] & STATUS) >> 6
        
        if status == 0 or status == 1:  # will always pass for now.
            humidity = round((((data[0] & 0x3f) << 8) |
                              data[1]) * 100.0 / (2**14 - 2), 3)
            self.humidity = humidity
            self.temp = (round((((data[2] << 6) + ((data[3] & 0xfc) >> 2))
                               * 165.0 / 16382.0 - 40.0), 3) * 9/5) + 32
            return TCA_select(SensorCluster.bus, self.mux_addr, "off")
        else:
            raise I2CBusError("Unable to retrieve humidity")
471407
def get_temperature(self):
        """"""
        try:
            request = requests.get(
                '{}/temp'.format(self.resource), timeout=self.timeout, allow_redirects=False)
            self.temperature = request.json()['compensated']
            return self.temperature
        except requests.exceptions.ConnectionError:
            raise exceptions.MyStromConnectionError()
        except ValueError:
            raise exceptions.MyStromNotVersionTwoSwitch()
988943
protected function _temperature($hwpath)
    {
       $sensor = glob($hwpath."temp*_input", GLOB_NOSORT);
       if (is_array($sensor) && (($total = count($sensor)) > 0)) {
            $buf = "";
            for ($i = 0; $i < $total; $i++) if (($buf = CommonFunctions::rolv($sensor[$i]))!==null) {
                $dev = new SensorDevice();
                $dev->setValue($buf/1000);
                if (($buf = CommonFunctions::rolv($sensor[$i], "/\/[^\/]*_input$/", "/name"))!==null) {
                   $name = " (".$buf.")";
                } else {
                   $name = "";
                }
                if (($buf = CommonFunctions::rolv($sensor[$i], "/_input$/", "_label"))!==null) {
                    $dev->setName($buf.$name);
                } else {
                    $labelname = trim(preg_replace("/_input$/", "", pathinfo($sensor[$i], PATHINFO_BASENAME)));
                    if ($labelname !== "") {
                        $dev->setName($labelname.$name);
                    } else {
                        $dev->setName('unknown'.$name);
                    }
                }
                if (($buf = CommonFunctions::rolv($sensor[$i], "/_input$/", "_crit"))!==null) {
                    $dev->setMax($buf/1000);
                    if (CommonFunctions::rolv($sensor[$i], "/_input$/", "_crit_alarm")==="1") {
                        $dev->setEvent("Critical Alarm");
                    }
                } elseif (($buf = CommonFunctions::rolv($sensor[$i], "/_input$/", "_max"))!==null) {
                    $dev->setMax($buf/1000);
                }
                $this->mbinfo->setMbTemp($dev);
            }
        }
    }
819522
def update(self):
        """"""
        # Init new stats
        stats = self.get_init_value()

        if self.input_method == 'local':
            # Update stats using the dedicated lib
            stats = []
            # Get the temperature
            try:
                temperature = self.__set_type(self.glancesgrabsensors.get('temperature_core'),
                                              'temperature_core')
            except Exception as e:
                logger.error("Cannot grab sensors temperatures (%s)" % e)
            else:
                # Append temperature
                stats.extend(temperature)
            # Get the FAN speed
            try:
                fan_speed = self.__set_type(self.glancesgrabsensors.get('fan_speed'),
                                            'fan_speed')
            except Exception as e:
                logger.error("Cannot grab FAN speed (%s)" % e)
            else:
                # Append FAN speed
                stats.extend(fan_speed)
            # Update HDDtemp stats
            try:
                hddtemp = self.__set_type(self.hddtemp_plugin.update(),
                                          'temperature_hdd')
            except Exception as e:
                logger.error("Cannot grab HDD temperature (%s)" % e)
            else:
                # Append HDD temperature
                stats.extend(hddtemp)
            # Update batteries stats
            try:
                batpercent = self.__set_type(self.batpercent_plugin.update(),
                                             'battery')
            except Exception as e:
                logger.error("Cannot grab battery percent (%s)" % e)
            else:
                # Append Batteries %
                stats.extend(batpercent)

        elif self.input_method == 'snmp':
            # Update stats using SNMP
            # No standard:
            # http://www.net-snmp.org/wiki/index.php/Net-SNMP_and_lm-sensors_on_Ubuntu_10.04

            pass

        # Set the alias for each stat
        for stat in stats:
            alias = self.has_alias(stat["label"].lower())
            if alias:
                stat["label"] = alias

        # Update the stats
        self.stats = stats

        return self.stats
122127
def process_temperature_sensors(helper, session):
        """"""
        snmp_result_temp_sensor_names = helper.walk_snmp_values(
            session, helper,
            DEVICE_TEMPERATURE_OIDS['oid_temperature_probe_location'], "temperature sensors")
        snmp_result_temp_sensor_states = helper.walk_snmp_values(
            session, helper,
            DEVICE_TEMPERATURE_OIDS['oid_temperature_probe_status'], "temperature sensors")
        snmp_result_temp_sensor_values = helper.walk_snmp_values(
            session, helper,
            DEVICE_TEMPERATURE_OIDS['oid_temperature_probe_reading'], "temperature sensors")

        for i, _result in enumerate(snmp_result_temp_sensor_states):
            helper.update_status(
                helper, probe_check(snmp_result_temp_sensor_names[i],
                                    snmp_result_temp_sensor_states[i], "Temperature sensor"))

            if i < len(snmp_result_temp_sensor_values):
                helper.add_metric(label=snmp_result_temp_sensor_names[i] + " -Celsius-",
                                  value=float(snmp_result_temp_sensor_values[i]) / 10)
93457
def get_sensor(self, sensor_name):
        
        sensor = self._sensors.get(sensor_name, None)
        if not sensor:
            raise ValueError("Unknown sensor '%s'." % (sensor_name,))
        return sensor
1071886
def read_temperature(self):
        """"""
        UT = self.read_raw_temp()
        # Datasheet value for debugging:
        #UT = 27898
        # Calculations below are taken straight from section 3.5 of the datasheet.
        X1 = ((UT - self.cal_AC6) * self.cal_AC5) >> 15
        X2 = (self.cal_MC << 11) // (X1 + self.cal_MD)
        B5 = X1 + X2
        temp = ((B5 + 8) >> 4) / 10.0
        self.logger.debug('Calibrated temperature {0} C', temp)
        return temp
184834
def gettempdir():
    """"""
    global tempdir
    if tempdir is None:
        _once_lock.acquire()
        try:
            if tempdir is None:
                tempdir = _get_default_tempdir()
        finally:
            _once_lock.release()
    return tempdir