
    j"                     *    d Z ddlmZ  G d de      Zy)a  
 Python module to interface with Tuya Socket Devices

 Author: Felix Pieschka
 For more information see https://github.com/Felix-Pi

 Local Control Classes
    SocketDevice(...)
        See OutletDevice() for constructor arguments

 Functions
    SocketDevice:
        get_energy_consumption()
        get_current()
        get_power()
        get_get_voltage()
        get_state()
    Inherited
        json = status()                    # returns json payload
        set_version(version)               # 3.1 [default] or 3.3
        set_socketPersistent(False/True)   # False [default] or True
        set_socketNODELAY(False/True)      # False or True [default]
        set_socketRetryLimit(integer)      # retry count limit [default 5]
        set_socketTimeout(timeout)         # set connection timeout in seconds [default 5]
        set_dpsUsed(dps_to_request)        # add data points (DPS) to request
        add_dps_to_request(index)          # add data point (DPS) index set to None
        set_retry(retry=True)              # retry if response payload is truncated
        set_status(on, switch=1, nowait)   # Set status of switch to 'on' or 'off' (bool)
        set_value(index, value, nowait)    # Set int value of any index.
        heartbeat(nowait)                  # Send heartbeat to device
        updatedps(index=[1], nowait)       # Send updatedps command to device
        turn_on(switch=1, nowait)          # Turn on device / switch #
        turn_off(switch=1, nowait)         # Turn off
        set_timer(num_secs, nowait)        # Set timer for num_secs
        set_debug(toggle, color)           # Activate verbose debugging output
        set_sendWait(num_secs)             # Time to wait after sending commands before pulling response
        detect_available_dps()             # Return list of DPS available from device
        generate_payload(command, data)    # Generate TuyaMessage payload for command with data
        send(payload)                      # Send payload to device (do not wait for response)
        receive()
   )Devicec                   D    e Zd ZdZdZdZdZdZd ZddZ	dd	Z
dd
Zd Zy)SocketDevicez(
    Represents a Tuya based Socket
    1181920c                     | j                         }i | j                  |      | j                  |      | j                  |      S N)statusget_current	get_powerget_voltage)selfdatas     J/DATA/.local/lib/python3.12/site-packages/tinytuya/Contrib/SocketDevice.pyget_energy_consumptionz#SocketDevice.get_energy_consumption:   sB    {{}[$""4([DNN4,@[DDTDTUYDZ[[    Nc                 l    || j                         }|d   | j                     }|t        |      dz   dS )Ndpsz mA)current_rawcurrent_fmt)r   DPS_CURRENTstr)r   status_datacurrents      r   r   zSocketDevice.get_current>   sA    ++-Ke$T%5%56&"7|e37 	7r   c                 r    || j                         }|d   | j                     dz  }|t        |      dz   dS )Nr   
   z W)	power_raw	power_fmt)r   	DPS_POWERr   )r   r   powers      r   r   zSocketDevice.get_powerG   sD    ++-KE"4>>2R7" Z$.2 	2r   c                 r    || j                         }|d   | j                     dz  }|t        |      dz   dS )Nr   r   z V)voltage_rawvoltage_fmt)r   DPS_VOLTAGEr   )r   r   voltages      r   r   zSocketDevice.get_voltageP   sF    ++-Ke$T%5%56;&"7|d24 	4r   c                 F    d| j                         d   | j                     iS )Nonr   )r   	DPS_STATE)r   s    r   	get_statezSocketDevice.get_stateY   s!    dkkmE*4>>:;;r   r   )__name__
__module____qualname____doc__r*   r   r!   r&   r   r   r   r   r+    r   r   r   r   0   s7     IKIK\724<r   r   N)r/   corer   r   r0   r   r   <module>r2      s   (T *<6 *<r   