<s> """<STR_LIT>""" <EOL> from mpf . system . device import Device <EOL> class MatrixLight ( Device ) : <EOL> """<STR_LIT>""" <EOL> config_section = '<STR_LIT>' <EOL> collection = '<STR_LIT>' <EOL> class_label = '<STR_LIT>' <EOL> def __init__ ( self , machine , name , config , collection = None , validate = True ) : <EOL> config [ '<STR_LIT>' ] = str ( config [ '<STR_LIT>' ] ) . upper ( ) <EOL> super ( MatrixLight , self ) . __init__ ( machine , name , config , collection , <EOL> platform_section = '<STR_LIT>' , <EOL> validate = validate ) <EOL> self . hw_driver , self . number = ( <EOL> self . platform . configure_matrixlight ( self . config ) ) <EOL> self . registered_handlers = [ ] <EOL> self . state = { <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : <NUM_LIT:0> } <EOL> self . cache = { <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : <NUM_LIT:0> } <EOL> self . x = None <EOL> self . y = None <EOL> if '<STR_LIT:x>' in config : <EOL> self . x = config [ '<STR_LIT:x>' ] <EOL> if '<STR_LIT:y>' in config : <EOL> self . y = config [ '<STR_LIT:y>' ] <EOL> def on ( self , brightness = <NUM_LIT:255> , fade_ms = <NUM_LIT:0> , start_brightness = None , <EOL> priority = <NUM_LIT:0> , cache = True , force = False , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if priority < self . state [ '<STR_LIT>' ] and not force : <EOL> return <EOL> if type ( brightness ) is list : <EOL> brightness = brightness [ <NUM_LIT:0> ] <EOL> if self . registered_handlers : <EOL> for handler in self . registered_handlers : <EOL> handler ( light_name = self . name , brightness = brightness ) <EOL> self . state [ '<STR_LIT>' ] = brightness <EOL> self . state [ '<STR_LIT>' ] = priority <EOL> if cache : <EOL> self . cache [ '<STR_LIT>' ] = brightness <EOL> self . cache [ '<STR_LIT>' ] = priority <EOL> self . hw_driver . on ( brightness , fade_ms , start_brightness ) <EOL> def off ( self , fade_ms = <NUM_LIT:0> , priority = <NUM_LIT:0> , cache = True , force = False , ** kwargs ) : <EOL> self . on ( brightness = <NUM_LIT:0> , fade_ms = fade_ms , priority = priority , cache = cache , <EOL> force = force , ** kwargs ) <EOL> """<STR_LIT>""" <EOL> def add_handler ( self , callback ) : <EOL> """<STR_LIT>""" <EOL> self . registered_handlers . append ( callback ) <EOL> def remove_handler ( self , callback = None ) : <EOL> """<STR_LIT>""" <EOL> if not callback : <EOL> self . registered_handlers = [ ] <EOL> return <EOL> if callback in self . registered_handlers : <EOL> self . registered_handlers . remove ( callback ) <EOL> def restore ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . debug : <EOL> self . log . debug ( "<STR_LIT>" ) <EOL> self . log . debug ( "<STR_LIT>" , <EOL> self . cache [ '<STR_LIT>' ] , self . cache [ '<STR_LIT>' ] ) <EOL> self . on ( brightness = self . cache [ '<STR_LIT>' ] , <EOL> priority = self . cache [ '<STR_LIT>' ] , <EOL> force = True , <EOL> cache = True ) </s>
