<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> devices = lifx . get_lights ( ) <EOL> bulb = devices [ <NUM_LIT:0> ] <EOL> print ( "<STR_LIT>" . format ( bulb . get_label ( ) ) ) <EOL> print ( "<STR_LIT>" ) <EOL> original_power = bulb . get_power ( ) <EOL> original_color = bulb . get_color ( ) <EOL> bulb . set_power ( "<STR_LIT>" ) <EOL> sleep ( <NUM_LIT:1> ) <EOL> print ( "<STR_LIT>" ) <EOL> rainbow ( bulb , <NUM_LIT:0.1> ) <EOL> print ( "<STR_LIT>" ) <EOL> rainbow ( bulb , <NUM_LIT:1> , smooth = True ) <EOL> print ( "<STR_LIT>" ) <EOL> bulb . set_power ( original_power ) <EOL> sleep ( <NUM_LIT:0.5> ) <EOL> bulb . set_color ( original_color ) <EOL> def rainbow ( bulb , 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> bulb . set_color ( color , transition_time_ms , rapid ) <EOL> sleep ( duration_secs ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> main ( ) </s>
