smart-controller.py 文件源码

python
阅读 45 收藏 0 点赞 0 评论 0

项目:yeelight-controller 作者: kevinxw 项目源码 文件源码
def __calculate_light_brightness(self, current_time, light_policy = {}):
        bright_time, dark_time = light_policy['bright_time'], light_policy['dark_time']
        if current_time < min(bright_time, dark_time) or current_time > max(bright_time, dark_time):
            return -1   # return -1 when current time is not within the bright_time and dark_time range
        # if there is a constant brightness value, return immediately
        if 'const_brightness' in light_policy:
            return light_policy['const_brightness']
        min_brightness, max_brightness = 0, 100
        if 'min_brightness' in light_policy:
            min_brightness = light_policy['min_brightness']
        if 'max_brightness' in light_policy:
            max_brightness = light_policy['max_brightness']
        time_scale = abs(self.__get_diff_between_datetime(bright_time, dark_time))
        time_passed = abs(self.__get_diff_between_datetime(current_time, bright_time))
        brightness = int(math.ceil(min_brightness + float(time_passed) / float(time_scale) * float(max_brightness - min_brightness)))
        brightness += min_brightness
        return brightness
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号