Пример #1
0
 def test_kelvin_dict_to(self):
     kelvin_dict = {'a': 301.0, 'b': 280}
     celsius_dict = {'a': 27.85, 'b': 6.85}
     fahrenheit_dict = {'a': 82.13, 'b': 44.33}
     self.assertEqual(celsius_dict,
                      temputils.kelvin_dict_to(kelvin_dict, "celsius"))
     self.assertEqual(fahrenheit_dict,
                      temputils.kelvin_dict_to(kelvin_dict, "fahrenheit"))
     self.assertEqual(kelvin_dict,
                      temputils.kelvin_dict_to(kelvin_dict, "kelvin"))
Пример #2
0
 def test_kelvin_dict_to(self):
     kelvin_dict = {'a': 301.0, 'b': 280}
     celsius_dict = {'a': 27.85, 'b': 6.85}
     fahrenheit_dict = {'a': 82.13, 'b': 44.33}
     self.assertEqual(celsius_dict,
                      temputils.kelvin_dict_to(
                                               kelvin_dict,
                                               "celsius")
                      )
     self.assertEqual(fahrenheit_dict,
                      temputils.kelvin_dict_to(
                                               kelvin_dict,
                                               "fahrenheit")
                      )
     self.assertEqual(kelvin_dict,
                      temputils.kelvin_dict_to(
                                               kelvin_dict,
                                               "kelvin")
                      )
Пример #3
0
    def get_temperature(self, unit="kelvin"):
        """Returns a dict with temperature info

        :param unit: the unit of measure for the temperature values. May be:
            '*kelvin*' (default), '*celsius*' or '*fahrenheit*'
        :type unit: str
        :returns: a dict containing temperature values.
        :raises: ValueError when unknown temperature units are provided

        """
        # This is due to the fact that the OWM web API responses are mixing
        # absolute temperatures and temperature deltas together
        to_be_converted = dict()
        not_to_be_converted = dict()
        for label, temp in self._temperature.items():
            if temp is None or temp < 0:
                not_to_be_converted[label] = temp
            else:
                to_be_converted[label] = temp
        converted = temputils.kelvin_dict_to(to_be_converted, unit)
        return dict(list(converted.items()) + list(not_to_be_converted.items()))
Пример #4
0
    def get_temperature(self, unit='kelvin'):
        """Returns a dict with temperature info

        :param unit: the unit of measure for the temperature values. May be:
            '*kelvin*' (default), '*celsius*' or '*fahrenheit*'
        :type unit: str
        :returns: a dict containing temperature values.
        :raises: ValueError when unknown temperature units are provided

        """
        # This is due to the fact that the OWM web API responses are mixing
        # absolute temperatures and temperature deltas together
        to_be_converted = dict()
        not_to_be_converted = dict()
        for label, temp in self._temperature.items():
            if temp is None or temp < 0:
                not_to_be_converted[label] = temp
            else:
                to_be_converted[label] = temp
        converted = temputils.kelvin_dict_to(to_be_converted, unit)
        return dict(list(converted.items()) + \
                    list(not_to_be_converted.items()))