<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def put_device(self, pin, state, momentary=None, times=None, pause=None):
 """ Actuate a device pin """

        url = self.base_url + '/device'

        payload = {
            "pin": pin,
            "state": state
        }

        if momentary is not None:
            payload["momentary"] = momentary

        if times is not None:
            payload["times"] = times

        if pause is not None:
            payload["pause"] = pause

        try:
            r = requests.put(url, json=payload, timeout=10)
            return r.json()
        except RequestException as err:
            raise Client.ClientError(err)