<s> from lifxlan import * <EOL> import sys <EOL> from time import sleep <EOL> def main ( ) : <EOL> num_lights = None <EOL> if len ( sys . argv ) != <NUM_LIT:2> : <EOL> print ( "<STR_LIT>" ) <EOL> print ( "<STR_LIT>" . format ( sys . argv [ <NUM_LIT:0> ] ) ) <EOL> else : <EOL> num_lights = int ( sys . argv [ <NUM_LIT:1> ] ) <EOL> print ( "<STR_LIT>" ) <EOL> lifx = LifxLAN ( num_lights ) <EOL> original_colors = lifx . get_color_all_lights ( ) <EOL> original_powers = lifx . get_power_all_lights ( ) <EOL> print ( "<STR_LIT>" ) <EOL> lifx . set_power_all_lights ( True ) <EOL> sleep ( <NUM_LIT:1> ) <EOL> print ( "<STR_LIT>" ) <EOL> rainbow ( lifx , <NUM_LIT:0.1> ) <EOL> print ( "<STR_LIT>" ) <EOL> rainbow ( lifx , <NUM_LIT:1> , smooth = True ) <EOL> print ( "<STR_LIT>" ) <EOL> for light , color in original_colors : <EOL> light . set_color ( color ) <EOL> sleep ( <NUM_LIT:1> ) <EOL> print ( "<STR_LIT>" ) <EOL> for light , power in original_powers : <EOL> light . set_power ( power ) <EOL> def rainbow ( lan , duration_secs = <NUM_LIT:0.5> , smooth = False ) : <EOL> colors = [ RED , ORANGE , YELLOW , GREEN , CYAN , BLUE , PURPLE , PINK ] <EOL> transition_time_ms = duration_secs * <NUM_LIT:1000> if smooth else <NUM_LIT:0> <EOL> rapid = True if duration_secs < <NUM_LIT:1> else False <EOL> for color in colors : <EOL> lan . set_color_all_lights ( color , transition_time_ms , rapid ) <EOL> sleep ( duration_secs ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> main ( ) </s>
