3 À<×e‰ ã @ sn d dl mZ d dlT ddlZddlmZ ddlZddlZddl Z ddl Z ejjƒ Z eƒ ZG dd„ dejƒZdS )é )Úhotplug)Ú*é N)Úcommandsc @ s˜ e Zd ZdZdd„ Zdd„ Zdd„ Zdd „ Zed d„ ƒZ dd „ Z dd„ Zeddddd„ ƒZ edƒddd„ƒZeddddd„ ƒZedƒddd„ƒZdS ) ÚAudioPluginaÊ `audio`:: Sets audio cards power saving options. The plug-in sets the auto suspend timeout for audio codecs to the value specified by the [option]`timeout` option. + Currently, the `snd_hda_intel` and `snd_ac97_codec` codecs are supported and the [option]`timeout` value is in seconds. To disable auto suspend for these codecs, set the [option]`timeout` value to `0`. To enforce the controller reset, set the option [option]`reset_controller` to `true`. Note that power management is supported per module. Hence, the kernel module names are used as device names. + .Set the timeout value to 10s and enforce the controller reset ==== ---- [audio] timeout=10 reset_controller=true ---- ==== c C sT d| _ tƒ | _tƒ | _x8| jjdƒjdƒD ]"}| j|ƒ}|dkr*| jj|ƒ q*W d S )NTZsoundzcard*Ú snd_hda_intelÚsnd_ac97_codec)r r ) Z_devices_supportedÚsetZ_assigned_devicesZ _free_devicesZ_hardware_inventoryZget_devicesZmatch_sys_nameÚ_device_module_nameÚadd)ÚselfÚdeviceZmodule_name© r ú"/usr/lib/python3.6/plugin_audio.pyÚ _init_devices( s zAudioPlugin._init_devicesc C s d|_ d|_d S )NTF)Z_has_static_tuningZ_has_dynamic_tuning)r Úinstancer r r Ú_instance_init2 s zAudioPlugin._instance_initc C s d S )Nr )r r r r r Ú_instance_cleanup6 s zAudioPlugin._instance_cleanupc C s y|j jS d S d S )N)ÚparentZdriver)r r r r r r 9 s zAudioPlugin._device_module_namec C s dddœS )Nr F)ÚtimeoutÚreset_controllerr )Úclsr r r Ú_get_config_options? s zAudioPlugin._get_config_optionsc C s d| S )Nz$/sys/module/%s/parameters/power_saver )r r r r r Ú _timeout_pathF s zAudioPlugin._timeout_pathc C s d| S )Nz//sys/module/%s/parameters/power_save_controllerr )r r r r r Ú_reset_controller_pathI s z"AudioPlugin._reset_controller_pathr T)Z per_devicec C sr yt |ƒ}W n" tk r. tjd| ƒ d S X |dkrj| j|ƒ}|sftj|d| |r^tjgndd |S d S d S )Nz!timeout value '%s' is not integerr z%dF)Úno_error) ÚintÚ ValueErrorÚlogÚerrorr ÚcmdÚ write_to_fileÚerrnoÚENOENT)r Úvaluer ÚsimÚremover Úsys_filer r r Ú_set_timeoutL s zAudioPlugin._set_timeoutFc C s, | j |ƒ}tj||d}t|ƒdkr(|S d S )N)r r )r r Ú read_fileÚlen)r r Úignore_missingr' r$ r r r Ú_get_timeout\ s zAudioPlugin._get_timeoutr c C sH t j|ƒ}| j|ƒ}tjj|ƒrD|s@t j|||r8tjgndd |S d S )NF)r ) r Úget_boolr ÚosÚpathÚexistsr! r" r# )r r$ r r% r&