|
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"
|
@@ -268,10 +269,19 @@ def receive_random_data(self, generator_id):
|
268 | 269 | path = self._compose_path("integrations/words/{0}".format(generator_id))
|
269 | 270 | return self._get(path)
|
270 | 271 |
|
271 |
| - def receive_time(self, time_type): |
272 |
| - """ |
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 |
275 |
| - """ |
276 |
| - path = 'https://io.adafruit.com/api/v2/time/{0}'.format(time_type) |
277 |
| - return self._get(path, return_text=True) |
| 272 | + def receive_time(self): |
| 273 | + """ |
| 274 | + Returns a struct_time from the Adafruit IO Server based on the device's IP address. |
| 275 | + https://circuitpython.readthedocs.io/en/latest/shared-bindings/time/__init__.html#time.struct_time |
| 276 | + """ |
| 277 | + path = self._compose_path('/integrations/time/clock.json{0}'.format(strftime_format)) |
| 278 | + time_response = self._get(path, return_text=True) |
| 279 | + times = time_response.split(' ') |
| 280 | + the_date = times[0] |
| 281 | + the_time = times[1] |
| 282 | + year_day = int(times[2]) |
| 283 | + week_day = int(times[3]) |
| 284 | + year, month, mday = [int(x) for x in the_date.split('-')] |
| 285 | + the_time = the_time.split('.')[0] |
| 286 | + hours, minutes, seconds = [int(x) for x in the_time.split(':')] |
| 287 | + return struct_time((year, month, mday, hours, minutes, seconds, week_day, year_day, None)) |
0 commit comments