function buildUrl(device, command = undefined) {
  const [, networkAddress] = device.external_id.split(':');
  const url = new URL(`http://${networkAddress}`);

  if (device && device.params) {
    const username = (device.params.find((param) => param.name === DEVICE_PARAM_NAME.USERNAME) || {}).value;
    if (username) {
      url.searchParams.append('user', username);

      const password = (device.params.find((param) => param.name === DEVICE_PARAM_NAME.PASSWORD) || {}).value;
      if (password) {
        url.searchParams.append('password', password);
      }
    }
  }

  if (command) {
    url.pathname = 'cm';
    url.searchParams.append('cmnd', command);
  }

  return url.href;
}
@description Build URL from device.
@param {object} device - Device.
@param {string} command - Command to send.
@returns {string} The build URL.
@example
buildUrl({}, 'Status');