<s> """<STR_LIT>""" <EOL> import logging <EOL> import sys <EOL> import libopenzwave <EOL> from pi import events , proxy <EOL> CONFIG = '<STR_LIT>' <EOL> CONTROLLER_COMMAND_ADD_DEVICE = <NUM_LIT:1> <EOL> class ZWave ( proxy . Proxy ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , device , callback ) : <EOL> self . _device = device <EOL> self . _callback = callback <EOL> self . _options = libopenzwave . PyOptions ( ) <EOL> self . _options . create ( CONFIG , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . _options . addOptionBool ( '<STR_LIT>' , False ) <EOL> self . _options . addOptionInt ( '<STR_LIT>' , <NUM_LIT:6> ) <EOL> self . _options . addOptionInt ( '<STR_LIT>' , <NUM_LIT:6> ) <EOL> self . _options . addOptionBool ( '<STR_LIT>' , True ) <EOL> self . _options . lock ( ) <EOL> self . _manager = libopenzwave . PyManager ( ) <EOL> self . _manager . create ( ) <EOL> self . _manager . addWatcher ( self . _zwave_callback ) <EOL> self . _manager . addDriver ( self . _device ) <EOL> self . _home_id = None <EOL> self . _node_ids = set ( ) <EOL> self . _add_device_event = None <EOL> def _zwave_callback ( self , data ) : <EOL> try : <EOL> self . _zwave_callback_internal ( data ) <EOL> except Exception : <EOL> logging . error ( '<STR_LIT>' , exc_info = sys . exc_info ( ) ) <EOL> def _zwave_callback_internal ( self , data ) : <EOL> """<STR_LIT>""" <EOL> notification_type = data [ '<STR_LIT>' ] <EOL> self . _home_id = data [ '<STR_LIT>' ] <EOL> node_id = data [ '<STR_LIT>' ] <EOL> if notification_type == '<STR_LIT>' : <EOL> for node_id in self . _node_ids : <EOL> node_info = { '<STR_LIT>' : '<STR_LIT>' } <EOL> node_info [ '<STR_LIT>' ] = self . _manager . getNodeBasic ( <EOL> self . _home_id , node_id ) <EOL> node_info [ '<STR_LIT>' ] = self . _manager . getNodeGeneric ( <EOL> self . _home_id , node_id ) <EOL> node_info [ '<STR_LIT>' ] = self . _manager . getNodeSpecific ( <EOL> self . _home_id , node_id ) <EOL> node_info [ '<STR_LIT>' ] = self . _manager . getNodeType ( <EOL> self . _home_id , node_id ) <EOL> node_info [ '<STR_LIT>' ] = self . _manager . getNodeName ( <EOL> self . _home_id , node_id ) <EOL> node_info [ '<STR_LIT>' ] = self . _manager . getNodeManufacturerName ( <EOL> self . _home_id , node_id ) <EOL> node_info [ '<STR_LIT>' ] = self . _manager . getNodeManufacturerId ( <EOL> self . _home_id , node_id ) <EOL> node_info [ '<STR_LIT>' ] = self . _manager . getNodeProductName ( <EOL> self . _home_id , node_id ) <EOL> node_info [ '<STR_LIT>' ] = self . _manager . getNodeProductType ( <EOL> self . _home_id , node_id ) <EOL> node_info [ '<STR_LIT>' ] = self . _manager . getNodeProductId ( <EOL> self . _home_id , node_id ) <EOL> self . _callback ( '<STR_LIT>' , '<STR_LIT>' % node_id , node_info ) <EOL> if node_id in { <NUM_LIT:1> , <NUM_LIT:255> } : <EOL> logging . info ( '<STR_LIT>' , node_id , notification_type ) <EOL> return <EOL> if notification_type == '<STR_LIT>' : <EOL> self . _node_ids . add ( node_id ) <EOL> self . _manager . addAssociation ( self . _home_id , node_id , <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> self . _manager . refreshNodeInfo ( self . _home_id , node_id ) <EOL> self . _manager . requestNodeState ( self . _home_id , node_id ) <EOL> self . _manager . requestNodeDynamic ( self . _home_id , node_id ) <EOL> self . _callback ( '<STR_LIT>' , '<STR_LIT>' % node_id , data ) <EOL> elif notification_type in { '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' } : <EOL> self . _callback ( '<STR_LIT>' , '<STR_LIT>' % node_id , data ) <EOL> else : <EOL> logging . info ( '<STR_LIT>' , node_id , notification_type ) <EOL> @ proxy . command <EOL> def heal ( self ) : <EOL> self . _manager . softResetController ( self . _home_id ) <EOL> self . _manager . healNetwork ( self . _home_id , upNodeRoute = True ) <EOL> @ proxy . command <EOL> def hard_reset ( self ) : <EOL> self . _manager . resetController ( self . _home_id ) <EOL> @ proxy . command <EOL> def heal_node ( self , node_id ) : <EOL> self . _manager . healNetworkNode ( self . _home_id , node_id , <EOL> upNodeRoute = True ) <EOL> @ proxy . command <EOL> def set_value ( self , value_id , value , node_id = None ) : <EOL> logging . info ( '<STR_LIT>' , <EOL> value_id , node_id , value ) <EOL> success = self . _manager . setValue ( value_id , value ) <EOL> if not success : <EOL> logging . info ( '<STR_LIT>' ) <EOL> def _add_device_callback ( self , args ) : <EOL> logging . info ( '<STR_LIT>' , args ) <EOL> def _cancel_add_device ( self ) : <EOL> logging . info ( '<STR_LIT>' ) <EOL> self . _manager . cancelControllerCommand ( self . _home_id ) <EOL> @ proxy . command <EOL> def add_device ( self ) : <EOL> """<STR_LIT>""" <EOL> logging . info ( '<STR_LIT>' ) <EOL> self . _manager . beginControllerCommand ( <EOL> self . _home_id , CONTROLLER_COMMAND_ADD_DEVICE , <EOL> self . _add_device_callback , highPower = True ) <EOL> self . _add_device_event = events . enter ( <NUM_LIT:30> , self . _cancel_add_device ) <EOL> def stop ( self ) : <EOL> if self . _add_device_event is not None : <EOL> try : <EOL> events . cancel ( self . _add_device_event ) <EOL> except ValueError : <EOL> pass <EOL> if self . _home_id is not None : <EOL> self . _manager . writeConfig ( self . _home_id ) <EOL> self . _manager . removeWatcher ( self . _callback ) <EOL> self . _manager . removeDriver ( self . _device ) <EOL> def join ( self ) : <EOL> pass </s>
