Skip to content

IP-based time using io.receive_time() returning UTC #95

Closed
@kattni

Description

@kattni

The AdafruitIO library does not provide the option to provide the tz parameter to specify timezone, which is the first thing IO looks for to return a time when using io.receive_time().

The second thing IO tries is "guessing" your timezone based on your IP address. This does not appear to be working; it is instead defaulting to UTC.

The final thing IO does is return UTC, which as said above, is happening regardless.

I tested it on a Feather ESP32-S3 TFT board, using CircuitPython 8.0.0-beta.4 and this library. I get UTC from io.receive_time(), every time.

cc: @brentru @lorennorman @jwcooper

That said, in my project code, I received a workaround for this issue from @jepler in the form of a class in my code. This really only helps if you want to make a workaround in this library, versus fixing the feature in IO itself. But I thought it was worth including either way.

class TZIO(IO_HTTP):
    def receive_time(self, tz='UTC'):
        """
        Returns a struct_time from the Adafruit IO Server based on the time zone
.
        https://circuitpython.readthedocs.io/en/latest/shared-bindings/time/__init__.html#time.struct_time
        """
        path = self._compose_path("integrations/time/struct.json?tz={}".format(tz))
        time_struct = self._get(path)
        return time.struct_time(
            (
                time_struct["year"],
                time_struct["mon"],
                time_struct["mday"],
                time_struct["hour"],
                time_struct["min"],
                time_struct["sec"],
                time_struct["wday"],
                time_struct["yday"],
                time_struct["isdst"],
            )
        )

Which is used when instantiating the io object as follows:

io = TZIO(AIO_USER, AIO_KEY, requests)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions