kevinkk525 / pysmartnode

Micropython Smarthome framework
MIT License
116 stars 22 forks source link

More Questions #17

Closed palmtreefrb closed 4 years ago

palmtreefrb commented 4 years ago
    def daylight_savings(utc, march, november): # daylight_savings(utc=(2020, 4, 9, 8, 44, 4, 4, 362, 0), march=-7 november=-8)
        year = time.localtime(utc)[0]  # get current year
        now = time.time()
        local_time = None
        HHMarch = time.mktime(
            (year, 3, (14-(int(5*year/4+1)) % 7), 1, 0, 0, 0, 0, 0))  # Time of 2nd Sunday of March change to PDT
        HHNovember = time.mktime(
            (year, 11, (7-(int(5*year/4+1)) % 7), 1, 0, 0, 0, 0, 0))  # Time of 1st Sunday of November change to PST
        if now < HHMarch:  # we are before last sunday of march
            local_time = now + 3600 * november
            pac = time.localtime(local_time)  # PDT:  UTC-8H
        elif now < HHNovember:  # we are before last sunday of october
            local_time = now + 3600 * march
            pac = time.localtime(local_time)  # PST: UTC-7H
        else:  # we are after last sunday of october
            local_time = now + 3600 * november
            pac = time.localtime(local_time)  # PDT:  UTC-8H
        return local_time
    def celsius_to_fahrenheit(c):
        n = float(9.0 / 5.0 * c + 32)
        # self.dprint("Temp: {}".format(str(n)))
        # normal_round
        if n - math.floor(n) < 0.5:
            return math.floor(n)
        return math.ceil(n)
kevinkk525 commented 4 years ago

The time sync is done in: https://github.com/kevinkk525/pysmartnode/blob/uasyncio_next/pysmartnode/networking/wifi_esp32.py (if you use the esp32).

Conversion from C to F is a good point.. I don't have anything implemented to allow using Fahrenheit instead of Celsius. I should probably do that for temperature sensors.