Within a platform time.localtime still returms UTC

I have developed a “next tide” sensor to access the Weather Undergound api for tides and present it. The requirement is to present the next tide in local time. However, when I convert the epoch time to local time I still get UTC.

I looked at the worldtidfeinfo platform and the same thing happens there. Even though the code uses time.localtime() UTC is the result.

I got around it by using the pretty string from the API, but I am still interested in how one would get a result returned for the local timezone and why time.localtime() does not appear to work. This is my first hack into homeassistant and I am probably missing something silly.

If the next tide Unix timestamp is in a variable named next_tide_ts, then you could do this:

from homeassistant import util
next_tide_local = util.dt.as_local(util.dt.utc_from_timestamp(float(next_tide_ts)))

There might be a more direct way, but that should work.

Thank you so much. I will try that out.