|
39 | 39 | https://github.com/adafruit/Adafruit_CircuitPython_ESP32SPI |
40 | 40 | https://github.com/adafruit/Adafruit_CircuitPython_ESP_ATcontrol |
41 | 41 | """ |
| 42 | +from time import struct_time |
42 | 43 | from adafruit_io.adafruit_io_errors import AdafruitIO_RequestError, AdafruitIO_ThrottleError |
43 | 44 |
|
44 | 45 | __version__ = "0.0.0-auto.0" |
@@ -119,18 +120,15 @@ def _post(self, path, payload): |
119 | 120 | self._handle_error(response) |
120 | 121 | return response.json() |
121 | 122 |
|
122 | | - def _get(self, path, return_text=False): |
| 123 | + def _get(self, path): |
123 | 124 | """ |
124 | 125 | GET data from Adafruit IO |
125 | 126 | :param str path: Formatted Adafruit IO URL from _compose_path |
126 | | - :param bool return_text: Returns text instead of json |
127 | 127 | """ |
128 | 128 | response = self.wifi.get( |
129 | 129 | path, |
130 | 130 | headers=self._create_headers(self._aio_headers[1])) |
131 | 131 | self._handle_error(response) |
132 | | - if return_text: |
133 | | - return response.text |
134 | 132 | return response.json() |
135 | 133 |
|
136 | 134 | def _delete(self, path): |
@@ -268,10 +266,12 @@ def receive_random_data(self, generator_id): |
268 | 266 | path = self._compose_path("integrations/words/{0}".format(generator_id)) |
269 | 267 | return self._get(path) |
270 | 268 |
|
271 | | - def receive_time(self, time_type): |
| 269 | + def receive_time(self): |
272 | 270 | """ |
273 | | - Returns the current time from the Adafruit IO Server |
274 | | - :param string time_type: Type of time to be returned: millis, seconds, or ISO-8601 |
| 271 | + Returns a struct_time from the Adafruit IO Server based on the device's IP address. |
| 272 | + https://circuitpython.readthedocs.io/en/latest/shared-bindings/time/__init__.html#time.struct_time |
275 | 273 | """ |
276 | | - path = 'https://io.adafruit.com/api/v2/time/{0}'.format(time_type) |
277 | | - return self._get(path, return_text=True) |
| 274 | + path = self._compose_path('integrations/time/struct.json') |
| 275 | + time = self._get(path) |
| 276 | + return struct_time((time['year'], time['mon'], time['mday'], time['hour'], |
| 277 | + time['min'], time['sec'], time['wday'], time['yday'], time['isdst'])) |
0 commit comments