コード例 #1
0
    def is_up_shortened(hours=0, minutes=30):
        """Like isUp(), but checks some returns false some time before the sunset and after sunrise"""
        Sun.update()

        diff_time = datetime.timedelta(hours=hours, minutes=minutes)

        # Because we change the time, there are some situations where sunrise > sunset could mean that
        # the sun is still up (or that it's bright outside)
        if Sun._sunset > Sun._sunrise:
            return False
        else:  # Sun is up (but it might not be bright yet/still)

            now = datetime.datetime.now(tz.tzlocal())
            sunset = Sun._sunset - diff_time
            # until 30 min before sunset -> it's not bright
            if now > sunset:
                return False

            # until 30 min after sunrise -> it's not bright
            sunrise = Sun._last_sunrise + diff_time
            if now < sunrise:
                return False

            return True
コード例 #2
0
 def is_up():
     Sun.update()
     return Sun._sunrise > Sun._sunset