%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python2.7/site-packages/salt/proxy/
Upload File :
Create Path :
Current File : //lib/python2.7/site-packages/salt/proxy/philips_hue.pyo

�
���^c@@spdZddlmZmZmZddljjjj	Z	ddl
Z
ddlZddlZ
ddlmZmZddlmZdgZiZe
je�Zdefd��YZd	�Zd
�Zd�Zd�Zd
dd�Zdd�Zd�Zd�Z d�Z!d�Z"d�Z#d�Z$d�Z%d�Z&d�Z'd�Z(d�Z)d�Z*d�Z+dS(un
Philips HUE lamps module for proxy.

.. versionadded:: 2015.8.3

First create a new user on the Hue bridge by following the
`Meet hue <https://www.developers.meethue.com/documentation/getting-started>`_ instructions.

To configure the proxy minion:

.. code-block:: yaml

    proxy:
      proxytype: philips_hue
      host: [hostname or ip]
      user: [username]

i(tabsolute_importtprint_functiontunicode_literalsN(tCommandExecutionErrortMinionError(tsixuphilips_huetConstcB@s�eZdZied6dd6Zied6dd6Ziddgd6Ziddgd6Zidd	6d
d6Z	idd	6d
d6Z
id
d	6d
d6Ziddgd6Zidd	6d
d6Z
iddgd6Ziddgd6ZRS(u,
    Constants for the lamp operations.
    uoniutransitiontimeg,Ԛ���?gu�V�?uxyg��6�[�?g�,C���?uhuei�usati�ci�.g|�Pk��?g7�A`���?iH�g��e�c]�?gx$(~�?g[���<�?g�J�4�?(t__name__t
__module__t__doc__tTruetLAMP_ONtFalsetLAMP_OFFtCOLOR_WHITEtCOLOR_DAYLIGHTt	COLOR_REDtCOLOR_GREENtCOLOR_ORANGEt
COLOR_PINKt
COLOR_BLUEtCOLOR_YELLOWtCOLOR_PURPLE(((s:/usr/lib/python2.7/site-packages/salt/proxy/philips_hue.pyR6scC@stS(u
    Validate the module.
    (R
(((s:/usr/lib/python2.7/site-packages/salt/proxy/philips_hue.pyt__virtual__HscC@s�|jdi�jd�td<tds;tdd��n|jdi�jd�td<tdsvtdd��ndjtd�td<d	S(
u 
    Initialize the module.
    uproxyuhosttmessageu7Cannot find 'host' parameter in the proxy configurationuuseru7Cannot find 'user' parameter in the proxy configurationu/api/{0}uuriN(tgettCONFIGRtformat(tcnf((s:/usr/lib/python2.7/site-packages/salt/proxy/philips_hue.pytinitOs

cO@stS(u
    Ping the lamps.
    (R
(targstkw((s:/usr/lib/python2.7/site-packages/salt/proxy/philips_hue.pytping^scO@stS(u!
    Shuts down the service.
    (R
(toptsRR((s:/usr/lib/python2.7/site-packages/salt/proxy/philips_hue.pytshutdownfsuuGETc		C@sd}djtd|r(dj|�p+d�|rCdj|�pFd}tjtd�}|dkr�|j||tjjj	|��n|j||�|j
�}|jtjkr�tjjj
|j��}ndj|j|j�}|j�|rt|��n|S(	u%
    Query the URI

    :return:
    u
{0}/lights{1}uuriu/{0}uuhostuPUTuHTTP error: {0}, {1}N(tNoneRRthttp_clienttHTTPConnectiontrequesttsalttutilstjsontdumpstgetresponsetstatustOKtloadstreadtreasontcloseR(	tlamp_idtstatetactiontmethodterrturltconntresptres((s:/usr/lib/python2.7/site-packages/salt/proxy/philips_hue.pyt_queryns 
%
ustatecC@s�yt||d|dd�}Wntk
r@}t|��nXt|�dkr]|dpd|d}|jd�r�itd6}n=|jd	�r�itd6|d	d
d
6|d	dd6}n|S(u\
    Set state to the device by ID.

    :param lamp_id:
    :param state:
    :return:
    R4R5uPUTii����iusuccessuresultuerrorudescriptionutype(R;t	ExceptionRtlenRR
R(R2R3R5R:R6((s:/usr/lib/python2.7/site-packages/salt/proxy/philips_hue.pyt_set�s&
cC@shd|krtd��nt|d�tkr>|dgpgg|djd�D]}t|�^qRS(uX
    Parse device(s) ID(s) from the common params.

    :param params:
    :return:
    uiduParameter ID is required.u,(Rttypetinttsplit(tparamstdev((s:/usr/lib/python2.7/site-packages/salt/proxy/philips_hue.pyt_get_devices�s#cC@s
tdd�S(u-
    Get all available lighting devices.
    N(R;R#(((s:/usr/lib/python2.7/site-packages/salt/proxy/philips_hue.pyt_get_lights�scO@s�t�}t�}xdd|kr-t|�p<t|j��D]8}|jtj|��r=|tj|�||<q=q=W|p�tS(u"
    Get info about all available lamps.

    Options:

    * **id**: Specifies a device ID. Can be a comma-separated values. All, if omitted.

    CLI Example:

    .. code-block:: bash

        salt '*' hue.lights
        salt '*' hue.lights id=1
        salt '*' hue.lights id=1,2,3
    uid(	tdictRERDtsortedtkeysRRt	text_typeR(RtkwargsR:tlightstdev_id((s:/usr/lib/python2.7/site-packages/salt/proxy/philips_hue.pytcall_lights�s		1cO@s�t�}t�}x�d|kr3t|j��p<t|�D]q}d|krn|drbtjphtj}n-|tj	|�ddr�tjp�tj}t
||�||<q=W|S(u�
    Switch lamp ON/OFF.

    If no particular state is passed,
    then lamp will be switched to the opposite state.

    Options:

    * **id**: Specifies a device ID. Can be a comma-separated values. All, if omitted.
    * **on**: True or False. Inverted current, if omitted

    CLI Example:

    .. code-block:: bash

        salt '*' hue.switch
        salt '*' hue.switch id=1
        salt '*' hue.switch id=1,2,3 on=True
    uiduonustate(RFRERGRHRDRRR
RRIR>(RRJtouttdevicesRLR3((s:/usr/lib/python2.7/site-packages/salt/proxy/philips_hue.pytcall_switch�s		1-c
O@s�t�}|jdd�}t�}x�d|krEt|j��pNt|�D]|}|tj|�dd}t||r�t	j
p�t	j�|r�tj
|�nt||r�t	j
p�t	j�||<qOW|S(ur
    Blink a lamp. If lamp is ON, then blink ON-OFF-ON, otherwise OFF-ON-OFF.

    Options:

    * **id**: Specifies a device ID. Can be a comma-separated values. All, if omitted.
    * **pause**: Time in seconds. Can be less than 1, i.e. 0.7, 0.5 sec.

    CLI Example:

    .. code-block:: bash

        salt '*' hue.blink id=1
        salt '*' hue.blink id=1,2,3
    upauseiuidustateuon(RERRFRGRHRDRRIR>RR
Rttimetsleep(RRJROtpauseR:RLR3((s:/usr/lib/python2.7/site-packages/salt/proxy/philips_hue.pyt
call_blink�s		1*cO@sJt�}x4t�j�D]#\}}|dst||<qqW|pItS(u�
    Ping the lamps by issuing a short inversion blink to all available devices.

    CLI Example:

    .. code-block:: bash

        salt '*' hue.ping
    uresult(RFRTtitemsRR
(RRJterrorsRLt
dev_status((s:/usr/lib/python2.7/site-packages/salt/proxy/philips_hue.pyt	call_pings

	
cO@s�t�}t�}xqd|kr3t|j��p<t|�D]E}tj|�}i||ddd6||ddd6||<q=W|S(u
    Return the status of the lamps.

    Options:

    * **id**: Specifies a device ID. Can be a comma-separated values. All, if omitted.

    CLI Example:

    .. code-block:: bash

        salt '*' hue.status
        salt '*' hue.status id=1
        salt '*' hue.status id=1,2,3
    uidustateuonu	reachable(RFRERGRHRDRRI(RRJR:RORL((s:/usr/lib/python2.7/site-packages/salt/proxy/philips_hue.pytcall_status#s		1cO@sjt|�}t|�dkr-td��nd|krHtd��nt|di|dd6dd�S(	u�
    Rename a device.

    Options:

    * **id**: Specifies a device ID. Only one device at a time.
    * **title**: Title of the device.

    CLI Example:

    .. code-block:: bash

        salt '*' hue.rename id=1 title='WC for cats'
    iu(Only one device can be renamed at a timeutitleuTitle is missingiunameR5u(RDR=RR>(RRJRL((s:/usr/lib/python2.7/site-packages/salt/proxy/philips_hue.pytcall_rename?sc
O@s}t�}t�}xdd|kr3t|j��p<t|�D]8}t|i|jdt�rddpgdd6�||<q=W|S(uH
    Lamp alert

    Options:

    * **id**: Specifies a device ID. Can be a comma-separated values. All, if omitted.
    * **on**: Turns on or off an alert. Default is True.

    CLI Example:

    .. code-block:: bash

        salt '*' hue.alert
        salt '*' hue.alert id=1
        salt '*' hue.alert id=1,2,3 on=false
    uiduonulselectunoneualert(RFRERGRHRDR>RR
(RRJR:RORL((s:/usr/lib/python2.7/site-packages/salt/proxy/philips_hue.pyt
call_alertXs
		16c	O@sqt�}t�}xXd|kr3t|j��p<t|�D],}t|i|jdd�d6�||<q=W|S(u�
    Set an effect to the lamp.

    Options:

    * **id**: Specifies a device ID. Can be a comma-separated values. All, if omitted.
    * **type**: Type of the effect. Possible values are "none" or "colorloop". Default "none".

    CLI Example:

    .. code-block:: bash

        salt '*' hue.effect
        salt '*' hue.effect id=1
        salt '*' hue.effect id=1,2,3 type=colorloop
    uidutypeunoneueffect(RFRERGRHRDR>R(RRJR:RORL((s:/usr/lib/python2.7/site-packages/salt/proxy/philips_hue.pytcall_effectrs
		1*cO@s�t�}i	tjd6tjd6tjd6tjd6tjd6tjd6tjd6tj	d6tj
d	6}t�}|jd
�}|r�|j
d�}t|�dkr�y+it|d
�t|d�gd6}Wq�tk
r�}d}q�Xq�d}n|s%|j|jdd�tj�}n|jitt|jdd
�d�d
�d6�xEd|krxt|j��p�t|�D]}t||�||<q�W|S(u�
    Set a color to the lamp.

    Options:

    * **id**: Specifies a device ID. Can be a comma-separated values. All, if omitted.
    * **color**: Fixed color. Values are: red, green, blue, orange, pink, white,
                 yellow, daylight, purple. Default white.
    * **transition**: Transition 0~200.

    Advanced:

    * **gamut**: XY coordinates. Use gamut according to the Philips HUE devices documentation.
                 More: http://www.developers.meethue.com/documentation/hue-xy-values

    CLI Example:

    .. code-block:: bash

        salt '*' hue.color
        salt '*' hue.color id=1
        salt '*' hue.color id=1,2,3 oolor=red transition=30
        salt '*' hue.color id=1 gamut=0.3,0.5
    uredugreenublueuorangeupinkuwhiteuyellowudaylightupurpleugamutu,iiiuxyucoloru
transitioni�utransitiontimeuidN(RFRRRRRRRRRRRERRAR=tfloatR<R#tupdatetmaxtminRGRHRDR>(RRJR:tcolormapROtcolortexRL((s:/usr/lib/python2.7/site-packages/salt/proxy/philips_hue.pyt
call_color�s6	








	+
	$21cO@st�}d|kr$td��ny&ttt|d�d�d�}Wntk
rk}td��nXy&ttt|d�d�d�}Wntk
r�}d}nXt�}xSd	|kr�t|j��p�t	|�D]'}t
|i|d
6|d6�||<q�W|S(u�
    Set an effect to the lamp.

    Arguments:

    * **value**: 0~255 brightness of the lamp.

    Options:

    * **id**: Specifies a device ID. Can be a comma-separated values. All, if omitted.
    * **transition**: Transition 0~200. Default 0.

    CLI Example:

    .. code-block:: bash

        salt '*' hue.brightness value=100
        salt '*' hue.brightness id=1 value=150
        salt '*' hue.brightness id=1,2,3 value=255
    uvalueuParameter 'value' is missingi�iu.Parameter 'value' does not contains an integeru
transitioni�iuidubriutransitiontime(RFRR_R`R@R<RERGRHRDR>(RRJR:t
brightnessR6t
transitionRORL((s:/usr/lib/python2.7/site-packages/salt/proxy/philips_hue.pytcall_brightness�s	&&
	1%cO@s�t�}d|kr$td��ny&ttt|d�d�d�}Wntk
rk}td��nXt�}xLd|kr�t|j��p�t	|�D] }t
|i|d6�||<q�W|S(u�
    Set the mired color temperature. More: http://en.wikipedia.org/wiki/Mired

    Arguments:

    * **value**: 150~500.

    Options:

    * **id**: Specifies a device ID. Can be a comma-separated values. All, if omitted.

    CLI Example:

    .. code-block:: bash

        salt '*' hue.temperature value=150
        salt '*' hue.temperature value=150 id=1
        salt '*' hue.temperature value=150 id=1,2,3
    uvalueu&Parameter 'value' (150~500) is missingi�i�u.Parameter 'value' does not contains an integeruiduct(RFRR_R`R@R<RERGRHRDR>(RRJR:tvalueR6RORL((s:/usr/lib/python2.7/site-packages/salt/proxy/philips_hue.pytcall_temperature�s	&	1(,R	t
__future__RRRtsalt.ext.six.moves.http_clienttextRtmovesR$tloggingRQtsalt.utils.jsonR'tsalt.exceptionsRRtsalt.extt__proxyenabled__Rt	getLoggert__file__tlogtobjectRRRR R"R;R>RDRERMRPRTRXRYRZR[R\RdRgRi(((s:/usr/lib/python2.7/site-packages/salt/proxy/philips_hue.pyt<module>"s<									!							=	+

Zerion Mini Shell 1.0