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
评论列表
文章目录