Skip to content

Commit 705809c

Browse files
author
brentru
committed
old time, change for clock
1 parent b00f674 commit 705809c

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

adafruit_io/adafruit_io.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
https://github.com/adafruit/Adafruit_CircuitPython_ESP32SPI
4040
https://github.com/adafruit/Adafruit_CircuitPython_ESP_ATcontrol
4141
"""
42+
from time import struct_time
4243
from adafruit_io.adafruit_io_errors import AdafruitIO_RequestError, AdafruitIO_ThrottleError
4344

4445
__version__ = "0.0.0-auto.0"
@@ -268,10 +269,19 @@ def receive_random_data(self, generator_id):
268269
path = self._compose_path("integrations/words/{0}".format(generator_id))
269270
return self._get(path)
270271

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

Comments
 (0)