Browse Source

Add temp_precision option to darksky plugin

This gives the darksky plugin a temp_precision option, which allows
users to set the precision with which temperatures are read.  It
defaults to 0, not the old hard-coded value of 1, because I decided that
it's not usually useful to hear that much information.
Clara Hobbs 6 years ago
parent
commit
a14358df2b
1 changed files with 9 additions and 1 deletions
  1. 9
    1
      kayleevc/plugins/darksky.py

+ 9
- 1
kayleevc/plugins/darksky.py View File

19
 (default 1800, half an hour).  To conserve API calls, the cache is not
19
 (default 1800, half an hour).  To conserve API calls, the cache is not
20
 updated until the first time the user requests weather information
20
 updated until the first time the user requests weather information
21
 after the cache becomes stale.
21
 after the cache becomes stale.
22
+
23
+Temperatures are read to the nearest ``temp_precision`` decimal places
24
+(default 0).
22
 """
25
 """
23
 
26
 
24
 import json
27
 import json
47
             self._cache_max_age = self.options['cache_max_age']
50
             self._cache_max_age = self.options['cache_max_age']
48
         except KeyError:
51
         except KeyError:
49
             self._cache_max_age = 1800
52
             self._cache_max_age = 1800
53
+        try:
54
+            self._temp_precision = self.options['temp_precision']
55
+        except KeyError:
56
+            self._temp_precision = 0
50
 
57
 
51
         self.commands = {
58
         self.commands = {
52
             'whats the temperature': self._temperature,
59
             'whats the temperature': self._temperature,
63
 
70
 
64
     def _format_temperature(self, temperature, unit='Fahrenheit'):
71
     def _format_temperature(self, temperature, unit='Fahrenheit'):
65
         """Format a temperature for the TTS system"""
72
         """Format a temperature for the TTS system"""
66
-        return '{:.1f} degrees {}'.format(temperature, unit)
73
+        return '{:.{prec}f} degrees {}'.format(temperature, unit,
74
+                prec=self._temp_precision)
67
 
75
 
68
     def _temperature(self):
76
     def _temperature(self):
69
         return self._format_temperature(self.cache['currently']['temperature'])
77
         return self._format_temperature(self.cache['currently']['temperature'])

Loading…
Cancel
Save