code: def will_set(self, topic, payload=None, qos=0, retain=False):
          
          if topic is None or len(topic) == 0:
              raise ValueError('Invalid topic.')
          if qos<0 or qos>2:
              raise ValueError('Invalid QoS level.')
          if isinstance(payload, str):
              self._will_payload = payload.encode('utf-8')
          elif isinstance(payload, bytearray):
              self._will_payload = payload
          elif isinstance(payload, int) or isinstance(payload, float):
              self._will_payload = str(payload)
          elif payload is None:
              self._will_payload = None
          else:
              raise TypeError('payload must be a string, bytearray, int, float or None.')
  
          self._will = True
          self._will_topic = topic.encode('utf-8')
          self._will_qos = qos
          self._will_retain = retain
docs: Set a Will to be sent by the broker in case the client disconnects unexpectedly.
  
          This must be called before connect() to have any effect.
  
          topic: The topic that the will message should be published on.
          payload: The message to send as a will. If not given, or set to None a
          zero length message will be used as the will. Passing an int or float
          will result in the payload being converted to a string representing
          that number. If you wish to send a true int/float, use struct.pack() to
          create the payload you require.
          qos: The quality of service level to use for the will.
          retain: If set to true, the will message will be set as the "last known
          good"/retained message for the topic.
  
          Raises a ValueError if qos is not 0, 1 or 2, or if topic is None or has
          zero string length.